Try PubSub+
If you haven't already, check out our new Developer Portal! You'll find useful information about Solace PubSub+ as well as handy resources to get you started.

SMF sample for Batch/Transacted Send and Receive

rdesojurdesoju Member Posts: 59
edited March 11 in PubSub+ Software

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

  • amackenzieamackenzie Member, Employee Posts: 28 Solace Employee

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

  • rdesojurdesoju Member Posts: 59
    edited March 12

    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.

  • amackenzieamackenzie Member, Employee Posts: 28 Solace Employee

    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.

  • rdesojurdesoju Member Posts: 59

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

  • rdesojurdesoju Member Posts: 59

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

  • amackenzieamackenzie Member, Employee Posts: 28 Solace Employee

    can you paste your publisher code?

  • rdesojurdesoju Member Posts: 59

    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

  • rdesojurdesoju Member Posts: 59

    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.

Sign In or Register to comment.