简体   繁体   中英

Getting username in Spring JMS listener

I already posted a question on this topic some two days earlier, but it was much more complicated question. Now, to put it more simply:

Is there a way to obtain username, used to connect the broker, in spring JMS listener? I have found only MessageListener and SessionAwareMessageListener, but I'm not able to obtain this information (or Connection instnace) from neither Session, nor Message instance.

Am I missing something obvious?

I'm using ActiveMQ embedded broker.

OK, the obvious answer was, that the connection listener is on is not the same connection as the client is on... Therefore, there is NO POINT of obtaining the connection handle...

Stupid me...

PS: I'm leaving it here to warn the future generations.

How about?

@JmsListener(destination = "mytopic")
public void processMessage(BytesMessage message) {
    ActiveMQBytesMessage msg = (ActiveMQBytesMessage) message;
    ActiveMQConnection conn = msg.getConnection();
    ConnectionInfo info = conn.getConnectionInfo();
    String username = info.getUserName();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM