activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christopher Shannon <>
Subject Re: Do all Message usage have to be within onMessage?
Date Mon, 22 Jun 2015 01:14:39 GMT
Usually, if you think you might need to rollback a message you should just
want to handle that message in onMessage. What is the reason to share
messages between threads?  Is it just to be able to consume more than one
message at a time?  If so I would encourage you to just start multiple
consumers instead of trying to pass messages to another thread from one
consumer.  On of my favorite ways to have multiple consumers and to handle
messages concurrently is to use Spring's DefaultMessageListenerContainer.

JMS is really designed to handle messages in the same thread they were
consumed.  A Session and a MessageConsumer are both only single threaded
and shouldn't be shared across threads, for example.   In the past I have
done something where i've had a message listener receive messages and then
pass them to other threads in a thread pool to increase throughput but I
immediately acknowledged the messages before passing them.  This has the
disadvantage of not being able to roll back if something happens during

If really want to try and pass messages to other threads you might be able
to get something to work if you use individual acknowledgement since only a
single message will be acknowledged. (I haven't tested this so I could be
wrong) Trying to forward a message to another thread while using
transactions won't work because when you call commit all messages received
since the last commit would be committed. The same for client acknowledge

On Sun, Jun 21, 2015 at 6:41 PM, Kevin Burton <> wrote:

> If you’re using a MessageListener, what’s the best way to use that Message
> in other threads? I was thinking of reading the message as a string, then
> forwarding the *string* to other threads, with just a reference to the
> message.  Then stick it back in a queue so that the original thread can
> commit the message.
> --
> Founder/CEO
> Location: *San Francisco, CA*
> blog:
> … or check out my Google+ profile
> <>

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message