Hi,
Sorry, this is a bit of a long post/question...

I have an application where I need to use the synchronous API of the
activemq-cpp library where I will have one thread that needs to subscribe
to, and receive messages from, multiple topics. After studying the API docs,
I don't see a way to efficiently wait for messages from multiple
MessageConsumer instances (belonging to the same Session) and receive the
messages in the order they were published. (I'm not sure that ActiveMQ
guarantees message order across multiple topics.) The only approach I see
would be to poll the consumers using receiveNoWait(); however, that will
burn CPU cycles and won't preserve message order across topics.

I experimented with adapting the Asynchronous API to my needs; however, I
can't use the MessageListener approach due to the need to perform
potentially long/complex processing within the onMessage callback function -
and deferring the processing till later leads to complexity with
Message/Request buffering within the client code under heavy message loads
(i.e. I can't implement flow control within client code without eventual
deadlocks).

This lead me to the MessageAvailableListener API, which seemed like a good
solution. I used an internal buffer to store pointers to MessageConsumer
instances with available messages (messages stay in the prefetch buffer, so
flow control works), then synchronize with an efficiently waiting receiver
to receive the messages. This almost worked; however, it appears that the
receiver does not always receive onMessageAvailable() callbacks for every
message delivered to the prefetch buffer, which causes the client code to
get out of synch with the incoming message flow. I'm not sure if this is a
bug or not, as the issue arises when dynamically subscribing to topics under
heavy load. I stop() the Connection, create the consumer, set the listener,
then start() the Connection, but messages still seem to arrive in the
prefetch buffer. (The test case for this is fairly complex...)

So, does anyone have any suggestions for an approach to have a single client
thread synchronously and efficiently receive messages from multiple message
consumers? (i.e. like the socket API and using the select() statement)

Thanks in advance!



--
View this message in context: 
http://activemq.2283324.n4.nabble.com/Activemq-cpp-Synchronous-Receive-from-Multiple-Consumers-tp4702375.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to