Braviz Inter Application Communication¶
Braviz applications can share data because all of them work on the same database. They may also send messages and listen to them. With this mechanism it is possible to coordinate several applications and therefore enrich the analysis environment.
Messages are transmitted over TCP using the 0MQ protocol. The current configuration has a message broker which retransmits messages to all running applications. This broker usually runs on the menu application.
On one side, the broker acts as a publisher, and all applications subscribe to receive messages from it. On the other side it acts as a sink receiving messages from all applications. It has two addresses, one for publishing messages, to which applications should subscribe, and a listening one, to which applications should send messages. These are the only two well known addresses in the network.
The broker is implemented in MessageServer
,
and the client side is implement in MessageClient
.
Both of these classes generate PyQt-Signals when they receive a message, and therefore are easy
to connect to the rest of your application.
The protocol of the messages themselves is described in Braviz Messages.
Message Broker¶
-
class
MessageServer
(local_only=True)[source]¶ Acts as a message broker, listens for messages in one port, and broadcasts them in another port
Also generates the message_received signal when it receives a message with the message string. The broadcast and receive addresses are binded to ephimeral ports, use the respective properties to query them.
Parameters: local_only (bool) – If True
the server will only accept connections from localhost-
broadcast_address
¶ The address in which this server broadcasts messages
-
pause
¶ Pause the server, received messages will be ignored.
-
receive_address
¶ The address in which the server listens for messages
-
Message Client¶
-
class
MessageClient
(server_broadcast=None, server_receive=None)[source]¶ A client that connects to
MessageServer
When it receives a message it emits the message_received signal with the message string.
Parameters: -
send_message
(msg)[source]¶ Send a message
Parameters: msg (dict) – Message to send to the server, will be encoded as JSON
-
server_broadcast
¶ The server broadcast address
-
server_receive
¶ The server receive address
-
-
class
PassiveMessageClient
(server_broadcast=None, server_receive=None)[source]¶ A client that connects to
MessageServer
When it receives a message it keeps it in memory. The last message may be polled using the method
get_last_message()
Parameters: -
get_last_message
()[source]¶ Get the last received message and a consecutive number
Returns: number, message_text
; where the number will increase each time a new message arrives
-
server_broadcast
¶ The server broadcast address
-
server_receive
¶ The server receive address
-
-
class
GenericMessageClient
(handler, server_broadcast=None, server_receive=None)[source]¶ A client that connects to
MessageServer
When it receives a message it calls
handle_new_message
on the handler, optionally, if the handler hast thehandle_json_message
, it will be called with the raw json message as argument.Parameters: -
send_json_message
(net_msg)[source]¶ Send a message already encoded as json
Warning
This message will also bounce to the handler, be careful with loops
Parameters: net_msg (str) – Message to send to the server
-
send_message
(msg)[source]¶ Send a message
Warning
This message will also bounce to the handler, be careful with loops
Parameters: msg (dict) – Message to send to the server
-
server_broadcast
¶ The server broadcast address
-
server_receive
¶ The server receive address
-
Tornado Clients¶
This classes are meant to be used inside in tornado web servers to send and receive messages to the rest of the system
-
class
MessageHandler
(application, request, **kwargs)[source]¶ Allow querying for messages and sending messages through http
- GET requests will receive json data
{"count":<n>,"message",<s>}
where count is a number - that increases with any new message, and message is the text of the last message.
POST requests allow to send messages. It is required to have a
"message"
parameter in the request body- GET requests will receive json data
-
class
LongPollMessageHandler
(application, request, **kwargs)[source]¶ Allow querying for messages and sending messages through http
GET requests will receive json data
{"message",<s>}
. This request will not return until a new message is available. (Long poll)POST requests allow to send messages. It is required to have a
"message"
parameter in the request body