简体   繁体   English

XMPP客户端(带有smack)和ActiveMQ,如何截获“ adminConsole”消息

[英]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). 我已经制作了一个非常简单的Java应用程序(仅是一个证明),并且我可以将其连接到ActiveMQ消息布鲁克(安装在我用来测试Java应用程序的同一台计算机上)没有问题。 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). 我在下面的应用程序中设置了messageListener,但是我不确定它是否在正确的位置,也不确定插入消息的正确方法(例如,管理员使用“发送到”选项发送的消息) ActiveMQ控制台,如本文下部链接中所述)。 Here is the code for the messageListener: 这是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). 这或多或少是我想要做的,使用我的java应用程序而不是spark(我已经可以使用spark做到这一点)。 ActiveMQ with XMPP 带有XMPP的ActiveMQ

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. 我不知道ActiveMQ如何处理XMPP,但很有可能ActiveMQ不会基于您创建的同一聊天向您发送消息。 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 聊天使用线程ID进行协调,如果MQ使用不同的线程发送消息,或者根本不使用任何消息发送,则它可能与您创建的聊天不匹配,因此不会调用您的侦听器

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. 尝试将一个侦听器添加到ChatManager ,以获取有关新传入聊天的通知,并尝试使用-Dsmack.debugEnabled = true来确保您实际上从ActiveMQ接收了数据包。

BTW, your PacketFilter is not used in this scenario, that is used when you put a listener directly on the Connection. 顺便说一句,在这种情况下不使用您的PacketFilter,当您将侦听器直接放在Connection上时使用。

I hope it's not only a fluke. 我希望这不仅是uke幸。 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. Apache ActiveMQ Artemis支持拦截器来拦截进入和退出服务器的数据包。 An interceptor for the core protocol must implement the interface Interceptor . 核心协议的拦截器必须实现接口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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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