[rabbitmq-discuss] Catching channel disconnect
Valentino Volonghi
dialtone at gmail.com
Wed Oct 15 01:41:19 BST 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Oct 14, 2008, at 4:31 PM, Valentino Volonghi wrote:
> Do you think this makes sense?
It does, it's in fact very simple:
http://github.com/dialtone/shovel/tree/master/src/shovel.erl#L55
connect(User, Password, To) ->
connect(User, Password, To, 1000).
connect(User, Password, To, Backoff) ->
try
Connection = lib_amqp:start_connection(User, Password, To),
Channel = lib_amqp:start_channel(Connection),
{Connection, Channel}
catch
error:{badmatch,{error,econnrefused}} ->
% so the remote is not reachable right now... let's backoff
timer:sleep(Backoff),
NewBackoff = lists:min([round(Backoff*?
BACKOFF_MULTIPLIER), ?BACKOFF_MAX]),
connect(User, Password, To, NewBackoff)
end.
does the trick.
One thing I'm wondering though... Is tail recursion preserved when the
call or the
return value is inside a try..catch or a case ... of ?
I'll patiently wait for the other patch to land tip :)
- --
Valentino Volonghi aka Dialtone
Now running MacOS X 10.5
Home Page: http://www.twisted.it
http://www.adroll.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iEYEARECAAYFAkj1PC8ACgkQ9Llz28widGWqRgCdEivGBHrIsdH+lfWPXHH6wY2o
Qn0An2GRkqiNQE6I6uZIN/sH4v8iCV78
=+Qfp
-----END PGP SIGNATURE-----
More information about the rabbitmq-discuss
mailing list