读取使用咂嘴传入的消息包中发布订阅

读取使用咂嘴传入的消息包中发布订阅

本文介绍了读取使用咂嘴传入的消息包中发布订阅的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用的Openfire 服务器和 asmack 库来实现PubSub的。我有这样一种方式,用户已采取了出版商批准配置我的节点

i am trying to implement pubsub using openfire server and asmack library.i have configured my node in such a way that subscribers has to take the approval of publishers

现在我想读的信息使用下面的code 包,但我没有得到任何数据包。我想读消息数据包,因为我想知道每当用户请求发送给出版商获得认购。

now i am trying to read the Message packet using following code but i am not getting any packet. i want to read Message packet because i want to know whenever the subscribers send the request to publishers to get subscribe.

PacketTypeFilter filter = new  PacketTypeFilter(org.jivesoftware.smack.packet.Message.class);

    PacketListener myListener = new PacketListener(){

        @Override
        public void processPacket(Packet packet) {
            // TODO Auto-generated method stub

            Log.d("PACKET" , "READ");

            if(packet instanceof org.jivesoftware.smack.packet.Message){

                    org.jivesoftware.smack.packet.Message msg = (org.jivesoftware.smack.packet.Message) packet;

            Log.d("MY MESSAGE" , msg.toXML()+ "");


                    }
                }

            };

    cxmpp.addPacketListener(myListener, filter);

我要的是读取传入消息包

All i want is to read the incoming Message Packets

推荐答案

如果你把所有的配置位和你的PubSub的部件正常工作,然后得到一个正常的消息,你会做这样的事情:

If you have all the configuration bits and your pubsub component correctly working, then for getting a normal message you would do something like:

ConnectionConfiguration config = new ConnectionConfiguration("ADDRESS",PORT); // service name, also known as XMPP domain of the target server.
config.setServiceName(this.pubsubServiceAddress);
connection = new XMPPConnection(config);
connection.connect();

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

connection.addPacketListener(new PacketListener() {
    public void processPacket(Packet packet) {
    Message mes = (Message)packet;
        // do your stuff here
    }
}, filter);

这篇关于读取使用咂嘴传入的消息包中发布订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-03 02:10