🎄 Happy Holidays! 🥳
Most of Solace is closed December 24–January 1 so our employees can spend time with their families. We will re-open Thursday, January 2, 2024. Please expect slower response times during this period and open a support ticket for anything needing immediate assistance.
Happy Holidays!
Please note: most of Solace is closed December 25–January 2, and will re-open Tuesday, January 3, 2023.
SMF sample for Batch/Transacted Send and Receive
Hi,
I have a use case in which I have to send batch of 256 messages in a single local transaction. Also, on the consumer side I should receive all 256 messages in a batch and local transaction.
Is there a Java (JCSMP) sample to do that?
Please help.
Thanks,
Raghu
Comments
-
The example at: https://solace.com/samples/solace-samples-java/feature_transactions/ shows the use of transactions. In the example it shows a producer and consumer in the transaction which is a different use case than what you are asking about. However, the setup would be the same but you would do 256 of the
onReceive()
and then calltxSession.commit();
to close off that window.0 -
Don't 256
onReceive()
methods create 256 different asynchronous threads? If write 256onReceive()
methods, do we need to put 'txSession.commit()` on all methods?
Also, writing 256 onReceive methods with same signature does not compile. Does it mean, we have to create 256 FlowReceivers on the transacted session? and have commit in one of the Flow receivers?
Please clarify.0 -
I wasn't suggesting doing 256 onRecieve() functions. I was suggesting that on your onRecieve () you keep a counter and reset it every 256 messages. When you reset it back to 0, commit the txn.
0 -
@amackenzie thanks a lot for clarifying. Suggested approach is working like a charm
0 -
@amackenzie Message send and receive is working fine with the approach. However, the callback function in JCSMPStreamingPublishEventHandler is not working as expected. None of the logging statements were printed in the callback method when doing batch
transactedSession.commit()
:@Override public void responseReceived(String messageID) {...}
Am I missing something?
0 -
can you paste your publisher code?
0