Is Rabbit MQ and Python possible with Content Based Routing?
The AMQP standard and RabbitMQ claim to support content-based routing, but is there a library for Python that helps in specifying content-based binding?
I am currently using (py-amqplib) library routing only with subject-based simple pattern-mailing (#, *).
The answer is "yes", but there is more to it ... ...)
Routing based on the first material means what. Two possible meanings are some people say that it is based on the header part of the message, others say that it is based on the data part of a message.
If we take the first definition, then the lesser the assumptions we make are: the data comes into being, and it is sent through some software to the AMQP broker, we believe that this piece of software Provides sufficient information about the data so that the key-value (KV) pair can be added to the header of the message describing the content. Ideally, the sender is also the creator of the data, so there is as much information as there can be as much information as we want to assume that the data is an image, after which we can add KV pairs to the message headers:
width = 1024 height = 768 mode = bw Photographer = John Doe Now we can implement content-based routing by making a proper queue. Suppose we have a separate campaign to display on black and white images and color is different on the images, we can create two rows, one that is mode = bw and mode = Color . Then we have different clients who are listening on those lines. The broker routing, and there is nothing in our customer who should be aware of routing.
If we take another definition, then we go by different assumptions. We believe that the data comes into being, and it is sent to some AMQP broker by some software. But we believe that it is not demandable that the software should populate the header with KV pairs. Instead, we want to make routing decisions based on our own data .
There are two options in AMQP for this: You can decide to apply a new exchange for your particular data format, or you can delegate to the customer routing.
In RabbitMQ, direct (1-to-1), fanout (1-to-n), header (header-filtered 1-to-n) and subject (subject to filtered 1-to- N) exchanges, but you can implement yourself according to the AMQP standard. For this many will need to read the RabbitMQ document and implement the exchange in Erlang.
The second option is to create an AMQP client in Python that listens to a particular "Content Routing Queue". Whenever a message comes in the queue, your router-client raises it, whatever it is necessary to make routing decisions, and the message back to the broker in a suitable queue. So to apply the above scenario, your Python program will detect that an image is black-and-white or in color, and (again) it will send it in the "black and white" or "color" queue, where some The customer will take
So on your second question, there really is nothing that you do in your customer who does any content-based binding work. Either your customers work as described above, or you create yourself a new exchange type in which RabbitMQ itself is, then, in your customer setup code, you can define the exchange type as your new type Are there.
Answer this question for your questions!
Comments
Post a Comment