[BUG] ServiceBusMessageBatch does not preserve message order reliably #25112
Labels
Client
This issue points to a problem in the data-plane of the library.
customer-reported
Issues that are reported by GitHub users external to the Azure organization.
question
The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Service Bus
Milestone
Describe the bug
When the ServiceBusMessageBatch class is used to send batches of ServiceBus messages, the order of adding the messages to the ServiceBusMessageBatch object is not reliably the order the messages are added to the destination queue.
Exception or Stack Trace
Add the exception log and stack trace if available
To Reproduce
It was confirmed by testing and comparing the resulting order of the messages on the queue. When not using ServiceBusMessageBatch the send order was reliably the message order on the queue, but when using ServiceBusMessageBatch the order was frequently not preserved, leading to erroneous processing by the received.
Code Snippet
I have a simple wrapper around the ServiceBus client that enable switching between batched sends and un-batched sends - the actual send method looks like this:
void sendMessage(ServiceBusMessage serviceBusMessage){
if(!batchingEnabled) {
log.trace("Send single service bus messages to {}", getNameQualifier());
senderClient.sendMessage(serviceBusMessage);
} else {
if(!serviceBusMessageBatch.get().tryAddMessage(serviceBusMessage)){
flush();
if(!serviceBusMessageBatch.get().tryAddMessage(serviceBusMessage)){
String msg = String.format("Unable to add SB message to batch - too large - %d?", serviceBusMessage.getBody().toBytes().length);
ServiceBusSink.this.senderClient = null;
throw new RuntimeException(msg);
}
}
}
}
Expected behavior
Batches of messages assembled using ServiceBusMessageBatch should be written to the destination queue in the order in which they are added to the ServiceBusMessageBatch object.
Screenshots
If applicable, add screenshots to help explain your problem.
Setup (please complete the following information):
If you suspect a dependency version mismatch (e.g. you see
NoClassDefFoundError
,NoSuchMethodError
or similar), please providemvn dependency:tree -Dverbose
)Additional context
Add any other context about the problem here.
Information Checklist
Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
The text was updated successfully, but these errors were encountered: