<div dir="ltr"><span style="font-family:arial,sans-serif;font-size:13px">I'd suggest subscribing to the queue with a 1-message buffer using the rabbitmq </span><span style="font-family:arial,sans-serif;font-size:13px">erlang client. I haven't had time to look into how to properly close the channel if your gen server crashes but I think a good enough approach is to link your gen_server to the connection pid and the channel pid - if anything crashes the gen_server can reconnect when it gets restarted by its supervisor. no polling for messages, you deal with them as they come in.</span><div>
<div style="font-family:arial,sans-serif;font-size:13px"><br></div><div style="font-family:arial,sans-serif;font-size:13px">So you your application top supervisor can supervise one worker - your gen_server. Simple as that. There are very few situations leading to the Erlang VM crashing, especially with such a simple system. One thing to watch out for is running out of memory. I think a common way of getting into that situation is having messages building up in the process message queue, e.g. if you receive rabbitMQ messages without requiring an ack before getting the next message, and if your gen_server can't keep up. It would really take many many messages for this to get out of hand, but do some napkin maths and be aware of it. <br>
<div><br></div><div>More about rabbitmq connection cleanup that I havent had time to look into properly... <a href="http://grokbase.com/t/rabbitmq/rabbitmq-discuss/116e7des0q/linking-to-a-channel-process-erlang-client" target="_blank">http://grokbase.com/t/rabbitmq/rabbitmq-discuss/116e7des0q/linking-to-a-channel-process-erlang-client</a></div>
</div><div style="font-family:arial,sans-serif;font-size:13px">RabbitMQ erlang client including subscribing to a queue with one message buffered <a href="http://www.rabbitmq.com/erlang-client-user-guide.html" target="_blank">http://www.rabbitmq.com/erlang-client-user-guide.html</a></div>
</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On 29 December 2012 08:35, hyperboreean <span dir="ltr"><<a href="mailto:hyperboreean@nerdshack.com" target="_blank">hyperboreean@nerdshack.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi guys,<br>
<br>
I'm just trying to bring Erlang into my company - it's a hard road, but<br>
we might eventually use it for at least some of our projects. I want to<br>
get started by changing a small piece of code that reads an AMQP queue<br>
and appends the contents of each message to a file. To be more specific,<br>
there are multiple producers for that queue (which produce error<br>
messages, if any) and there's this consumer which gets the error<br>
messages from the queue and updates a file with them. Now, this piece of<br>
software has always been problematic for us, for one reason or another -<br>
it's not reliable and when it fails it might bring the AMQP broker to<br>
its knees because of the number of messages that are not consumed.<br>
<br>
I'd like to change this code with some Erlang code - maybe with a<br>
supervision tree so that if/when the server fails, it gets automatically<br>
restarted. I was thinking of trying a gen_server, but then I figured out<br>
that there's no client of the server, the code just has to constantly<br>
pull data out of that queue.<br>
<br>
Any good hints on how to get started on this ? What's the OTP way of<br>
doing this kind of things?<br>
<br>
Thank you!<br>
<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br></div>