Sleekxmpp订阅和事件不适用于相同的用户会话

时间:2014-09-26 10:25:37

标签: python xmpp publish-subscribe

我正在尝试使用时尚的xmpp实现pub sub。下面是光滑的xmpp下的示例重构的发布和订阅代码。我正在做的是我通过user1 / resourceB从会话订阅user1 / resourceA的节点n1(节点的创建者)。问题是

  • 当我从user1 / resourceA发布msg时,虽然订阅成功,但我没有在user1 / resourceB中获得节点n1的事件。
  • 当我从user1 / resourceB发布到节点n1时,我从同一会话中获取事件发布但不发布到其他会话。即从作为节点创建者的user1 / resourceA订阅节点n1。在这种情况下,我得到的是事件。

    def create(self,node_name,config=None):
      try :        
          self['xep_0060'].create_node(self.pubsubserver,node_name,config=config)
     except:
          logging.error('Could not create node: %s' % node_name)
    
    def publish(self,node_name,payload,_id=None):
          print 'entering pubsub publish'
          payload_xml = ET.fromstring("<test xmlns='test'>%s</test>" % payload)
          ET.dump(payload_xml)
          try:
             result = self['xep_0060'].publish(self.pubsubserver, node_name,payload=payload_xml)
    
        except:
             logging.error('Could not publish to: %s' % node_name)
    def subscribe(self,node_name,cb,options=None):
       try:
           self['xep_0060'].map_node_event(node_name,node_name)
           self.add_event_handler('n1_publish',cb)
           result = self['xep_0060'].subscribe(jid=self.pubsubserver, node=node_name)
           print('Subscribed to node %s' % (node_name))
       except:
           logging.error('Could not subscribe')
    

日志:

#logs for create node n1
  xmlstream: 1728 SEND: <iq to="xmppserver.com" type="set"  id="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb17011"><pubsub xmlns="http://jabber.org/protocol/pubsub">
   <create node="n1" /></pubsub></iq>
   xmlstream: 1603 RECV: <iq from="xmppserver.com" type="result" id="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb17011" to="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb170" />


 #logs for subscribe to node n1 from session2 
    xmlstream: 1728 SEND: <iq to="xmppserver.com" type="set" id="test@xmppserver.com/test2d487986-4564-11e4-b710-3c970eebb1707"><pubsub xmlns="http://jabber.org/protocol/pubsub"><subscribe node="n1" jid="test@xmppserver.com" /></pubsub></iq>
    xmlstream: 1603 RECV: <iq from="xmppserver.com" type="result" id="test@xmppserver.com/test2d487986-4564-11e4-b710-3c970eebb1707" to="test@xmppserver.com/test2d487986-4564-11e4-b710-3c970eebb170"><pubsub xmlns="http://jabber.org/protocol/pubsub"><subscription node="n1" jid="test@xmppserver.com" subscription="subscribed"><subscribe-options /></subscription></pubsub></iq>


 #logs for publish to node1 from session1
  publish n1 session1
  test_pubsub: 59 publish to node n1 with data session1 :
  entering pubsub publish
  <ns0:test xmlns:ns0="test">session1</ns0:test>
  <iq to="xmppserver.com" type="set" id="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb17013"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publish node="n1"><item><test xmlns="test">session1</test></item></publish></pubsub></iq>
  xmlstream: 1728 SEND: <iq to="xmppserver.com" type="set" id="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb17013"><pubsub xmlns="http://jabber.org/protocol/pubsub"><publish node="n1"><item><test xmlns="test">session1</test></item></publish></pubsub></iq>
  xmlstream: 1603 RECV: <iq from="xmppserver.com" type="result" id="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb17013" to="test@xmppserver.com/testff388888-4563-11e4-ad83-3c970eebb170" />
  xmlstream: 1603 RECV: <message to="test@xmppserver.com" from="test@xmppserver.com" id="n1__test@xmppserver.com__fE85u"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="n1"><item id="4be1b29a-4af8-4456-a5c8-0a311dabce4937"><test xmlns="test">session1</test></item></items></event></message>

xmlstream: 1156 Event triggered: pubsub_publish
test_pubsub: 36 1. create  <node name>
xmlstream: 1603 RECV: <message to="test@xmppserver.com" from="test@xmppserver.com" id="n1__test@xmppserver.com__fE85u"><event xmlns="http://jabber.org/protocol/pubsub#event"><items node="n1"><item id="4be1b29a-4af8-4456-a5c8-0a311dabce4937"><test xmlns="test">session1</test></item></items></event></message>

我正在使用Openfire服务器进行Xmpp

0 个答案:

没有答案