本文整理汇总了Golang中github.com/vburenin/firempq/pqueue.PQueue.Push方法的典型用法代码示例。如果您正苦于以下问题:Golang PQueue.Push方法的具体用法?Golang PQueue.Push怎么用?Golang PQueue.Push使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/vburenin/firempq/pqueue.PQueue
的用法示例。
在下文中一共展示了PQueue.Push方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: PushAMessage
func PushAMessage(pq *pqueue.PQueue, senderId string, paramList []string) sqs_response.SQSResponse {
out := &MessageParams{
DelaySeconds: -1,
MessageBody: "",
}
attrs, err := urlutils.ParseNNotationAttr("MessageAttribute.", paramList, out.Parse, NewReqQueueAttr)
if err != nil {
return err
}
attrsLen := len(attrs)
outAttrs := make(map[string]*sqsmsg.UserAttribute)
for i := 1; i <= attrsLen; i++ {
a, ok := attrs[i]
if !ok {
return sqserr.InvalidParameterValueError("The request must contain non-empty message attribute name.")
}
reqMsgAttr, _ := a.(*ReqMsgAttr)
sqs_err := validation.ValidateMessageAttrName(reqMsgAttr.Name)
if sqs_err != nil {
return sqs_err
}
sqs_err = validation.ValidateMessageAttrName(reqMsgAttr.DataType)
if sqs_err != nil {
return sqs_err
}
if reqMsgAttr.BinaryValue != "" && reqMsgAttr.StringValue != "" {
return sqserr.InvalidParameterValueError(
"Message attribute name '%s' has multiple values.", reqMsgAttr.Name)
}
if _, ok := outAttrs[reqMsgAttr.Name]; ok {
return sqserr.InvalidParameterValueError(
"Message attribute name '%s' already exists.", reqMsgAttr.Name)
}
if strings.HasPrefix(reqMsgAttr.DataType, "Number") {
if _, err := strconv.Atoi(reqMsgAttr.StringValue); err != nil {
return sqserr.InvalidParameterValueError(
"Could not cast message attribute '%s' value to number.", reqMsgAttr.Name)
}
}
if reqMsgAttr.BinaryValue != "" {
if reqMsgAttr.DataType != "Binary" {
return sqserr.InvalidParameterValueError(
"The message attribute '%s' with type 'Binary' must use field 'Binary'", reqMsgAttr.Name)
}
outAttrs[reqMsgAttr.Name] = &sqsmsg.UserAttribute{
Type: reqMsgAttr.DataType,
Value: reqMsgAttr.BinaryValue,
}
continue
}
if reqMsgAttr.StringValue != "" {
if reqMsgAttr.DataType != "String" && reqMsgAttr.DataType != "Number" {
return sqserr.InvalidParameterValueError(
"The message attribute '%s' with type 'String' must use field 'String'", reqMsgAttr.Name)
}
outAttrs[reqMsgAttr.Name] = &sqsmsg.UserAttribute{
Type: reqMsgAttr.DataType,
Value: reqMsgAttr.StringValue,
}
}
}
msgId := IdGen.RandId()
if out.DelaySeconds < 0 {
out.DelaySeconds = pq.Config().DeliveryDelay
} else if out.DelaySeconds > conf.CFG_PQ.MaxDeliveryDelay {
return sqserr.InvalidParameterValueError(
"Delay secods must be between 0 and %d", conf.CFG_PQ.MaxDeliveryDelay/1000)
}
bodyMd5str := fmt.Sprintf("%x", md5.Sum(enc.UnsafeStringToBytes(out.MessageBody)))
attrMd5 := CalcAttrMd5(outAttrs)
msgPayload := sqsmsg.SQSMessagePayload{
UserAttributes: outAttrs,
MD5OfMessageBody: bodyMd5str,
MD5OfMessageAttributes: attrMd5,
SenderId: senderId,
SentTimestamp: strconv.FormatInt(utils.Uts(), 10),
Payload: out.MessageBody,
}
d, marshalErr := msgPayload.Marshal()
if marshalErr != nil {
log.Error("Failed to serialize message payload: %v", err)
}
payload := enc.UnsafeBytesToString(d)
resp := pq.Push(msgId, payload, pq.Config().MsgTtl, out.DelaySeconds, 1)
if resp.IsError() {
e, _ := resp.(error)
return sqserr.InvalidParameterValueError(e.Error())
}
//.........这里部分代码省略.........