Skip to content

Commit

Permalink
Cosmetic: list comprehensions instead of funs, indentation.
Browse files Browse the repository at this point in the history
  • Loading branch information
majek committed Jul 20, 2011
1 parent cb0f9a5 commit 73ca6bc
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
2 changes: 1 addition & 1 deletion erlang/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
15 changes: 9 additions & 6 deletions erlang/emit_log_direct.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
15 changes: 9 additions & 6 deletions erlang/emit_log_topic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
11 changes: 5 additions & 6 deletions erlang/receive_logs_direct.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand All @@ -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.
11 changes: 5 additions & 6 deletions erlang/receive_logs_topic.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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"),

Expand All @@ -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.