pubsub 发布到节点成功,从节点检索失败

Posted

技术标签:

【中文标题】pubsub 发布到节点成功,从节点检索失败【英文标题】:pubsub publish to node success, retrieve from node fail 【发布时间】:2009-10-14 12:57:18 【问题描述】:

下面显示我建议发布到节点调用“ghost2”

iq id="kB8dk-0" to="computer/2c10ee6b" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>admin@computer/Smack</jid></bind></iq>
<iq id="kB8dk-1" to="admin@computer/Smack" type="result"></iq>
<iq id="kB8dk-2" to="admin@computer/Smack" type="result"><query xmlns="jabber:iq:roster"><item jid="test" name="test" subscription="none"></item><item jid="test@computer" subscription="from"></item></query></iq>
<message id="admin@computer__admin@computer__ChWrY" to="admin@computer" from="admin@computer"><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='null'><item id='ghost2'/></items></event></message>
<iq id="kB8dk-4" to="admin@computer/Smack" from="computer" type="result"></iq>
<iq id="kB8dk-5" to="admin@computer/Smack" from="computer" type="result"></iq>
<message id="ghost2__admin@computer__DGaLS" to="admin@computer" from="admin@computer"><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='ghost2'><item id='testid2'><book xmlns="pubsub:test:book"><title>book x</title></book></item></items></event></message>

但是当我尝试从同一个节点订阅和检索时,我收到错误 404

<iq id="zpWDI-0" to="computer/b7fe68a8" type="result"><bind xmlns="urn:ietf:params:xml:ns:xmpp-bind"><jid>test@computer/Smack</jid></bind></iq>
<iq id="zpWDI-1" to="test@computer/Smack" type="result"></iq>
<iq id="zpWDI-2" to="test@computer/Smack" type="result"><query xmlns="jabber:iq:roster"><item jid="admin@computer" name="test" subscription="to"><group>Friends</group></item><item jid="test" name="test" subscription="none"></item></query></iq>
<presence id="kB8dk-3" to="test@computer/Smack" from="admin@computer/Smack"></presence>
<message id="admin@computer__test@computer__tAVfB" to="test@computer/Smack" from="admin@computer"><event xmlns='http://jabber.org/protocol/pubsub#event'><items node='TestNode2323'><item id='2Ke42PVQ77iSCP0'><book xmlns="pubsub:test:book"><title>book x</title></book></item></items></event><x xmlns="jabber:x:delay" stamp="20091013T14:16:32"></x><addresses xmlns="http://jabber.org/protocol/address"><address type="replyto" jid="admin@computer/god"/></addresses></message>
<iq id="zpWDI-4" to="test@computer/Smack" from="computer" type="error"><query xmlns="http://jabber.org/protocol/disco#info" node="ghost2"></query><error code="404" type="CANCEL"><item-not-found xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/></error></iq>

【问题讨论】:

【参考方案1】:

您已收到已发布的项目:

<book xmlns="pubsub:test:book"><title>book x</title></book>

您已从“计算机”(您的 xmpp 服务器)收到此查询的 404 错误:

<query xmlns="http://jabber.org/protocol/disco#info" node="ghost2"></query>

这与服务发现有关。您是否有可能从整个对话中删除了一些消息?

编辑:

您可以尝试替换吗:

PubSubManager manager = new PubSubManager(connection, "computer");

有了这个

String pubSubAddress = "pubsub." + connection.getServiceName();
PubSubManager manager = new PubSubManager(connection, pubSubAddress);

【讨论】:

我认为您可能为了便于阅读而删除了一些消息,例如正如你的意思他们是无关的。但正如您在对上一个问题的评论中提到的那样:您将哪个库用于 pubsub?我也在使用 pubsub,但不必担心原始消息。 我正在使用 smackx pubsub。你呢? 另外,从响应中,“book x”来自节点“TestNode2323”..你能评论一下吗?【参考方案2】:

也许这个例子可以作为你的参考:

public void login(String Ip,String username,String passwaord)
     
         try 
         
            connConfig = new androidConnectionConfiguration(Ip, 5222);
            connection = new XMPPConnection(connConfig);
            connection.connect();  
            connection.login(username, passwaord);
            pubSubAddress = "pubsub."+ connection.getServiceName();
            manager = new PubSubManager(connection,pubSubAddress);
            Log.i("MyError","connection success");  
         
         catch (XMPPException e) 
         
             Log.i("MyError","connection failed");      
             e.printStackTrace();
         

     

另外,您可以参考与您相关的another question。

希望这会有所帮助。

【讨论】:

【参考方案3】:

也许你可以参考这个例子:

import org.jivesoftware.smack.XMPPConnection;
import org.jivesoftware.smackx.pubsub.ItemPublishEvent;
import org.jivesoftware.smackx.pubsub.Node;
import org.jivesoftware.smackx.pubsub.PayloadItem;
import org.jivesoftware.smackx.pubsub.PubSubManager;
import org.jivesoftware.smackx.pubsub.listener.ItemEventListener;
public class XmppPubsub_Reciever 
    private static XMPPConnection connection = new XMPPConnection("think");
    private static String USRE_NAME = "user";
    private static String PASSWORD = "1";
    static 
        try 
            connection.connect();
            connection.login(USRE_NAME, PASSWORD);
         catch (Exception e) 
            e.printStackTrace();
        
    
    public static void main(String[] args) throws Exception 
        String nodeId = "test";
        PubSubManager manager = new PubSubManager(connection);
        Node eventNode = manager.getNode(nodeId);
        eventNode.addItemEventListener(new ItemEventListener<PayloadItem>() 
            public void handlePublishedItems(ItemPublishEvent evt) 
                for (Object obj : evt.getItems()) 
                    PayloadItem item = (PayloadItem) obj;
                    System.out.println("--:Payload=" + item.getPayload().toString());
                
            
        );
        eventNode.subscribe(connection.getUser());
        while(true);
    

【讨论】:

以上是关于pubsub 发布到节点成功,从节点检索失败的主要内容,如果未能解决你的问题,请参考以下文章

Openfire 服务器端订阅节点

XMPP Pubsub 节点发现,未找到项目

asmack pubsub getItems 错误

在 asmack 中将项目发送到 pubsub 节点

使用 strophe.pubsub 插件为多个发布者配置 pubsub 节点或创建白名单

将消息发布到 GCP pubSub 主题失败