[rabbitmq-discuss] Fwd: Point-to-point messaging with AMQP (was Re: rabbitmq-server failing to start?!)

Tony Garnock-Jones tonyg at lshift.net
Thu Feb 25 04:51:35 GMT 2010


Aha. OK.

So for Java, it'd be:

  Channel ch;
  String myWellKnownPublicName = ...;
  ...
  ch.exchangeDeclare("chat", "direct");
  String privateQueueName = ch.queueDeclare().getQueue();
  ch.queueBind(privateQueueName, "chat", myWellKnownPublicName);
  ...
  // To send a message to someone else:
  ch.basicPublish("chat", otherPartysPublicName, ...);
  ...
  // To retrieve messages for me, one at a time, without needing
  // to ack them (that's the 'true' part):
  GetResponse deliveryOrNull = ch.basicGet(privateQueueName, true);
  ...
  // To retrieve them as they arrive via push, again without
  // needing to ack:
  QueueingConsumer consumer = new QueueingConsumer(ch);
  ch.basicConsume(privateQueueName, true, consumer);
  while (true) {
    QueueingConsumer.Delivery delivery = consumer.nextDelivery();
    ...
  }

That's the complex form. For the simple form, everything's the same,
except you replace "chat" with "", omit the queueBind, replace all uses
of privateQueueName with myWellKnownPublicName and declare the queue
like this instead:

  ch.queueDeclare(myWellKnownPublicName,
                  false, false, false, true, null);

Cheers,
  Tony


Meredith Gregory wrote:
> Dear Tony,
> 
> Thanks for the response! Unfortunately, i'm such a RabbitMQ noob that
> terms like "bound to a separate exchange" don't mean anything to me in
> terms of lines of code, */yet/*. That's why i was hoping for a code
> sample ;-).
> 
> Best wishes,
> 
> --greg
> 
> ---------- Forwarded message ----------
> From: *Tony Garnock-Jones* <tonyg at lshift.net <mailto:tonyg at lshift.net>>
> Date: Tue, Feb 23, 2010 at 7:01 PM
> Subject: Point-to-point messaging with AMQP (was Re: rabbitmq-server
> failing to start?!)
> To: Meredith Gregory <lgreg.meredith at gmail.com
> <mailto:lgreg.meredith at gmail.com>>
> Cc: legitimategrievance at rabbitmq.com
> <mailto:legitimategrievance at rabbitmq.com>
> 
> 
> Meredith Gregory wrote:
>> That was the ticket. i figured it out last night after some poking
>> around. BTW, do you have code samples for the a simple two-way
>> conversation? I.e., setting up a channel from A -> B and another from B
>> -> A? i'm currently working with the Scala/Lift wrapper around what i
>> believe to be the Java client.
> 
> At its simplest, this can be
> 
>  - one queue with a well-known name per party
>  - messages sent to exchange "", routing_key = queue_name
> 
> For more flexibility (and compositionality! ;-) ) choose to use queues
> without well-known names, that are bound to a separate exchange
> 
>  - one queue with a secret name per party
>  - the party binds it to a direct exchange called "chat" or similar
>   with routing_key/binding_key equal to the name it wishes to be
>   known by
>  - messages sent to exchange "chat", routing_key = public name
> 
> Fancy posting these questions to rabbitmq-discuss at all? We're always
> looking to build up the archive for later mining for FAQs :-)
> 
> Tony
> 
> 
> 
> 
> -- 
> L.G. Meredith
> Managing Partner
> Biosimilarity LLC
> 1219 NW 83rd St
> Seattle, WA 98117
> 
> +1 206.650.3740
> 
> http://biosimilarity.blogspot.com
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss




More information about the rabbitmq-discuss mailing list