Topic dispatching with guaranteed delivery using JCSMP
Hi there,
The article here explains how one can have custom callback to handle guaranteed messages received with matching topics thru flows bound to queues using Java RTO. Is there something similar for the JCSMP API, or another way that we can achieve something like that?
On a related note, there's normally only be one active flow per queue, but with this feature, is it one active flow per topic subscription per queue? If so, how does it work if a message matches multiple topic subscriptions?
Essentially, what I am trying to achieve is multiple subscribers within the same app (with possible overlap in terms of intended messages), but I am trying to avoid the if-else blocks for the handlers if possible. So I was wondering if this feature could come in handy because even with the selectors set in the flows, only one flow ever remains active, so I am having to have a common handler to consume the guaranteed messages from the queue before delegating based on the topic on the message.
Best Answer
-
JCSMP does not support topic dispatch. The feature is specific to the C-API and its derivatives (which Java RTO is one).
In the new Java API recently released, the use case you mention is a fundamental part of its design. You define a
MessagingService
and on that you can define multipleMessageReceivers
which each have their own subscription list. Thus you get a message handler per receiver and the subs can be set up in an even more versatile way than with Topic Dispatch.0
Answers
-
JCSMP does not support topic dispatch. The feature is specific to the C-API and its derivatives (which Java RTO is one).
In the new Java API recently released, the use case you mention is a fundamental part of its design. You define a
MessagingService
and on that you can define multipleMessageReceivers
which each have their own subscription list. Thus you get a message handler per receiver and the subs can be set up in an even more versatile way than with Topic Dispatch.0 -
Great, I just came across this video of yours and some code samples here: https://github.com/SolaceSamples/solace-samples-java. I will try it out myself, but that certainly answers my question. Thanks!
0 -
I wished I'd found this post earlier..! I made topic dispatch for JCSMP, and have been using it quite successfully in a couple of my apps for a while. Find it here: https://github.com/aaron-613/jcsmp-topic-dispatch
I think the code is pretty self-explanatory, it's not that hard. There's a (slightly faster) linear scan algorithm for doing the matching, or you can generate a regex Pattern for your sub that allows you to just use a Matcher. Some convenience methods.
I should probably clean up the code a bit and maybe improve the README. And maybe migrate it to SolaceLabs GitHub… it might get more attention there.
0