Implementing publish/subscribe

Time has come for the last example of this book, once again using both AsyncIO and RxPY. This last example is an implementation of the publish/subscribe communication pattern on a TCP connection. Two applications will be implemented here: the publisher, implemented in a TCP server, and the subscriber, implemented in a TCP client.

The publisher emits either an observable of four numbers (1, 2, 3, 4), or an observable containing the "let's go" string, each time a remote observer subscribes to it. The observable being returned depends on a parameter provided by the subscriber. The publisher supports several clients connected at the same time, and routes the items to the corresponding client.

Both applications are implemented via Cyclotron. The boilerplate to set up the project is not detailed in this chapter, so that explanations of the code can focus on the multiplexing part. Also, the observable subscription is simplified, with the ack and nack parts being omitted. The complete code for this example is available in the GitHub repository of this book, in the rmux sub-folder.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.144.17.137