예제 #1
0
func SendMessageBatch(pq *pqueue.PQueue, sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {
	attrs, _ := urlutils.ParseNNotationAttr(
		"SendMessageBatchRequestEntry.", sqsQuery.ParamsList, nil, NewReqQueueAttr)

	attrsLen := len(attrs)

	checker, err := validation.NewBatchIdValidation(attrsLen)
	if err != nil {
		return err
	}

	// map used to detect duplicated ids.
	attrList := make([]*MessageBatchParams, 0, attrsLen)

	for i := 1; i <= attrsLen; i++ {
		a, ok := attrs[i]
		if !ok {
			return sqserr.MissingParameterError("The request is missing sequence %d", i)
		}
		p, _ := a.(*MessageBatchParams)
		if err = checker.Validate(p.Id); err != nil {
			return err
		}
		if err := validation.ValidateBatchRequestId(p.Id); err != nil {
			return err
		}
		attrList = append(attrList, p)
	}

	batchResponse := &SendMessageBatchResponse{
		RequestId: "rreer",
	}

	for _, a := range attrList {
		resp := send_message.PushAMessage(pq, sqsQuery.SenderId, a.ParamsList)
		if resp.HttpCode() == 200 {
			batchResponse.ResultEntry = append(batchResponse.ResultEntry, resp.BatchResult(a.Id))
		} else {
			batchResponse.ErrorEntry = append(batchResponse.ErrorEntry, resp.BatchResult(a.Id))
		}
	}

	return batchResponse
}
func ChangeMessageVisibilityBatch(pq *pqueue.PQueue, sqsQuery *urlutils.SQSQuery) sqs_response.SQSResponse {
	attrs, _ := urlutils.ParseNNotationAttr(
		"ChangeMessageVisibilityBatchRequestEntry.", sqsQuery.ParamsList,
		nil, NewVisibilityBatchParams)
	attrsLen := len(attrs)

	checker, err := validation.NewBatchIdValidation(attrsLen)
	if err != nil {
		return err
	}

	attrList := make([]*VisibilityBatchParams, 0, attrsLen)

	for i := 1; i <= attrsLen; i++ {
		a, ok := attrs[i]
		if !ok {
			return sqserr.MissingParameterError("The request is missing sequence %d", i)
		}
		p, _ := a.(*VisibilityBatchParams)
		if err = checker.Validate(p.Id); err != nil {
			return err
		}
		attrList = append(attrList, p)
	}

	output := &ChangeMessageVisibilityBatchResponse{
		RequestId: "visibilitybatch",
	}

	for _, batchItem := range attrList {
		resp := pq.UpdateLockByRcpt(batchItem.ReceiptHandle, batchItem.VisibilityTimeout)
		if resp == mpqerr.ERR_INVALID_RECEIPT {
			e := sqserr.InvalidReceiptHandleError("The input receipt handle is not a valid receipt handle.")
			output.ErrorEntry = append(output.ErrorEntry, e.BatchResult(batchItem.Id))
		} else {
			output.ResultEntry = append(output.ResultEntry, &OkChange{Id: batchItem.Id})
		}
	}
	return output
}