Cosmetic: list comprehensions instead of funs, indentation.
This commit is contained in:
parent
cb0f9a5b00
commit
73ca6bc425
@ -50,5 +50,5 @@ You need Erlang Client binaries:
|
||||
|
||||
[Tutorial five: Topics](http://www.rabbitmq.com/tutorial-five-python.html):
|
||||
|
||||
./receive_logs_topic.erl *.rabbit
|
||||
./receive_logs_topic.erl "*.rabbit"
|
||||
./emit_log_topic.erl red.rabbit Hello
|
||||
|
@ -12,14 +12,17 @@ main(Argv) ->
|
||||
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,
|
||||
[] ->
|
||||
{<<"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},
|
||||
exchange = <<"direct_logs">>,
|
||||
routing_key = Severity},
|
||||
#amqp_msg{payload = Message}),
|
||||
io:format(" [x] Sent ~p:~p~n", [Severity, Message]),
|
||||
ok = amqp_channel:close(Channel),
|
||||
|
@ -12,14 +12,17 @@ main(Argv) ->
|
||||
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,
|
||||
[] ->
|
||||
{<<"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},
|
||||
exchange = <<"topic_logs">>,
|
||||
routing_key = RoutingKey},
|
||||
#amqp_msg{payload = Message}),
|
||||
io:format(" [x] Sent ~p:~p~n", [RoutingKey, Message]),
|
||||
ok = amqp_channel:close(Channel),
|
||||
|
@ -14,11 +14,10 @@ main(Argv) ->
|
||||
#'queue.declare_ok'{queue = Queue} =
|
||||
amqp_channel:call(Channel, #'queue.declare'{exclusive = true}),
|
||||
|
||||
lists:foreach(fun(S) ->
|
||||
amqp_channel:call(Channel, #'queue.bind'{exchange = <<"direct_logs">>,
|
||||
routing_key = list_to_binary(S),
|
||||
queue = Queue})
|
||||
end, Argv),
|
||||
[amqp_channel:call(Channel, #'queue.bind'{exchange = <<"direct_logs">>,
|
||||
routing_key = list_to_binary(Severity),
|
||||
queue = Queue})
|
||||
|| Severity <- Argv],
|
||||
|
||||
io:format(" [*] Waiting for logs. To exit press CTRL+C~n"),
|
||||
|
||||
@ -31,7 +30,7 @@ main(Argv) ->
|
||||
|
||||
loop(Channel) ->
|
||||
receive
|
||||
{#'basic.deliver'{routing_key=RoutingKey}, #amqp_msg{payload = Body}} ->
|
||||
{#'basic.deliver'{routing_key = RoutingKey}, #amqp_msg{payload = Body}} ->
|
||||
io:format(" [x] ~p:~p~n", [RoutingKey, Body]),
|
||||
loop(Channel)
|
||||
end.
|
||||
|
@ -14,11 +14,10 @@ main(Argv) ->
|
||||
#'queue.declare_ok'{queue = Queue} =
|
||||
amqp_channel:call(Channel, #'queue.declare'{exclusive = true}),
|
||||
|
||||
lists:foreach(fun(R) ->
|
||||
amqp_channel:call(Channel, #'queue.bind'{exchange = <<"topic_logs">>,
|
||||
routing_key = list_to_binary(R),
|
||||
queue = Queue})
|
||||
end, Argv),
|
||||
[amqp_channel:call(Channel, #'queue.bind'{exchange = <<"topic_logs">>,
|
||||
routing_key = list_to_binary(BindingKey),
|
||||
queue = Queue})
|
||||
|| BindingKey <- Argv],
|
||||
|
||||
io:format(" [*] Waiting for logs. To exit press CTRL+C~n"),
|
||||
|
||||
@ -31,7 +30,7 @@ main(Argv) ->
|
||||
|
||||
loop(Channel) ->
|
||||
receive
|
||||
{#'basic.deliver'{routing_key=RoutingKey}, #amqp_msg{payload = Body}} ->
|
||||
{#'basic.deliver'{routing_key = RoutingKey}, #amqp_msg{payload = Body}} ->
|
||||
io:format(" [x] ~p:~p~n", [RoutingKey, Body]),
|
||||
loop(Channel)
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user