【问题标题】:subscribe to a topic in python on crossbar autobahn在横杆高速公路上订阅 python 中的主题
【发布时间】:2019-10-25 13:06:05
【问题描述】:

我是横梁的菜鸟。 我正在尝试在 python 中使用高速公路和横杆来订阅主题。

crossbar url是“wss://******.******.org/ws/”,主题是c******d。

没有信号主题,每次调用都转到这个主题c******d。

我在那里找到了一些代码 https://autobahn.readthedocs.io/en/latest/ 并尝试对其进行调整。

from autobahn.twisted.component import Component
from twisted.internet.defer import inlineCallbacks
from autobahn.twisted.component import Component
from autobahn.twisted.component import run

#component with my crossbar url :

component = Component(
     transports=u"wss://******.******.org/ws/",       
     realm=u"realm1",
 )

@component.on_join
@inlineCallbacks
def joined(session,details):
    print("session ready")

    def oncounter(count):
        print("event received: {0}", count)

    try:
        yield session.subscribe(oncounter, u'c******d') #here my topic
        print("subscribed to topic")
    except Exception as e:
        print("could not subscribe to topic: {0}".format(e))

if __name__ == "__main__":
     run([component]) 

我收到此错误。似乎没有任何工作正常。

2019-10-25T14:38:07+0200 SSL error: certificate verify failed (in tls_process_server_certificate)
2019-10-25T14:38:07+0200 TLS failure: certificate verify failed
2019-10-25T14:38:07+0200 Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:09+0200 connecting once using transport type "websocket" over endpoint "tcp"
2019-10-25T14:38:09+0200 Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:09+0200 SSL error: certificate verify failed (in tls_process_server_certificate)
2019-10-25T14:38:09+0200 TLS failure: certificate verify failed
2019-10-25T14:38:09+0200 Stopping factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>
2019-10-25T14:38:12+0200 connecting once using transport type "websocket" over endpoint "tcp"
2019-10-25T14:38:12+0200 Starting factory <autobahn.twisted.websocket.WampWebSocketClientFactory object at 0x000002B693A58>

如前所述,我是新手,因此对上述内容的任何见解将不胜感激!

【问题讨论】:

    标签: python autobahn crossbar


    【解决方案1】:

    我认为你想要做的是:

    import sys 
    import asyncio
    from autobahn.asyncio.wamp import ApplicationSession, ApplicationRunner
    import autobahn.wamp
    
    
    class Component(ApplicationSession):
    
        """
        An application component that subscribe to a topic
        and print messages
    
        """
        async def onJoin(self, details):
    
            def onmessage(*args, **kwargs):
                print ("message received kwargs= "+str(kwargs))
    
            await self.subscribe(onmessage, "c******d")
    
        def onDisconnect(self):
    
            asyncio.get_event_loop().stop()
    
    if __name__ == '__main__':
    
            url = u"wss://************.org/ws/"
            realm = u"realm1"
            runner = ApplicationRunner(url, realm)
            runner.run(Component,'debug')
    
    

    【讨论】:

    • 欢迎来到 SO!当你回复一个问题时,试着解释一下,而不是粘贴代码。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多