Package: microservicebus-py
microservicebus-pyGeneralTo avoid blocking the thread, avoid using theprint(...)function. Instead use the built-inprintffunction inherited from base_service:self.printf("Hello world")You can also useself.Debugif you want the logging transmitted to msb.com.BaseService (base_service)All services inherit fromBaseServiceeither directly or throughCustomService. Inheriting fromBaseServiceprovides a number of functions such asself.Debug(text)andself.SubmitMessage(message). Such methods are predefined to target specific destinations and functions. A service can also callself.SubmitAction(destination, action, message)when more flexibility is needed.For instance, if you had a custom service calledemailhandlerwhich would send emails through theProcessfunction you could use the following code:message={'to':'foo@bar.com','subject':'Hello','body':'...from foo'}awaitself.SubmitAction("emailhandler","Process",message)Note that the action is set to "Process". All services inheriting fromBaseServicehas aStart.StopandProccessfunction. However, you could have created aSendEmailfunction and set the action to "SendEmail".If, on the other hand, you'd like to send a message to the IoT Hub you would set thedestinationto "com". However, there is already a simplified function calledSubmitMessagepredefined with bothdestinationandaction:message={'ts':'2021-01-01 01:01:01','temperature':22}awaitself.SubmitMessage(message)Similarly there is a predefined function to logging:awaitself.Debug("Hello from Python")Internal servicesInternal services are used as any other service but are never stopped.Orchestrator (orchestrator_service)TheOrchestratoris responsible for starting up services and correlate messages between then. All messages on the queue are of type QueueMessage (baseservice) and contains information such as thedestinationandaction. When the Orchestrator receives a message on the queue, it will resolve the destination and call the function (_action).microServiceBusHandler (msb_handler)As the name implies themicroServiceBusHandleris responsible for all communication with microServiceBus.com. When staring up the service will sign in to msb.com and set up channels for different commands in msb. After successful sign-in, the service will call the Orchestrator to start up the these services.Logger (logger_service)The Logger service outputs data to the terminal and forward debugging info tomicroServiceBusHandlerif enabledCustom servicesAll custom services inherit fromBaseServiceand must expose the following functions:StartTheStartfunction will be called when the when custom service is started. This is the where the services should start any kind of interval or work to produce readings.Readings can be submitted using theself.SubmitMessage(message)function which forwards the message to theProcessfunction of theComservice.StopTheStopfunction is called as the service is getting stopped and can be used for any cleanup.ProcessTheProcessmethod can optionally be used for transmitting messages between services using theself.SubmitAction(destination, action, message)E.gawaitself.SubmitAction('MyOtherService','Process',message)StateUpdateState updates received by theComservice are forwarded to all services and accessible through the StateUpdate function