Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: batchSend messages return result has msgIds and offsetMsgId #1154

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -741,8 +741,12 @@ func (c *rmqClient) ProcessSendResponse(brokerName string, cmd *remote.RemotingC
}

msgIDs := make([]string, 0)
for i := 0; i < len(msgs); i++ {
msgIDs = append(msgIDs, msgs[i].GetProperty(primitive.PropertyUniqueClientMessageIdKeyIndex))
if msgs[0].Batch {
for i := range msgs[0].List {
msgIDs = append(msgIDs, msgs[0].List[i].GetProperty(primitive.PropertyUniqueClientMessageIdKeyIndex))
}
} else {
msgIDs = append(msgIDs, msgs[0].GetProperty(primitive.PropertyUniqueClientMessageIdKeyIndex))
}
uniqueMsgId := strings.Join(msgIDs, ",")

Expand Down
1 change: 1 addition & 0 deletions primitive/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ const (
)

type Message struct {
List []*Message
Topic string
Body []byte
CompressedBody []byte
Expand Down
2 changes: 2 additions & 0 deletions producer/producer.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,14 @@ func (p *defaultProducer) encodeBatch(msgs ...*primitive.Message) *primitive.Mes
batch.Queue = msgs[0].Queue
batch.Body = MarshalMessageBatch(msgs...)
batch.Batch = true
batch.List = msgs
return batch
}

func MarshalMessageBatch(msgs ...*primitive.Message) []byte {
buffer := bytes.NewBufferString("")
for _, msg := range msgs {
msg.WithProperty(primitive.PropertyUniqueClientMessageIdKeyIndex, primitive.CreateUniqID())
data := msg.Marshal()
buffer.Write(data)
}
Expand Down