[rabbitmq-discuss] RabbitMQ Synchronous Client Example?

558 views
Skip to first unread message

Lynton Grice

unread,
Jul 18, 2009, 10:58:17 AM7/18/09
to rabbitmq...@lists.rabbitmq.com

Hi guys,

 

Quick one.....I have the following scenario:

 

Client sends message -> Mochiweb HTTP Server -> AMQP Erlang client -> RabbitMQ -> PYTHON consumer

 

Obviously the scenario suits ASYNCHRONOUS processing very well.......but now I want to handle SYNCHRONOUS as well....?

 

So what I would like is a SYNCHRONOUS scenario whereby the message goes from the client -> Mochiweb HTTP server -> then to the AMQP Erlang client, this then sends the message to RabbitMQ and blocks for a RESPONSE (waits for return message).....then the Python consumer picks up the message....processes it and sends the response to a “RESPONSE queue”.....the code then receives this response message (via some type of “correlationID”?) and sends it back to the calling client.

 

So basically how are synchronous scenarios handles in RabbitMQ? Does anyone have any example code in Erlang (or other) that shows how to process a message with ID “123” in RabbitMQ and put the result of message “123” into some other response queue..

 

Well I suppose when I speak of queues above maybe it should be “exchange”....maybe with a “routing_key”? The “routing_key” could be an internal “correlationID” of sorts?

 

So essentially the process will seem SYNCHRONOUS from that calling client but will be ASYNCHRONOUS in the “internals”...

 

Any ideas?

 

Thanks for the help ;-)

 

Lynton

Alexis Richardson

unread,
Jul 18, 2009, 2:47:32 PM7/18/09
to Lynton Grice, rabbitmq...@lists.rabbitmq.com
Lynton

There should be some examples of the RPC pattern in the source and
docs. At least for Java and .NET. You could also look at some of the
python and ruby synchronous clients. None of them use HTTP though.
They all use AMQP (iirc).

alexis

> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq...@lists.rabbitmq.com
> http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
>
>

_______________________________________________
rabbitmq-discuss mailing list
rabbitmq...@lists.rabbitmq.com
http://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss

Lynton Grice

unread,
Jul 19, 2009, 3:59:06 AM7/19/09
to Alexis Richardson, rabbitmq...@lists.rabbitmq.com
Hi Alexis,

Ideally I would want an AMQP client in Erlang code for the RPC pattern....I
will check it out, thanks for the help ;-)

Lynton

Ben Hood

unread,
Jul 19, 2009, 9:54:02 AM7/19/09
to Lynton Grice, rabbitmq
Lynton,

On Sun, Jul 19, 2009 at 8:59 AM, Lynton
Grice<lynton...@logosworld.com> wrote:

> Ideally I would want an AMQP client in Erlang code for the RPC pattern....I
> will check it out, thanks for the help ;-)

Not really sure if I understand you correctly but there is an RPC over
AMQP pattern in the Erlang client.

Check out the test case for it to see it's usage (the test is called
rpc_test/1 in the test_util module).

HTH,

Ben

Lynton Grice

unread,
Jul 19, 2009, 10:27:22 AM7/19/09
to Ben Hood, rabbitmq
Hi Ben,

Yup, I ran that earlier and it worked fine....thanks....

Can you explain to me how it would work if I had a PYTHON consumer (or
other) that would take the message off the queue....process it and send it
back? What do I send it back to? I assume it would all be on
"correlationid".....

I can see the TEST code below:

rpc_test(Connection) ->
Q = uuid(),
Fun = fun(X) -> X + 1 end,
RPCHandler = fun(X) -> term_to_binary(Fun(binary_to_term(X))) end,
Server = amqp_rpc_server:start(Connection, Q, RPCHandler),
Client = amqp_rpc_client:start(Connection, Q),
Input = 1,
Reply = amqp_rpc_client:call(Client, term_to_binary(Input)),
Expected = Fun(Input),
DecodedReply = binary_to_term(Reply),
?assertMatch(Expected, DecodedReply),
amqp_rpc_client:stop(Client),
amqp_rpc_server:stop(Server),
ok.

So as I mentioned above I want to send the message to a Python consumer, let
it process the message and send the response back....

Any ideas? Or a rough sketch on how that would work?

Thanks for the help, I really appreciate it ;-)

Lynton


-----Original Message-----
From: Ben Hood [mailto:0x6e...@gmail.com]
Sent: 19 July 2009 03:54 PM
To: Lynton Grice
Cc: rabbitmq
Subject: Re: [rabbitmq-discuss] RabbitMQ Synchronous Client Example?

Ben Hood

unread,
Jul 19, 2009, 4:29:09 PM7/19/09
to Lynton Grice, rabbitmq
Lynton,

On Sun, Jul 19, 2009 at 3:27 PM, Lynton
Grice<lynton...@logosworld.com> wrote:
> Can you explain to me how it would work if I had a PYTHON consumer (or
> other) that would take the message off the queue....process it and send it
> back? What do I send it back to?  I assume it would all be on
> "correlationid".....

..


> So as I mentioned above I want to send the message to a Python consumer, let
> it process the message and send the response back....

The client sets both the name of it's private queue in the reply-to
field and and creates a unique correlation id for each RPC. So all the
"server" has to do when responding is to a) set the routing key of the
message to the value of the reply-to field it received on the inbound
message and b) copy the correlation id from the inbound message to the
resulting outbound message. There are examples of how to do this in
the Erlang, Java and .NET clients - just look for modules/classes
called RpcServer.

Reply all
Reply to author
Forward
0 new messages