I recently crushed into a problem with开发者_JAVA百科 one of the popular libraries implementing AMQP client protocol. AMQP specification defines synchronous and asynchronous messages. The problem is that I sent two synchronous requests one by one without waiting for the the first to finish and RabbitMQ server responded in reversed order. The library expected the responses to come in the same order the requests were sent. Is this a bug in the library or my misusage ?
The question is: should the AMQP client take care on its own to serialize the synchronous calls?
Below are some references which I found related. The specification document [1] section 2.2.1 says the following:
To make method processing simple, we define distinct replies for each synchronous request. That is, no method is used as the reply for two different requests. This means that a peer, sending a synchronous request, can accept and process incoming methods until getting one of the valid synchronous replies. This differentiates AMQP from more traditional RPC protocols.
The misunderstanding here is whether the author meant that processing of incoming methods is limited to asynchronous calls (like basic_deliver) or does it also include responses to different synchronous calls.
[1] http://www.amqp.org/confluence/download/attachments/720900/amqp0-9-1.pdf?version=1&modificationDate=1227526523000
Your Amqp client library should enforce synchronous messages by waiting for the corresponding response message after sending an sync. message. One exception here is to use a 'no-wait' field and set the value to true, certain methods allow this, and in this case the client library should not wait for a response, as the no-wait flag effectively says "don't send me the response message".
BTW, which client library are you using?
精彩评论