RabbitMQ is perfect for this situation. You have several options to do what you want. I suggest reading the documentation to better understand. I suggest you use a topic or direct exchange. The topic is more flexible. This happens as follows.
The manufacturer code connects to Broker RabbitMQ and creates Exchange with a specific name.
Producer publishes for sharing. Each published message will be published using a routing key.
The consumer connects to the RabbitMQ broker.
Consumer creates a queue
The consumer binds the queue to the exchange, the same exchange defined in the producer. Binding also includes routing keys for each message required for that particular consumer.
Suppose you posted a journal post. The routing key can be something like "log.info", "log.warn", "log.error". Each message published by the manufacturer will have a corresponding routing key. Then you will have a consumer who sends and sends all error messages by email, and the other writes all error messages to a file. Thus, the mail client will determine the binding of its queue to the exchange using the routing key "log.error". Thus, although the exchange receives all messages, the queue defined for the mail sender will only contain error messages. Filelogger will detect a new separate queue associated with the same exchange and configure a different routing key. You can make three separate bindings for three different routing keys or simply use the "log. *" Template to request all messages from the exchange, starting with the log.
This is a simple example that shows how you can achieve what you want.
look here for code examples, in particular, tutorial number 5.
robthewolf
source share