Try PubSub+

Acknowledge message using ID

lilyevskylilyevsky Member Posts: 6

I usually acknowledge messages explicitly using BytesXMLMessage.ackMessage() method.
This is pretty convenient, because I don't need to worry about how it is done in the implementation. However, there is one essential problem: I need to have the message object around when I want to call the ackMessage(). In my specific scenario (which may be actually very common), I extract data from the message and do some processing, and I want to acknowledge it only if everything goes without errors. I saw somewhere in Solace API documentation that it is not recommended to cache messages; in any case, keeping them around for too long is a waste of memory. Besides, under Flink environment which I am using, with all that checkpoint infrastructure, keeping Solace messages is very problematic.
Here is my question: can I just save a little piece of that message (some sort of ID) which I can later use to do the ack? I believe that when I call ackMessage(), inside it uses some ID to send to the broker anyway, it should not need the whole message.

Tagged:

Comments

  • lilyevskylilyevsky Member Posts: 6

    I think I found the solution.
    In my code I use synchronous consumer of the FlowReceiver type, I get it like this:
    flow = session.createFlow(null, flowProperties);
    It appears that the actual runtime type of it is FlowHandleImpl, which can be cast to interface FlowHandle:
    flowHandle = (FlowHandle) flow;
    Then, from each message I can retrieve message ID, using getMessageIdLong() method. Then I use flowHandle to send the ack:
    flowHandle.sendSingleAck(id, true);
    Not sure about the second parameter, should I set it to false?
    Anyway, I tested it and it works.

  • AaronAaron Member, Moderator, Employee Posts: 88 Solace Employee

    Hey @lilyevsky . Slowly getting around to responding to your various posts. Thanks for pointing out this (unofficial) way of being able to ACK a message based on an ID. It's something we're discussing internally at Solace about supporting officially, so maybe in the future, who knows? But yeah, I've been using JCSMP for quite a few years and never figured this out, so VERY COOL!

    I also mentioned it in my weekly Twitch livestream. And apologies for butchering your name! :cry:

Sign In or Register to comment.