Consuming message from specific Topic subscription added in Queue
Hi,
I have created the queue with topic subscriptions(more than 1 topic subscription), as below.
"queueName": "QUE_TEST"
"subscription_topics": [
"Demo/Msg",
"Demo"
]
now, I am interested in consuming message published to specific topic, like from 'Demo/Msg'. I have created the flow with queue to consume the messages published, so its giving me all messages published on topics under queue, no idea that which message is from which topic. Below is code I have implemented, how to get messages from specific topic under queue?
var endpoint = ContextFactory.Instance.CreateQueue(queue);
var Flow = InternalSolaceSession.CreateFlow(new FlowProperties()
{
AckMode = MessageAckMode.AutoAck
}, endpoint, null, HandleMessageEvent, HandleFlowEvent);
Flow.Start();
Comments
-
Hi @Amol D
You can still find out the topic that particular message was published. I'm guessing for dotnet you can use the IMessage.Destination properties (ref)
But...
I had to ask, why would you want to do that? What is the objective?
A couple of points came to mind:
- The idea of having Queues as your 'consumption' endpoint with topic subscriptions - means you get the flexibility of adding/changing topic subscriptions without any impact on the consumer apps.
- If you'd like to subscribe directly to such topics, but do not require persistency, then just do a direct topic subscription. Here's the tutorial for dotnet for reference.
- Or, you could just create another Queue for that specific topic subscription :)
-Ari
0 -
Thanks @arih
Since we wanted message persistency and multiple consumer support, we have opted queues with topic subscription.
I am able to get the topic name with the help of IMessage.Destination properties. however I was keen to understand how I can apply filtering while subscribing the queue.
0 -
Hi @Amol D ,
I recommend to think about multiple queues for different consumers - in other words make more fine-grained Queues :)
We can get the original destination topic, but I don't recommend to use that to 'filter'. The filtering should happen when the routing is happening within the broker / event mesh.
0 -
Thanks @arih , I will think about multiple queue.
one more question(using .net), I using client ack mode to send the message acknowledgment, however, however its not working as messages are still there on solace, below is the consume and message handler code.
Would you advise here?
0 -
In the source code you have shown, It is unclear how you are persisting the flow instance. In
SubscribeAndHandle()
I see you have declared a local variable,var Flow
, and in theHandleMessageEvent
callback, there is a class field_flow
.Is there some part of the code which is missing here?
Otherwise, the code is generally correct; however, with some caveats that the local
queue
variable on which the flow is based may be disposed prematurely as soon as theSubscribeAndHandle()
method completes. I am not sure what effect that might have on the flow instance.Can you verify that the
_flow.Ack(...)
call is returningReturnCode.SOLCLIENT_OK
?0