forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit_log_direct.erl
executable file
·30 lines (26 loc) · 1.26 KB
/
emit_log_direct.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
#!/usr/bin/env escript
%%! -pz ./amqp_client ./rabbit_common ./amqp_client/ebin ./rabbit_common/ebin ./recon/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 = <<"direct_logs">>,
type = <<"direct">>}),
{Severity, Message} = case Argv of
[] ->
{<<"info">>, <<"Hello World!">>};
[S] ->
{list_to_binary(S), <<"Hello World!">>};
[S | Msg] ->
{list_to_binary(S), list_to_binary(string:join(Msg, " "))}
end,
amqp_channel:cast(Channel,
#'basic.publish'{
exchange = <<"direct_logs">>,
routing_key = Severity},
#amqp_msg{payload = Message}),
io:format(" [x] Sent ~p:~p~n", [Severity, Message]),
ok = amqp_channel:close(Channel),
ok = amqp_connection:close(Connection),
ok.