跳转到主要内容

bluesky的STOMP集成

项目描述

CI Coverage PyPI License

Bluesky Stomp

bluesky的STOMP集成

源代码 https://github.com/DiamondLightSource/bluesky-stomp
PyPI pip安装bluesky-stomp
发布 https://github.com/DiamondLightSource/bluesky-stomp/releases

低级API

该库包含一些用于与STOMP代理交互的帮助程序

from bluesky_stomp.messaging import MessageContext, StompClient
from bluesky_stomp.models import Broker, MessageQueue, MessageTopic

# Assumes you have an unauthenticated broker such as ActiveMQ running on localhost:61613
client = StompClient.for_broker(Broker(host="localhost", port=61613))

try:
    # Connect to the broker
    client.connect()

    # Send a message to a queue and a topic
    client.send(MessageQueue(name="my-queue"), {"foo": 1, "bar": 2})
    client.send(MessageTopic(name="my-topic"), {"foo": 1, "bar": 2})

    # Subscribe to messages on a topic, print all messages received,
    # assumes there is another service to post messages to the topic
    def on_message(message: str, context: MessageContext) -> None:
        print(message)

    client.subscribe(MessageTopic(name="my-other-topic"), on_message)

    # Send a message and wait for a reply, assumes there is another service
    # to post the reply
    reply_future = client.send_and_receive(
        MessageQueue(name="my-queue"), {"foo": 1, "bar": 2}
    )
    print(reply_future.result(timeout=5.0))
finally:
    # Disconnect at the end
    client.disconnect()

项目详情


下载文件

下载适用于您的平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分发

bluesky_stomp-0.1.2.tar.gz (33.3 kB 查看哈希值)

上传时间: 源代码

构建分发

bluesky_stomp-0.1.2-py3-none-any.whl (18.4 kB 查看哈希值)

上传于 Python 3

支持者