SMF sample for Batch/Transacted Send and Receive

rdesoju
rdesoju Member Posts: 66
edited March 2020 in PubSub+ Event Broker #1

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

  • amackenzie
    amackenzie Member, Employee Posts: 262 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.

  • rdesoju
    rdesoju Member Posts: 66
    edited March 2020 #3

    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.

  • amackenzie
    amackenzie Member, Employee Posts: 262 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.

  • rdesoju
    rdesoju Member Posts: 66

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

  • rdesoju
    rdesoju Member Posts: 66

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

  • amackenzie
    amackenzie Member, Employee Posts: 262 Solace Employee

    can you paste your publisher code?

  • rdesoju
    rdesoju Member Posts: 66

    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

  • rdesoju
    rdesoju Member Posts: 66

    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.