<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Hello, Matthias!<br>
<br>
<br>
<br>
On 07/30/2012 11:52 AM, Matthias Radestock wrote:
<blockquote cite="mid:50165947.4070609@rabbitmq.com" type="cite">Anton,
<br>
<br>
On 29/07/12 21:59, anton prokofiev wrote:
<br>
<blockquote type="cite">On Sunday, 29 July 2012 21:21:06 UTC+2,
anton prokofiev wrote:
<br>
I tried to create a consumer in Erlang for RabbitMQ and get
into
<br>
big troubles.
<br>
Looks like examples that are available in RabbitMQ website
did not work.
<br>
</blockquote>
<br>
*Which* example didn't work?
<br>
</blockquote>
It seams to me that this one did not work:<br>
<pre class="sourcecode">Sub = #'basic.consume'{queue = Q},
#'basic.consume_ok'{consumer_tag = Tag} = amqp_channel:call(Channel, Sub) %% the caller is the subscriber
</pre>
<font face="Times New Roman, Times, serif">At </font>least I do not
managed to force it to work.<br>
In another one, <br>
<br>
<pre class="sourcecode">Sub = #'basic.consume'{queue = Q},
#'basic.consume_ok'{consumer_tag = Tag} = amqp_channel:subscribe(Channel, Sub, Consumer)
</pre>
It was not clear to me what should be used as a consumer, as final
example contains only case when we use *#'basic.get'* command.<br>
<br>
If I understood it correctly, I should pass a PID of the consumer
process, when I open channel:<br>
<tt>amqp_connection:open_channel(Connection,none,*{amqp_direct_consumer,[Pid]}*),
</tt><br>
<br>
Unfortunately I can not found this in the documentation, or may be
it was not clearly enough pointed out. :(<br>
<br>
I should say that I have not too much experience with erlang, and
just started to work with rabbitMQ.<br>
Another problem is that RabbitMQ broker I work with is out of my
control and documentation that I have really misleading.<br>
As a result I have to use try-and-error approach to develop my
application.<br>
<br>
<blockquote cite="mid:50165947.4070609@rabbitmq.com" type="cite">
<blockquote type="cite">Looks like I have found a correct
solution:
<br>
<br>
1. I have implemented simple gen_server, that just print all
messages to
<br>
the stdout.
<br>
<br>
2. And to like this:
<br>
{ok,Connection} = amqp_connection:start(ConnectionParams), %
open
<br>
connection with predefined params.
<br>
{ok,Pid} = test_srv:start_link(), % Start our own
consumer.
<br>
{ok,Channel} =
<br>
amqp_connection:open_channel(Connection,none,*{amqp_direct_consumer,[Pid]}*),
<br>
</blockquote>
<br>
The above creates a channel with a default consumer. More
typically you'd associate consumers with particular subscriptions,
as shown in
<a class="moz-txt-link-freetext" href="http://www.rabbitmq.com/erlang-client-user-guide.html#subscribing">http://www.rabbitmq.com/erlang-client-user-guide.html#subscribing</a>.
<br>
<br>
<blockquote type="cite">Would it be better to create my own
implementation of consume behavior,
<br>
or handle them thought the message_info as it is now?
<br>
Any recommendations?
<br>
</blockquote>
<br>
Implementing your own instance of the amqp_gen_consumer behaviour
is probably the more "correct" approach, but it's a bit more work
and if the behaviour of the amqp_direct_consumer fits in well with
the rest of your system design then just use that.
<br>
<br>
Regards,
<br>
<br>
Matthias.
<br>
</blockquote>
<br>
</body>
</html>