Message

In order to effectively communicate between different parts of the application, all of the components must know what to expect when they get information. To enable this, messages should be created with the Message class.

This provides a consistent layout for handling messsages throughout the application. It is set up to be minimal and extendable. There are also various helper functions to automatically fill in some of these fields in common scenarios.

sender and receiver are a list of strings, which becomes useful when complex message routing is required.

command is simply required to ensure there is a straightforward way to identify different message types when handling messages.

package actually carries the data and may be of any type. From experience, dictionaries work well. Adding labels to the data does not add much overhead, but does make the message much easier to parse, allowing for changes in input order, new fields etc.

class pysimpleapp.message.Message(sender: List[str], receiver: List[str], command: str, package: any)[source]

Generic message class which will be used to move information around the system

__init__(sender: List[str], receiver: List[str], command: str, package: any)[source]

Create the message with data about where the message came from, where it is going, what it should do and any supplementary information. The package can be of any type, dictionaries tend to be useful for decoding on the other end.

Parameters:
  • sender – Address of the object which sent the message
  • receiver – Address of the intended recipient of the message
  • command – Headline of the message to allow simple handling
  • package – Data transferred as part of the message