Skip to content

Commit

Permalink
use two channels in erlang amqptest
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Jan 12, 2011
1 parent adba454 commit b449923
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions amqptest.erl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@

-include_lib("amqp_client/include/amqp_client.hrl").

-define(COUNT, 5000).
-define(COUNT, 20000).

main(_) ->
{ok, Connection} = amqp_connection:start(network,
#amqp_params{host = "localhost"}),
{ok, Channel} = amqp_connection:open_channel(Connection),
{ok, Channel2} = amqp_connection:open_channel(Connection),

#'exchange.declare_ok'{} = amqp_channel:call(Channel, #'exchange.declare'{
exchange = <<"test_direct">>,
Expand All @@ -25,6 +26,12 @@ main(_) ->
queue = <<"hello">>,
routing_key = <<"hello">>}),

amqp_channel:subscribe(Channel2, #'basic.consume'{queue = <<"hello">>,
no_ack = true}, self()),
receive
#'basic.consume_ok'{} -> ok
end,

io:format("Start~n"),
T0 = now(),

Expand All @@ -35,15 +42,11 @@ main(_) ->
#amqp_msg{payload = <<"Hello World!">>})
|| X <- lists:seq(0, ?COUNT-1)],

amqp_channel:subscribe(Channel, #'basic.consume'{queue = <<"hello">>,
no_ack = true}, self()),
receive
#'basic.consume_ok'{} -> ok
end,
loop(Channel, ?COUNT),
loop(Channel2, ?COUNT),
Td = timer:now_diff(now(), T0) / 1000000.0,
io:format("Done ~.3fsec ~.3f MPS~n", [Td, ?COUNT/Td]),
ok = amqp_channel:close(Channel),
ok = amqp_channel:close(Channel2),
ok = amqp_connection:close(Connection),
ok.

Expand Down

0 comments on commit b449923

Please sign in to comment.