Home
Ratchet Library :: API Reference
API  ·  Manual

Module ratchet.bus

This module is designed as a convenience to make requests in the form of a message queue, with simple responses being returned to the sender. Two different forms exist, allowing sharing either between threads in the same ratchet context or sharing across a socket. This can be especially useful as an abstraction when two systems may be running separately or running side-by-side in the same process.

Functions

new_client (socket, request_to_bus, response_from_bus) Creates the client-side of a socket-based message bus.
new_local () Creates a new, local message bus.
new_server (socket, request_from_bus, response_to_bus) Creates the server-side of a socket-based message bus.
recv_request (self) Receives a request from the server-side of a message bus.
send_request (self, request) Sends a request from the client-side of a message bus.


Functions

new_client (socket, request_to_bus, response_from_bus)
Creates the client-side of a socket-based message bus. After sending a request, the client-side will need wait to receive a response.

Parameters

  • socket: a socket already connected to a server.
  • request_to_bus: an arbitrary function that converts a request object into a string.
  • response_from_bus: an arbitrary function that accepts a string and converts it into a response object.
new_local ()
Creates a new, local message bus. Waiting for a request in a thread will pause that thread until another sends a request, and waiting for a response will pause until one is sent. Requests are queued if a thread is not actively waiting for them. The same bus object, created by this function, is used for both the client- and server-sides of the message bus.

Return value:

a new local message bus, returned twice.
new_server (socket, request_from_bus, response_to_bus)
Creates the server-side of a socket-based message bus. Receiving a request will wait for a new client connection and a request on that connection. The response is then sent back over the connection to the client-side of the bus.

Parameters

  • socket: a socket already listening for new connections.
  • request_from_bus: an arbitrary function that accepts a string and converts it into a request object.
  • response_to_bus: an arbitrary function that converts a response object into a string.
recv_request (self)
Receives a request from the server-side of a message bus. This function can be used by a local message bus object created with new_local() or a server-side socket message bus object created with new_server().

Parameters

  • self: the server-side of a message bus.

Return value:

a ratchet.bus.transaction object on which to send the response, followed by the request object received.
send_request (self, request)
Sends a request from the client-side of a message bus. This function can be used by a local message bus object created with new_local() or a client-side message bus object created with new_client().

Parameters

  • self: the client-side of a message bus.
  • request: a request object to send.

Return value:

a ratchet.bus.transaction object on which to receive the response.