DiamondLightSource / bluesky-stomp

STOMP messaging integration for bluesky
Apache License 2.0
1 stars 0 forks source link

Easy support for bluesky callbacks #14

Open callumforrester opened 3 months ago

callumforrester commented 3 months ago

As a user I want to run bluesky callbacks (of the form (name: str, doc: dict) -> None) in a separate process using a stomp broker as the intermediary for the documents.

Also requested by @olliesilvester to aid in the Hyperion migration.

Possible Solution

I imagine we want something that looks a bit like this

import bluesky.plans as bp
from bluesky.run_engine import RunEngine
from dodal.i22 import saxs, waxs
from ophyd_async.core import DeviceCollector
from bluesky_stomp.router import DocumentRouter
from bluesky.callbacks.best_effort import BestEffortCallback

username = input("Please enter your username")
password = input("Please enter your password", password=True)
auth = BasicAuthentication(username=username, password=password)

# We assume there is a RunEngine out there somewhere publishing documents to topic "foo"
router = DocumentRouter(host="localhost", port=61613, destination=Topic(name="foo"), auth=auth)
bec = BestEffortCallback()
router.subscribe(bec)

input("Press enter to finish")

Where we have a wrapper around StompClient that takes a RunEngine callback of the form (name, doc) -> None, bundles it into a dictionary of the form {"name": name, "doc": doc} and sends it to the desired destination.

Acceptance Criteria