Whitespace.
This commit is contained in:
parent
a120745533
commit
6b0432f6ef
@ -5,22 +5,22 @@
|
||||
|
||||
main(Argv) ->
|
||||
{ok, Connection} = amqp_connection:start(network,
|
||||
#amqp_params{host = "localhost"}),
|
||||
#amqp_params{host = "localhost"}),
|
||||
{ok, Channel} = amqp_connection:open_channel(Connection),
|
||||
|
||||
amqp_channel:call(Channel, #'queue.declare'{queue = <<"task_queue">>,
|
||||
durable = true}),
|
||||
durable = true}),
|
||||
|
||||
Message = case Argv of
|
||||
[] -> <<"Hello World!">>;
|
||||
Msg -> list_to_binary(string:join(Msg, " "))
|
||||
end,
|
||||
[] -> <<"Hello World!">>;
|
||||
Msg -> list_to_binary(string:join(Msg, " "))
|
||||
end,
|
||||
amqp_channel:cast(Channel,
|
||||
#'basic.publish'{
|
||||
exchange = <<"">>,
|
||||
routing_key = <<"task_queue">>},
|
||||
#amqp_msg{props = #'P_basic'{delivery_mode = 2},
|
||||
payload = Message}),
|
||||
#'basic.publish'{
|
||||
exchange = <<"">>,
|
||||
routing_key = <<"task_queue">>},
|
||||
#amqp_msg{props = #'P_basic'{delivery_mode = 2},
|
||||
payload = Message}),
|
||||
io:format(" [x] Sent ~p\n", [Message]),
|
||||
ok = amqp_channel:close(Channel),
|
||||
ok = amqp_connection:close(Connection),
|
||||
|
11
erlang/receive.erl
Normal file → Executable file
11
erlang/receive.erl
Normal file → Executable file
@ -5,24 +5,23 @@
|
||||
|
||||
main(_) ->
|
||||
{ok, Connection} = amqp_connection:start(network,
|
||||
#amqp_params{host = "localhost"}),
|
||||
#amqp_params{host = "localhost"}),
|
||||
{ok, Channel} = amqp_connection:open_channel(Connection),
|
||||
|
||||
amqp_channel:call(Channel, #'queue.declare'{queue = <<"hello">>}),
|
||||
|
||||
io:format(" [*] Waiting for messages. To exit press CTRL+C\n"),
|
||||
|
||||
amqp_channel:subscribe(Channel, #'basic.consume'{queue = <<"hello">>,
|
||||
no_ack = true}, self()),
|
||||
no_ack = true}, self()),
|
||||
receive
|
||||
#'basic.consume_ok'{} -> ok
|
||||
#'basic.consume_ok'{} -> ok
|
||||
end,
|
||||
loop(Channel).
|
||||
|
||||
|
||||
loop(Channel) ->
|
||||
receive
|
||||
{#'basic.deliver'{}, #amqp_msg{payload = Body}} ->
|
||||
io:format(" [x] Received ~p\n", [Body]),
|
||||
{#'basic.deliver'{}, #amqp_msg{payload = Body}} ->
|
||||
io:format(" [x] Received ~p\n", [Body]),
|
||||
loop(Channel)
|
||||
end.
|
||||
|
10
erlang/send.erl
Normal file → Executable file
10
erlang/send.erl
Normal file → Executable file
@ -5,16 +5,16 @@
|
||||
|
||||
main(_) ->
|
||||
{ok, Connection} = amqp_connection:start(network,
|
||||
#amqp_params{host = "localhost"}),
|
||||
#amqp_params{host = "localhost"}),
|
||||
{ok, Channel} = amqp_connection:open_channel(Connection),
|
||||
|
||||
amqp_channel:call(Channel, #'queue.declare'{queue = <<"hello">>}),
|
||||
|
||||
amqp_channel:cast(Channel,
|
||||
#'basic.publish'{
|
||||
exchange = <<"">>,
|
||||
routing_key = <<"hello">>},
|
||||
#amqp_msg{payload = <<"Hello World!">>}),
|
||||
#'basic.publish'{
|
||||
exchange = <<"">>,
|
||||
routing_key = <<"hello">>},
|
||||
#amqp_msg{payload = <<"Hello World!">>}),
|
||||
io:format(" [x] Sent 'Hello World!'\n"),
|
||||
ok = amqp_channel:close(Channel),
|
||||
ok = amqp_connection:close(Connection),
|
||||
|
@ -5,31 +5,31 @@
|
||||
|
||||
main(_) ->
|
||||
{ok, Connection} = amqp_connection:start(network,
|
||||
#amqp_params{host = "localhost"}),
|
||||
#amqp_params{host = "localhost"}),
|
||||
{ok, Channel} = amqp_connection:open_channel(Connection),
|
||||
|
||||
amqp_channel:call(Channel, #'queue.declare'{queue = <<"task_queue">>,
|
||||
durable = true}),
|
||||
durable = true}),
|
||||
io:format(" [*] Waiting for messages. To exit press CTRL+C\n"),
|
||||
|
||||
amqp_channel:call(Channel, #'basic.qos'{prefetch_count = 1}),
|
||||
amqp_channel:subscribe(Channel, #'basic.consume'{queue = <<"task_queue">>},
|
||||
self()),
|
||||
self()),
|
||||
receive
|
||||
#'basic.consume_ok'{} -> ok
|
||||
#'basic.consume_ok'{} -> ok
|
||||
end,
|
||||
loop(Channel).
|
||||
|
||||
loop(Channel) ->
|
||||
receive
|
||||
{#'basic.deliver'{delivery_tag = Tag}, #amqp_msg{payload = Body}} ->
|
||||
Dots = length([C || C <- binary_to_list(Body), C == $.]),
|
||||
io:format(" [x] Received ~p\n", [Body]),
|
||||
receive
|
||||
after
|
||||
Dots*1000 -> ok
|
||||
end,
|
||||
io:format(" [x] Done\n"),
|
||||
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
|
||||
{#'basic.deliver'{delivery_tag = Tag}, #amqp_msg{payload = Body}} ->
|
||||
Dots = length([C || C <- binary_to_list(Body), C == $.]),
|
||||
io:format(" [x] Received ~p\n", [Body]),
|
||||
receive
|
||||
after
|
||||
Dots*1000 -> ok
|
||||
end,
|
||||
io:format(" [x] Done\n"),
|
||||
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
|
||||
loop(Channel)
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user