-
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
To handle event messages in Flux, you first have to subscribe to the event topic of interest with handle.event_subscribe. Then create a message watcher for the EVENT type message with handle.msg_watcher_create(). Finally start the message handler, then enter the reactor. Here's a simple example that subscribes to import flux
# Message handler callback:
# Args:
# handle: Flux handle on which the msg was receieved
# msg_handler: this message handler
# msg: the message
# arg, arbitrary argument passed to args parameter of msg_watcher_create()
#
def hb_cb(handle, msg_handler, msg, arg):
print(f"got {msg.topic}")
handle = flux.Flux()
# Subscribe to heartbeat.pulse event
handle.event_subscribe("heartbeat.pulse")
# Create a msg handler for the heartbeat.pulse event messages
msg_handler = handle.msg_watcher_create(
hb_cb, flux.constants.FLUX_MSGTYPE_EVENT, "heartbeat.pulse"
)
# The message handler is not enabled until .start() is called.
# (The msg handler can be stopped with .stop()
msg_handler.start()
# Run the reactor. The reactor will not stop until forcibly stopped with
# handle.reactor_stop() or if the message handler is stopped with
# msg_handler.stop() (if there are no other watchers enabled on this
# handle)
handle.reactor_run() |
Beta Was this translation helpful? Give feedback.
To handle event messages in Flux, you first have to subscribe to the event topic of interest with handle.event_subscribe. Then create a message watcher for the EVENT type message with handle.msg_watcher_create(). Finally start the message handler, then enter the reactor.
Here's a simple example that subscribes to
heartbeat.pulse
and calls a callback for each event: