One thing to note, that connection management is super important to ensure your application behaves well if their connection drops or service restarts. This is something that you have to do on your own.
Another really good option for propagating events inside your system is RabbitMQ. RabbitMQ is an open-source message broker, so it takes sending messages around between different services, producers, and consumers. It has support for a lot of different protocols, but the main one that is usually used is MQP. And this allows for reliable, flexible, scalable message routing.
Some key terms to know about RabbitMQ, if you start looking into it or somebody's talking to you about its connection, is a TCP connection using the MTP protocol. A channel, which is a multiplex virtual connection inside of MQP. This is how you do different actions and you can have multiplex communication across the single TCP socket. Queues, which are basic components for storing and managing specific messages, and exchanges, which are like a routing agent that allows you to put messages to one or more queues.
There's a couple of well-known patterns in RabbitMQ. The first would be publish and subscribe. This fits really well into admin architecture. We can have a publisher on the left-hand side that publishes into an exchange, which is just a messaging agent that allows you to route messages to different people. And consumers are able to bind their own queues to this exchange. So each consumer that we see on the right-hand side, consumer A, consumer B, and consumer C, can actually consume updates from this publisher at their own pace and deal with it at their own way. So this is really, really powerful inside of RabbitMQ. It's a propagate change.
Another thing that you might look at is remote procedure calls, where service A needs to send an instruction to service B. In this case, service B instantiates a command queue. Service A interacts with this command queue by sending a correlation ID for the message and a reply queue, which is a queue that service A is to try to. So when service A sends the command to service B or this command queue, service B processes it and sends the response with the correlation ID on with this provided reply queue back to service A.
When we look at combining these things inside of your microservices, you will see a lot of things like this, where you have exchanges going in either direction. You have this exchange that's being exposed by service A, where client A is subscribed to it, and you also have command queues where client A can say, edit, get me all of the data for the past 24 hours. It's not enough that I just get the real-time updates.
Another really good broker, which is more lightweight, would be MQTT. This basically is just a messaging protocol, so don't confuse it with brokers themselves. This is commonly used in IoT applications, where you have like low bandwidth or unreliable networks, or maybe there's power saving with your batteries, you don't want to have a consistent connection. And this operates on a basic publish-subscribe model, which allows you to decouple your producers and consumers. Some of the things you'll hear about when discussing MQTT are topics, which is just a hierarchical string that acts as a routing mechanism.
Comments