簡體   English   中英

訂閱橫桿高速公路上 python 中的主題

[英]subscribe to a topic in python on crossbar autobahn

我是橫梁的菜鳥。 我正在嘗試使用 python 中的高速公路和橫桿訂閱主題。

橫桿 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>

如前所述,我對此並不陌生,因此將不勝感激任何有關上述內容的見解!

我認為你想要做的是:

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')

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM