Review how to apply the topical filtering of ZeroMQ to implement basic notifications. Also take a look at the framing and encoding of news updates.
- [Instructor] As mentioned previously, subscribers must set topical subscriptions in order to receive messages. In fact, they can set multiple subscriptions. However, filtering is done using binary prefix matching. In other words, the leading bytes of the first frame of the message are matched against a given subscription. We'll make significant use of this feature in our chat application. So it's worth understanding it in detail. Let's imagine we have a publisher broadcasting where each message has one of five different topics. Now imagine our subscriber sets a subscription of a-n.
We can expect to receive messages with any of the five topics. However, if we instead set a subscription of a-n-t, we would only receive messages with three of the topics. Finally, consider two more examples. A-n-t-i and a-n-t-u. We can expect to receive only messages that begin with byte sequencing a-n-t-i-q-u-e. We'd like to extend our server to announce when a client arrives or leaves the chat. To do so, we'll add a popsocket to our server.
It will broadcast a message with two frames. This follows the very common pattern of using one message frame as the topic with a second frame for the actual content. In our client, we'll set up a sub socket to receive these updates. Note that we've used the first few bytes of the topic to describe our chat protocol. So we could, at a minimum, set a subscription for that information. However, we'll actually set a subscription which matches the full topic frame. This would give us a bit more flexibility in the future should we decide to receive additional information.
- Building a single-file application
- Two-way messaging
- Heartbeating to detect disconnects
- Broadcasting messages using publish/subscribe
- Combining one-way and two-way messaging channels
- Troubleshooting your app
- Designing and evolving protocols