Search code examples
javaxmppactivemq-classicclient-sidesmack

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!


Solution

  • 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!