[rabbitmq-discuss] register_confirm_handler using the Erlang client

eimu gray eimu.gray at gmail.com
Fri Sep 27 16:39:11 BST 2013


Hi,
   I'm a Rabbit newbie, I use register_confirm_handler/2 to register a 
handler which deals with confirm-related messages, but it didn't receive 
any acks or nacks.
Then I  add  code1 after amqp_channel:cast(Channel, Publish, Msg), It can 
work. so why? I want to publish msg In the asynchronous mode.  Thanks!!!!

code1:
receive
   Any -> void
end


my code:

deal_confirm(Pid) ->
loop(Pid, S).

loop(Pid, S) ->
receive
#'basic.ack'{delivery_tag = Tag}  ->
io:format("********"),
loop(Pid, S);
#'basic.nack'{delivery_tag = Tag} ->
io:format("XXXXXXXXXXXX");
_ ->
io:format("??????????~n")
end,
loop(Pid, S).  

send_message(_, _, _, 100) ->
void;
send_message(Channel, Publish, Msg, A) ->
amqp_channel:cast(Channel, Publish, Msg),
send_message(Channel, Publish, Msg, A+1).

start() ->
{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
{ok, Channel}    = amqp_connection:open_channel(Connection),
#'confirm.select_ok'{} = amqp_channel:call(Channel, #'confirm.select'{}), 
S = self(),
amqp_channel:register_confirm_handler(Channel, spawn(fun() -> 
deal_confirm(S) end)),
Payload = <<"helloworld">>,
Publish = #'basic.publish'{exchange = <<"infoexchange">>, routing_key = 
<<"info">>},
Props   = #'P_basic'{delivery_mode = 2},
Msg     = #amqp_msg{props = Props, payload = Payload},
send_message(Channel, Publish, Msg, 0),
amqp_channel:close(Channel),
amqp_connection:close(Connection).

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20130927/389deadf/attachment.htm>


More information about the rabbitmq-discuss mailing list