JMS doesn't provide a route to determine the consumer/session/connection
from a given Message, presumably because they are not in general tied to
specific instances of these (the only way I can think any are directly
related is the acknowledge() method). You would need to simply remember
such things in the application code when creating your MessageListener if
you want to use them later. A lambda would make that simple, but I guess
you cant use those given continued use of 0.11.1 implies you are on Java 7.

Regardless however, closing a Session from within its own onMessage thread
is a bit of a problem and not typically done. JMS 1.1 essentially defined
this should deadlock (close waiting for onMessage to complete), while JMS
2.0 resolved that by stating an explicit exception should be thrown (which
is what Qpid JMS now does) if failing or defining the behaviour for
AUTO_ACK usage if doing it. As such, to maintain portability and to proceed
with current clients, you would need to hand the session closure off to
anther thread, which probably then means stopping the connection first to
avoid racing against further deliveries on the session. Alternatively it
might be simpler not to use onMessage.

Robbie

On Mon, 7 Jan 2019 at 11:59, Alessandro Crotti - SMC Consulting <
a.cro...@smcconsulting.it> wrote:

> Hi,
>
> When I'm consuming a message (running onMessage() method) there could be a
> particular condition why I need to close that message session and open it
> again.
>
> My application starts a connection to the Broker with many Sessions and,
> for each of those Sessions, one MessageConsumer.
>
> When I receive a message, like usual, onMessage() method is triggered
> getting "message" object. On "message" object, I can access only to its
> connection but not to its session (neither its consumer).
>
> Having more sessions opened, I need to identify exactly the session on
> which the message has been received. Then I need to close it and open
> another new session.
>
> Do you know how to identify a message session on onMessage() method?
>
> All suggestions would be appreciated and code snippet would be even better.
>
> Best Regards
> --
> [image: SMC Consulting] <http://www.smcconsulting.it>
>
> [image: facebook]
> <http://www.facebook.com/SMC-Consulting-Srl-597548223675024/>  [image:
> linkeding] <http://www.linkedin.com/company/smc-consulting-srl> *Alessandro
> Crotti*
> Senior Developer
>
> tel:  +39 342 573 4450
> skype:  crotti.alessandro
>
> *SMC Consulting* <http://www.smcconsulting.it>
> Via dell'industria, 87 41012 Carpi (MO) - Italy
> tel: +39 059 664875
> CONFIDENTIALITY NOTICE: This message may contain confidential and/or
> privileged information.
> If you are not the intended recipient, please do not use its contents for
> any purpose, advise
> the sender immediately by reply e-mail and delete this message and any
> attachments without retaining a copy.
>

Reply via email to