0

I am using java based application to publish & consume RabbitMq services for message exchanges. So architecture is pretty simple Java application which produces & consume messages from RMQ nothing too much complex. Case or rather problem statement is I am publishing messages to RMQ in a huge load lets say 10 messages per second. with sample below format in JSON data

{"id":"a:1143-fdf45-34fd4-23d23f", "class":"AClass"}
{"id":"a:2243-fdf45-34fd4-23d23f", "class":"BClass"}
{"id":"a:3343-fdf45-34fd4-23d23f", "class":"AClass"}
{"id":"a:4443-fdf45-34fd4-23d23f", "class":"CClass"}

and for some reason the messages took considerable longer time to process, and by that time next messages are already published. in this case, I am wanted to reshuffle or reorder the messages which are placed in RMQ or already published to RMQ (group by id, class). does RMQ allows me to inject such type of stratergy ? If not then is there work around to reorder before publishing the messages to RMQ ? since in my Microservice, controller receive the POST request for single object and it will do channel.basicPublish as of now this is straight forward flow. main objective is to not to de-duplicate, but rather arrange them in a custom sequence.

4
  • 2
    RabbitMQ does not support message reordering once messages are in the queue. Queues in RabbitMQ are FIFO (first-in-first-out) by design, and you cannot reshuffle or reprioritize messages already enqueued. Custom ordering must be handled either before publishing or at consumption time. Commented Jun 5 at 9:23
  • Do you have fixed possible values for grouping elements (id/class)? If yes, you could use them for priority, which achieves some sort of grouping (e.g: AClass may have priority 1, BClass may have priority 2, etc) Commented Jun 5 at 10:21
  • values are obviously dynamic one. there are several values for type class and so is for id as well. but I would like to know what is your theory behind priority1 & priority2 ? Commented Jun 5 at 12:52
  • If you have a fixed number of possible classes (let's say a total of 100 possible classes), you can setup priority of each. Afterwards, whenever data is pushed to the queue, it will be stored automatically grouped by priority and will be fetched by clients in the order of priority. So if someone pushes 3 elements in order [AClass, BClass, AClass], clients will first fetch 2x AClass and afterwards the BClass (assuming AClass has higher priority). So grouping by class (or any attribute for which you know possible options when configuring rabbit queue) is sort of possible. Commented Jun 6 at 7:18

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.