[rabbitmq-discuss] Creating exchanges on demand.

Matthias Radestock matthias at lshift.net
Mon Jun 8 20:44:44 BST 2009


Camilo Lopez wrote:
> Appart from the rpc facilities  in the clients is there a good pattern
> to follow here?

The rpc wrappers actually implement a very straightforward pattern. Take 
a look at the code for Rpc{Client,Server}.java.

The pattern is this:

The server creates a queue for requests and binds that queue to an 
exchange. In the simplest case, the queue is named after the rpc service 
and the standard binding to AMQP's default exchange suffices - that's 
what I am assuming below. The server subscribes a consumer to that queue.

Each client creates a (usually anonymous and exclusive) queue for 
replies and subscribes a consumer (usually with noAck=true) to that queue.

RPCs then happen as follows:

1. The client publishes the request as a message to the default exchange 
with a routing key identifying the rpc service, the request as the 
payload, and two message properties (see 
a correlationId that identifies the requests (this is only necessary if 
the client wants to pipeline requests), and a replyTo property set to 
its reply queue name.

2. The server's consumer receives the request, performs the necessary 
invocations, and then publishes the reply to the default exchange with 
the routing key set to the value of the replyTo property of the request, 
and the correlationId message property set to the correlationId property 
of the request. The client then basic.ack's the request.

3. The client's consumer receives the reply, and correlates it with the 
request using the correlationId.



More information about the rabbitmq-discuss mailing list