Hello. I am trying to write a queue on rabbitmq. On all the tutorials that I watched, everything works as follows:

  1. There is a code (the sender) that sends the message to the Rabbit queue and ends immediately.
  2. There is a code (recipient) that works by constantly listening to the queue in order to pick up a message from it. After HE receives a message from the queue, it is possible to give a message to the rabbit that he received it. And then rabbit will remove it from the queue. In this case, the recipient does not know whether the message was delivered or not (it was simply removed from the queue).

But this is not enough for me. I need the sender to know that the message has been delivered.

That is, I will try to give an example.

The sender queues two messages:

  1. "Hello"
  2. "until"

The recipient received the message and replies:

  1. "Hi ok"
  2. "not yet ok"

Tell me, can this be realized somehow?

  • Do you want to receive a response in synchronous mode? Or is it just meant time-out notification? If in synchronous (that is, sent and waiting for an answer) - then why do you need JMS? If in asynchronous, send the message to the recipient where you need it (be it a service, mail or something else). And yes, if the message is not received, then how do you understand about it?) - Chubatiy
  • In fact, you can only send AFTER you receive a message. If you have not received anything, then this may be as an option that the message is “lost” or it was not sent at all - Chubatiy
  • Weird question. You only need to know that the message is queued RabbitMQ. On the other side there may be a single listener / concierge, or several listeners (You understand that RabbitMQ is very good as a BALANCER of tasks between MULTIPLE listeners / task handlers, one is just a special case). How are you going to handle these situations? Re-read the phrase @Chybatiy "if the message is not received, how will you understand about it" and think about it. - AK
  • No, I would like to put messages in the queue for the recipient. And the recipient to receive and process the message put the answer in a kind of "reverse" queue, which would reach the sender. - fantastic
  • 1 message may not be received, then it will remain in the queue. 2 the message can be received (togdzha it will disappear from the queue), but processed with an error. Tom who sent the message you need to know about it. - fantastic

2 answers 2

You need to understand the ideology of the queues, how they work and in the first place - "acknowledgment of messages" (acknowledgment, ack) as described in this article .

When executing a task, send to another queue "task id = 123 completed" after successful execution of the task.

Plus optional:

  1. queue for error notifications

  2. periodically check "tasks that are stuck for more than X minutes."

And again, I can not fail to draw your attention to the fact that you have TWO message queues: one in RabbitMQ, the other in MSSQL.

Synthetic example. Suppose you have an archive of pages in the MSSQL database. And then you add a sign in which you set tasks for bots that download new articles. Download - added a new entry to the database.

You made a redundant structure. It was possible to manage the base in MSSQL and store the tasks ONLY in RabbitMQ. And keep a hundred subscribers, add and remove them to download faster. The handler took the task, processed it, saved it to the database, followed the next task. Took another, an sees - the article was updated five minutes ago, it is less than the specified interval of freshness - deleted from the queue.

It would be possible not to involve Rabbit MQ, to leave everything on the basis of MSSQL.

And you have two turns in fact. This sometimes happens, if you have MSSQL in one organization, and Rabbit MQ is a third-party service. Or different departments that use different technologies (some Linux, others Windows), it also happens. But since I do not know your features, I simply point out excessive duplication, it is probably not obvious to you.

  • I read this article, the receiver receives data from the queue, puts a confirmation, the data is removed from the queue. Transmitter how to find out about it? - fantastic
  • "From another queue". I added the answer, removed the extra copy-paste, since you read this article. - AK
  • And at the level of the Rabbit itself, you can’t do this? In order not to create two queues yourself? Something very similar is in the 6th case of using the rabbit habrahabr.ru/post/236221 rabbitmq.com/tutorials/tutorial-six-java.html - fantastic
  • @fantastic Yes, it is possible, but this method has not taken root in our company, so I have no such experience exactly - I speak purely theoretically. - AK

Here are two options for you:

  1. On the sender, raise the listener (recipient) who will listen to queue B. Ie you send to queue A, it is processed by recipient A, and after processing it is sent to queue B, which listens (processes) recipient B
  2. Enter in some message identifier. After processing, place this identifier in some kind of storage (DB for example) with the processing status. Thus, the sender can retrieve data from this repository by the identifier specified in the message
  • one
    lay down -> put it - AK