Skip to content

Instantly share code, notes, and snippets.

@Gsantomaggio
Last active August 28, 2015 21:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gsantomaggio/e4fcb9db8d4cb605d5d9 to your computer and use it in GitHub Desktop.
Save Gsantomaggio/e4fcb9db8d4cb605d5d9 to your computer and use it in GitHub Desktop.
issue_35
%%%-------------------------------------------------------------------
%%% @author gabriele
%%% @copyright (C) 2015, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 27. Aug 2015 12:01
%%%-------------------------------------------------------------------
-module(issue_management_35).
-author("gabriele").
-include("amqp_client.hrl").
-export([loop/1, test/0, publish/1, internalPublish/2]).
loop(Channel) ->
receive
%% This is received when the subscription is cancelled
#'basic.cancel_ok'{} ->
ok;
%% A delivery
{#'basic.deliver'{delivery_tag = Tag}, _Content} ->
amqp_channel:cast(Channel, #'basic.ack'{delivery_tag = Tag}),
%% Loop
loop(Channel)
end.
internalPublish(Count, _Channel) when Count == 0 -> done;
internalPublish(Count, Channel) when Count > 0 ->
amqp_channel:cast(Channel,
#'basic.publish'{
exchange = <<"">>,
routing_key = <<"issue_35">>},
#amqp_msg{payload = <<"Hello World!">>}),
internalPublish(Count - 1, Channel).
publish(Channel) ->
internalPublish(90000000000, Channel),
ok.
test() ->
%% Start a network connection
{ok, Connection} = amqp_connection:start(#amqp_params_network{}),
%% Open a channel on the connection
{ok, Channel} = amqp_connection:open_channel(Connection),
io:format("ready\n"),
%% Declare a queue
#'queue.declare_ok'{queue = Q}
= amqp_channel:call(Channel, #'queue.declare'{durable = true, queue = <<"issue_35">>}),
Sub = #'basic.consume'{queue = Q},
#'basic.consume_ok'{consumer_tag = Tag} =
amqp_channel:call(Channel, Sub), %% the caller is the subscriber
receive
#'basic.consume_ok'{} -> ok,
spawn(?MODULE, publish, [Channel])
end,
loop(Channel).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment