Hi Adam,<div><br></div><div>If I understood correctly your question, there are two points there:</div><div>1. how you can replicate a message;</div><div>2. how you can be sure that the message is received.</div><div><br></div>
<div>If that is the case, here are few simple answers (hopefully, more skilled Erlang users will come with better ideas/solutions):</div><div><br></div><div>1. Take a look at gproc or any equivalent implementation.</div><div>
<br></div><div>2. That depends on how the message is sent, but the general solution is to have a reply from the receiver. Here are two simple solutions for doing that:</div><div><br></div><div>a) Message sent via threads messaging (Pid ! MyMessage):</div>
<div>-> sender: ReceiverPid ! {self(), MyMessage}</div><div>-> receiver listener (basics only):</div><div>receive</div><div> Message -> {SenderPid, SenderMessage} = Message, SenderPid ! received</div><div> ...</div>
<div>end</div><div>or you can add SenderPid in the group of receivers.</div><div><br></div><div>b) Message sent via TCP connection (for the receiver only; the sender should have also a listener to be able to receive the answer):</div>
<div>listen_socket(Socket) -></div><div><div> case gen_tcp:recv(Socket, 0) of</div><div> {ok,Data} -></div><div> gen_tcp:send(Socket,<<"received">>),</div><div> listen_socket(Socket);</div>
<div> ...</div><div> end.</div></div><div><br></div><div>These are only few basic options. Of course, there are many other options (e.g., monitoring your receiver). I resume my answer to a simple one. Take care of the length of the queue (if you need a personalized queue, I suggest gen_fsm).</div>
<div><br></div><div>I hope this answer helps and if I misunderstood your problem, I kindly ask you to ignore my answer.</div><div><br></div><div>CGS</div><div><br></div><div><br></div><div><br><br><div class="gmail_quote">
On Fri, Jul 27, 2012 at 12:47 PM, Adam Warski <span dir="ltr"><<a href="mailto:adam@warski.org" target="_blank">adam@warski.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I've been looking at the Erlang ecosystem, and coming from a Java world, I am wondering what is the "Erlang way" to implement the following.<br>
<br>
The use case is very simple: I want to receive requests from users, and later process them asynchronously. However I want to be sure that if a request is received, it will be safe from single-node crashes, in other words, I want requests to be replicated across my cluster.<br>
<br>
In Java I would implement it using a replicated message queue. However RabbitMQ doesn't have replicated queues, only the meta-data is clustered (as far as I know). Mnesia has replication, but then it is a database, not a queue (although you could probably implement a mq ontop od that, but I didn't see anybody doing that).<br>
<br>
So how would you implememt this in Erlang? :)<br>
<br>
Regards,<br>
Adam Warski<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>