Closed yangjian102621 closed 2 years ago
I had find the reason. i should have specify a QueueSelector for the producer.
type MyQueueSelector struct{}
func (q MyQueueSelector) Select(msg *primitive.Message, mqs []*primitive.MessageQueue) *primitive.MessageQueue {
orderId, err := strconv.Atoi(msg.GetShardingKey())
if err == nil {
return mqs[orderId%len(mqs)]
} else {
return mqs[0]
}
}
// then create producer with specified queue selector
p, err := rocketmq.NewProducer(
producer.WithNameServer(config.NameSrvAddr),
producer.WithGroupName(config.ProducerGroup),
producer.WithRetry(2),
producer.WithQueueSelector(MyQueueSelector{}),
)
Then it worked perfect.
INFO[0063] Receive message: Ordered Message Step -> 0, orderId: 0
INFO[0063] Receive message: Ordered Message Step -> 1, orderId: 0
INFO[0063] Receive message: Ordered Message Step -> 2, orderId: 0
INFO[0063] Receive message: Ordered Message Step -> 3, orderId: 0
INFO[0063] Receive message: Ordered Message Step -> 4, orderId: 0
INFO[0063] Receive message: Ordered Message Step -> 0, orderId: 1
INFO[0063] Receive message: Ordered Message Step -> 1, orderId: 1
INFO[0063] Receive message: Ordered Message Step -> 2, orderId: 1
INFO[0063] Receive message: Ordered Message Step -> 3, orderId: 1
INFO[0063] Receive message: Ordered Message Step -> 4, orderId: 1
INFO[0063] Receive message: Ordered Message Step -> 0, orderId: 2
INFO[0063] Receive message: Ordered Message Step -> 1, orderId: 2
INFO[0063] Receive message: Ordered Message Step -> 2, orderId: 2
INFO[0063] Receive message: Ordered Message Step -> 3, orderId: 2
INFO[0063] Receive message: Ordered Message Step -> 4, orderId: 2
And i found it does not had a example for orderly message Producer, considering add one?
can use NewHashQueueSelector
as your selector
@Victor1319 got it, thanks.
BUG REPORT
When i send some orderly message with producer, there are not in ordered when the consumer pull the message.
ENV
Producer code
Consumer code
I expected the steps of the message for the same order to be in order, but it's not actually
Some thing else is that i send orderly message with java SDK work OK, the go client consumer could receive orderly message.
Java SDK producer
The golang consumer client received ordered messages:
I do not know what the matter is , i need help, thanks.