Router

A router is responsible for initializing and holding all event modules, connecting their queues and organize the event flow between them.

The router object plays a central role in the Wishbone setup. When bootstrapping an instances using the CLI tooling you are not really exposed to it (though the routing table might give a hint), however if you create a server directly in Python you will always first have to initialize a Router instance:

input_config = ActorConfig("input")
output_config = ActorConfig("output")

router = Default()
router.registerModule(TestEvent, input_config, {"message": "Hello world!"})
router.registerModule(STDOUT, output_config)
router.connectQueue("input.outbox", "output.inbox")
router.start()
router.block()

Multiple routers can be initialized which run inside the same process.

from wishbone.actor import ActorConfig
from wishbone.router import Default
from wishbone.module.testevent import TestEvent
from wishbone.module.stdout import STDOUT

input_config = ActorConfig("input")
output_config = ActorConfig("output")

router_1 = Default()
router_1.registerModule(TestEvent, input_config, {"message": "Hello world from router instance 1!"})
router_1.registerModule(STDOUT, output_config)
router_1.connectQueue("input.outbox", "output.inbox")
router_1.start()

router_2 = Default()
router_2.registerModule(TestEvent, input_config, {"message": "Hello world from router instance 2!"})
router_2.registerModule(STDOUT, output_config)
router_2.connectQueue("input.outbox", "output.inbox")
router_2.start()

router_1.block()
router_2.block()
$ python 2_routers.py
Hello world from router instance 1!
Hello world from router instance 2!
Hello world from router instance 1!
Hello world from router instance 2!
Hello world from router instance 1!
Hello world from router instance 2!

Note

If desired, multiple Router instances can each run into their own Process using gipc. This is what wishbone.bootstrap.Dispatch does.

Wishbone comes with the default wishbone.router.Default router implementation.

class wishbone.router.Default(config=None, size=100, frequency=1, identification='wishbone', graph=False, graph_include_sys=False)[source]

The default Wishbone router.

A Wishbone router is responsible for shoveling the messages from one module to the other.

Parameters:
  • config (obj) – The router setup configuration.
  • size (int) – The size of all queues.
  • frequency (int)(1) – The frequency at which metrics are produced.
  • identification (wishbone) – A string identifying this instance in logging.
block()[source]

Blocks until stop() is called and the shutdown process ended.

connectQueue(source, destination)[source]

Connects one queue to the other.

For convenience, the syntax of the queues is <modulename>.<queuename> For example:

stdout.inbox
Parameters:
  • source (str) – The source queue in <module.queue_name> syntax
  • destination (str) – The destination queue in <module.queue_name> syntax
getChildren(module)[source]

Returns all the connected child modules

Parameters:module (str) – The name of the module.
Returns:A list of module names.
Return type:list
registerModule(module, actor_config, arguments={})[source]

Initializes the wishbone module module.

Parameters:
  • module (Actor) – A Wishbone module object (not initialized)
  • actor_config (ActorConfig) – The module’s actor configuration
  • arguments (dict) – The parameters to initialize the module.
start()[source]

Starts all registered modules.

stop()[source]

Stops all running modules.