Skip to content
Browse files

Cosmetic: list comprehensions instead of funs, indentation.

  • Loading branch information...
1 parent cb0f9a5 commit 73ca6bc42559ed7de4f8936839e6be9d322a5bfe @majek majek committed Jul 20, 2011
Showing with 29 additions and 25 deletions.
  1. +1 −1 erlang/README.md
  2. +9 −6 erlang/emit_log_direct.erl
  3. +9 −6 erlang/emit_log_topic.erl
  4. +5 −6 erlang/receive_logs_direct.erl
  5. +5 −6 erlang/receive_logs_topic.erl
View
2 erlang/README.md
@@ -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
View
15 erlang/emit_log_direct.erl
@@ -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),
View
15 erlang/emit_log_topic.erl
@@ -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),
View
11 erlang/receive_logs_direct.erl
@@ -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.
View
11 erlang/receive_logs_topic.erl
@@ -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.

0 comments on commit 73ca6bc

Please sign in to comment.
Something went wrong with that request. Please try again.