-
-
Save Gsantomaggio/e4fcb9db8d4cb605d5d9 to your computer and use it in GitHub Desktop.
issue_35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%%%------------------------------------------------------------------- | |
%%% @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