forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
receive_logs.erl
executable file
·34 lines (26 loc) · 1.15 KB
/
receive_logs.erl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env escript
%%! -pz ./amqp_client ./rabbit_common ./amqp_client/ebin ./rabbit_common/ebin
-include_lib("amqp_client/include/amqp_client.hrl").
main(_) ->
{ok, Connection} =
amqp_connection:start(#amqp_params_network{host = "localhost"}),
{ok, Channel} = amqp_connection:open_channel(Connection),
amqp_channel:call(Channel, #'exchange.declare'{exchange = <<"logs">>,
type = <<"fanout">>}),
#'queue.declare_ok'{queue = Queue} =
amqp_channel:call(Channel, #'queue.declare'{exclusive = true}),
amqp_channel:call(Channel, #'queue.bind'{exchange = <<"logs">>,
queue = Queue}),
io:format(" [*] Waiting for logs. To exit press CTRL+C~n"),
amqp_channel:subscribe(Channel, #'basic.consume'{queue = Queue,
no_ack = true}, self()),
receive
#'basic.consume_ok'{} -> ok
end,
loop(Channel).
loop(Channel) ->
receive
{#'basic.deliver'{}, #amqp_msg{payload = Body}} ->
io:format(" [x] ~p~n", [Body]),
loop(Channel)
end.