简体   繁体   中英

XMPP Client (with smack) and ActiveMQ, how to intercept “adminConsole” message

I've made a very simple java application (it's only a proof) and I've no problem to connect to my ActiveMQ message brooker (that is installed on the same machine i'm using to test my java application). The problem is that I'm not able to intercept any message. I've set a messageListener in my application as below, but i'm not sure that it's in the right place, nor the correct way to intercep a message (for example a message sent with the "send to" option available in the admin console of ActiveMQ as described in the link in the lower part of this post). Here is the code for the messageListener:

/*................previous code is not relevant.................*/
ConnectionConfiguration config = new ConnectionConfiguration("192.168.43.5",61222); //to get my XMPP connector uri
String msg="";
config.setSASLAuthenticationEnabled(false);
config.setCompressionEnabled(false);
XMPPConnection xmpp = new XMPPConnection(config);

try {

    xmpp.connect(); 
    xmpp.login("name", "pw");
        /*Filter*/
    PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 
        /*MessageListener to get messages*/             
    MessageListener listen = new MessageListener() {
        @Override
        public void processMessage(Chat arg0, Message arg1) {
            // TODO Auto-generated method stub
            msg = "ok ";
            msg = arg1.toString();
            }
        };
    /*New chat with my messageListener*/
        Chat c = xmpp.getChatManager().createChat("admin", listen) ;
        c.sendMessage("enter text here");
    }
     catch (XMPPException e) {  
}
/*...............other code.......................*/

this is more or less what i want to do, using my java application instead of spark (i'm already able to do that with spark). ActiveMQ with XMPP

Thanks to all people who wants to help me!

I don't know how ActiveMQ works with regards to XMPP, but it is very likely that ActiveMQ is NOT sending you messages based on the same chat you created. Chats are coordinated using a thread id, and if MQ is sending using a different one, or none at all, it may not match up with the chat you created and therefore won't call your listener

Try adding a listener to the ChatManager , to get notified of new incoming chats and try running with -Dsmack.debugEnabled=true to make sure you are actually receiving the packets from ActiveMQ.

BTW, your PacketFilter is not used in this scenario, that is used when you put a listener directly on the Connection.

I hope it's not only a fluke. I've tryed to replace:

PacketFilter filter = new MessageTypeFilter(Message.Type.chat); 

with:

PacketFilter filter = new AndFilter(new PacketTypeFilter(Message.class));

And i've replaced:

MessageListener listen = new MessageListener() {
    @Override
    public void processMessage(Chat arg0, Message arg1)

with:

PacketListener ls= new PacketListener() {
@Override
public void processPacket(Packet arg0) 

and the listener now work well!

Apache ActiveMQ Artemis supports interceptors to intercept packets entering and exiting the server. An interceptor for the core protocol must implement the interface Interceptor .

There is an example in official tutorial: Intercepting Operations

package org.apache.activemq.artemis.api.core.interceptor;

public interface Interceptor
{
    boolean intercept(Packet packet, RemotingConnection connection) throws ActiveMQException;
}

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