我们想为 ejabberd 构建一个简单的服务器组件,它接收发送到 MUC 房间的所有消息(我们有很多房间,并且一直在创建新房间),并在处理其中一些消息后执行一些操作。
我们不希望我们的服务器组件像机器人一样工作,所以我们不希望它回复消息或类似的东西,我们只希望它接收所有消息的副本以处理其中一些消息。
为此,我们遵循了此处提供的教程:https ://sleekxmpp.readthedocs.io/en/latest/getting_started/component.html
问题是该组件似乎只接收到一些消息(大约 5 条消息中的 1 条)。
此外,我们观察到一种奇怪的行为:消息传递似乎是“排他性的”,这意味着消息要么被传递到连接到房间的客户端,要么被传递到服务器组件,说实话这很奇怪。换句话说,5 条消息中的 1 条消息被传递到服务器组件,另外 4 条消息照常传递给客户端。
这是我们的组件代码(我们尝试过使用 slimxmpp 和 slixmpp,但我们总是有相同的行为):
import sys
import logging
#import sleekxmpp
#from sleekxmpp.componentxmpp import ComponentXMPP
import slixmpp
from slixmpp.componentxmpp import ComponentXMPP
if sys.version_info < (3, 0):
from sleekxmpp.util.misc_ops import setdefaultencoding
setdefaultencoding('utf8')
else:
raw_input = input
class NotificationsComponent(ComponentXMPP):
def __init__(self):
ComponentXMPP.__init__(self, "muc.ourservice.it", "secret", "jabber.ourservice.it", 5233)
# add handler
self.add_event_handler("message", self.message)
#self.add_event_handler("groupchat_message", self.message)
def message(self, msg):
if msg['type'] == 'groupchat':
print('Received group chat message')
print(msg)
#msg.reply('Well received').send()
else:
print('Received another message')
if __name__ == '__main__':
logging.basicConfig(level=logging.DEBUG,format='%(levelname)-8s %(message)s')
xmpp = NotificationsComponent()
xmpp.register_plugin('xep_0030') # Service Discovery
#xmpp.register_plugin('xep_0004') # Data Forms
#xmpp.register_plugin('xep_0060') # PubSub
xmpp.register_plugin('xep_0199') # XMPP Ping
#xmpp.register_plugin('xep_0045') # MUC
# Connect to the XMPP server and start processing XMPP stanzas.
xmpp.connect()
xmpp.process()
这是我们的 ejabberd 18.03 配置的片段:
listen:
-
port: 5222
ip: "::"
module: ejabberd_c2s
starttls: true
certfile: 'CERTFILE'
protocol_options: 'TLSOPTS'
## dhfile: 'DHFILE'
## ciphers: 'CIPHERS'
##
## To enforce TLS encryption for client connections,
## use this instead of the "starttls" option:
##
starttls_required: true
##
## Stream compression
##
zlib: true
##
max_stanza_size: 65536
shaper: none
access: c2s
-
port: 5280
ip: "::"
module: ejabberd_http
request_handlers:
"/admin": ejabberd_web_admin
"/bosh": mod_bosh
#request_handlers:
# "/ws": ejabberd_http_ws
# "/bosh": mod_bosh
# "/api": mod_http_api
## "/pub/archive": mod_http_fileserver
web_admin: true
http_bind: true
## register: true
captcha: false
certfile: 'CERTFILE'
tls: true
-
port: 5233
ip: "::"
module: ejabberd_service
access: all
privilege_access:
message: "outgoing"
password: "secret"
shaper: none
我们也尝试过使用 access、privilege_access 和类似的东西,但没有运气。
你知道什么可能导致这种奇怪的行为吗?是否应该启用任何特定的插件或模块?
当然,我们在 slimxmpp 和 ejabberd 上都启用了调试日志,但是我们没有看到任何错误,只是缺少消息。
我们还做了一项测试。即使使用 slixmpp 存储库中提供的官方“回声组件”示例,我们也会遇到同样的问题。所以看起来我们的服务器有问题,也许是消息路由部分,我们不知道。
谢谢