forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit_log.erl
executable file
·24 lines (20 loc) · 883 Bytes
/
emit_log.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
#!/usr/bin/env escript
%%! -pz ./amqp_client ./rabbit_common ./amqp_client/ebin ./rabbit_common/ebin
-include_lib("amqp_client/include/amqp_client.hrl").
main(Argv) ->
{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">>}),
Message = case Argv of
[] -> <<"info: Hello World!">>;
Msg -> list_to_binary(string:join(Msg, " "))
end,
amqp_channel:cast(Channel,
#'basic.publish'{exchange = <<"logs">>},
#amqp_msg{payload = Message}),
io:format(" [x] Sent ~p~n", [Message]),
ok = amqp_channel:close(Channel),
ok = amqp_connection:close(Connection),
ok.