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

The example at: 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 call txSession.commit(); to close off that window.

Don’t 256 onReceive() methods create 256 different asynchronous threads? If write 256 onReceive() 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.

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.

@amackenzie thanks a lot for clarifying. Suggested approach is working like a charm :slight_smile:

@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?

can you paste your publisher code?

One new observation is, when batch size is 1 (when i commit the transaction for each message) callback is happening. However, for batch size > 1 it is not happening.

Thanks,
Raghu

My previous observation is incorrect. Somehow I got to that conclusion by mistake.
Actually Producer callback is NOT happening when I use transacted session irrespective of the batch size.