Python sleekxmpp子示例

Python sleekxmpp子示例,python,xmpp,publish-subscribe,Python,Xmpp,Publish Subscribe,我正在寻找一个用于实现SleekXMPP XEP 60插件的工作示例代码。 我想做的是 通过TLS进行身份验证并订阅名为“blogupdates”的节点 然后,只需等待事件并获取事件中包含的数据 我已经搜索了几天,但我找不到一个好的工作例子谷歌左右 请注意,我不是订阅用户,而是一个节点,因此发布者可以是任何人 有什么帮助吗?如果您查看SleekXMPP邮件列表()上的这个线程,我有一个Pubsub客户端示例,您可以试用和检查。我将整理和润色这两个脚本,以便很快添加到捆绑示例中 (编辑:这些文件现

我正在寻找一个用于实现SleekXMPP XEP 60插件的工作示例代码。 我想做的是 通过TLS进行身份验证并订阅名为“blogupdates”的节点 然后,只需等待事件并获取事件中包含的数据 我已经搜索了几天,但我找不到一个好的工作例子谷歌左右

请注意,我不是订阅用户,而是一个节点,因此发布者可以是任何人


有什么帮助吗?

如果您查看SleekXMPP邮件列表()上的这个线程,我有一个Pubsub客户端示例,您可以试用和检查。我将整理和润色这两个脚本,以便很快添加到捆绑示例中

(编辑:这些文件现在位于开发分支的examples目录中。请参阅和)

对于您的用例,您应该:

xmpp['xep_0060'].subscribe('pubsub.example.com', 'blogupdates')
要获得更高级的使用,您还可以传递:

bare=False
# Subscribe using a specific resource, and not the bare JID

subscribee='somejid@example.com'
# Subscribe a different JID to the node, if authorized

options=data_form
# Provide subscription options using a XEP-0004 data form
但是,如果您使用的是develop分支,我已经添加了一些更新的功能,您可能希望能够更轻松地处理发布事件:

# Generic pubsub event handlers for all nodes
xmpp.add_event_handler('pubsub_publish', handler)
xmpp.add_event_handler('pubsub_retract', handler)
xmpp.add_event_handler('pubsub_purge', handler)
xmpp.add_event_handler('pubsub_delete', handler)

# Use custom-named events for certain nodes, in this case 
# the User Tune node from PEP.
xmpp['xep_0060'].map_node_event('http://jabber.org/protocol/tune', 'user_tune')
xmpp.add_event_handler('user_tune_publish', handler)
# ...
# The same suffixes as the pubsub_* events.
# These events are raised in addition to the pubsub_* events.
对于事件处理程序,您可以遵循以下模式:

def pubsub_publish(self, msg):
    # An event message could contain multiple items, but we break them up into
    # separate events for you to make it a bit easier.
    item = msg['pubsub_event']['items']['item']
    # Process item depending on application, like item['tune'], 
    # or the generic item['payload']
您可以查看XEP-0107和相关的PEP插件以查看更多示例,因为这些特性是为了实现这些功能而添加的

因此,以下是您的用例:

# Note that xmpp can be either a ClientXMPP or ComponentXMPP object.
xmpp['xep_0060'].map_node_event('blogupdates', 'blogupdates')
xmpp['xep_0060'].add_event_handler('blogupdates_publish', blogupdate_publish)
xmpp['xep_0060'].subscribe('pubsub.example.com', 'blogupdates')
# If using a component, you'll need to specify a JID when subscribing using:   
# ifrom="specific_jid@yourcomponent.example.com"

def blogupdate_publish(msg):
    """Handle blog updates as they come in."""
    update_xml = msg['pubsub_event']['items']['item']['payload']
    # Do stuff with the ElementTree XML object, update_xml
最后,如果你发现自己在谷歌上花了太多时间搜索,请访问时尚的聊天室:sleek@conference.jabber.org


--兰斯

非常感谢你。我现在有了一些想法。我今天会尝试一下,当然,现在我知道在哪里可以找到你们了,我会经常在聊天室闲逛。当然,我们可以使用您完善的pubsub脚本,主要是作为客户机sub,因为这在python相关开发中最有用,我们希望用XMPP替换MQ,我认为这将在不久的将来成为一个主要用例。感谢againit的工作,但在我通过pip安装的发行版中,我有相同的版本:(无论如何,谢谢啊,是的。PyPI上的1.0版本已经发布了几个月了,并且已经修复了很多bug,就像你指出的那样。我们一直在等待一些插件的开发完成,但是我们可能会继续,很快发布一个版本来修复这些bug。太棒了。我会尝试使用开发分支。我是一个假设我的代码从发布版本可以用于开发,我没有看到对类和方法结构的任何更改。非常感谢,sleek是一个很棒的库。我想发布一个更新。Lance非常有帮助,谢谢Lance,在jabber配置中获取他的hep。其次,一切都与开发分支完美配合。我很高兴请确认此项目存在。