forked from rabbitmq/rabbitmq-tutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
emit_log_topic.erl
executable file
·30 lines (26 loc) · 1.28 KB
/
emit_log_topic.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
-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 = <<"topic_logs">>,
type = <<"topic">>}),
{RoutingKey, Message} = case Argv of
[] ->
{<<"anonymous.info">>, <<"Hello World!">>};
[R] ->
{list_to_binary(R), <<"Hello World!">>};
[R | Msg] ->
{list_to_binary(R), list_to_binary(string:join(Msg, " "))}
end,
amqp_channel:cast(Channel,
#'basic.publish'{
exchange = <<"topic_logs">>,
routing_key = RoutingKey},
#amqp_msg{payload = Message}),
io:format(" [x] Sent ~p:~p~n", [RoutingKey, Message]),
ok = amqp_channel:close(Channel),
ok = amqp_connection:close(Connection),
ok.