Skip to content

Commit

Permalink
new module with misc functions
Browse files Browse the repository at this point in the history
  • Loading branch information
videlalvaro committed Apr 30, 2011
1 parent abad595 commit f00bd8e
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions src/misc.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
-module(misc).

-include("amqp_client.hrl").

-export([declare_exchanges/1, demo_callback/2, word_count_callback/2, word_reverse_callback/2]).

declare_exchanges(Exchanges) ->
{ok, Connection} = amqp_connection:start(network, #amqp_params{}),
{ok, Channel} = amqp_connection:open_channel(Connection),

[ #'exchange.declare_ok'{} = amqp_channel:call(Channel,
#'exchange.declare'{ exchange = Name,
type = Type,
durable = Durable}) ||
{Name, Type, Durable} <- Exchanges ],

amqp_channel:close(Channel),
amqp_connection:close(Connection),
ok.

demo_callback(_Channel, #amqp_msg{payload = Msg}) ->
io:format("Got message ~p~n", [Msg]).

word_count_callback(_Channel, #amqp_msg{payload = Msg}) ->
L = length(string:tokens(binary_to_list(Msg), " ")),
io:format("Count: ~p~n", [L]).

word_reverse_callback(_Channel, #amqp_msg{payload = Msg}) ->
Words = lists:reverse(string:tokens(binary_to_list(Msg), " ")),
io:format("Reversed Words: ~p~n", [Words]).

0 comments on commit f00bd8e

Please sign in to comment.