[rabbitmq-discuss] Temp Queues

Simon MacMullen simon at rabbitmq.com
Mon Oct 24 10:51:23 BST 2011


On 23/10/11 19:31, Gil Strauss wrote:
> On publisher:
> 1.
>      channel.exchangeDeclare(exchangeName, "direct")
>
>      val queueName = channel.queueDeclare().getQueue()
>
>      channel.queueBind(queueName, exchangeName, routingKey)

The zero-args version of queueDeclare() creates a server-named exclusive 
queue - this is one that is owned by the connection and will be deleted 
when it is closed.

Here you are declaring such an exclusive queue and then binding it in 
your publisher - if you are only going to publish then you don't need to 
do this.

> 2.
>   Publish message
>
> 3.
> On subscriber:
>      channel.exchangeDeclare(exchangeName, "direct")
>
>      val queueName = channel.queueDeclare().getQueue()
>
>      channel.queueBind(queueName, exchangeName, routingKey)
>
> 4.
> Result: Subscriber is not getting the message
>
> On the other hand, if I do 3 and only then 1 and 2: the subscriber is
> getting the message.
>
> So the questions are:
> a. Am I doing something wrong
> b. How can I ensure that the subscriber gets the message even if it
> was published before it subscribed to it?

The queue must exist before the message is published to it. You'll want 
to create queues which are non-exclusive and probably durable, and 
probably have your subscribers create names for them so they always 
connect to the same one (alternately have each subscriber declare a 
server-named queue the first time it starts up, then stash the name 
somewhere so it can connect again later).

Cheers, Simon

-- 
Simon MacMullen
RabbitMQ, VMware


More information about the rabbitmq-discuss mailing list