This repository has been archived by the owner on Jul 16, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename services to reflect the underlying socket, to avoid another le…
…vel of meaning flipping. The pub service has a pub socket and you connect sub sockets to it. Easy. (Also, add a file that had slipped through the net. Ops.)
- Loading branch information
Showing
10 changed files
with
72 additions
and
26 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[{r0mq, | ||
[{services, | ||
[{<<"PIPELINE">>, push, "tcp://127.0.0.1:5557"}, | ||
{<<"PIPELINE">>, pull, "tcp://127.0.0.1:5558"}]}]}]. | ||
[{<<"PIPELINE">>, pull, "tcp://127.0.0.1:5557"}, | ||
{<<"PIPELINE">>, push, "tcp://127.0.0.1:5558"}]}]}]. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[{r0mq, | ||
[{services, | ||
[{<<"PUBSUB">>, pub, "tcp://127.0.0.1:5555"}, | ||
{<<"PUBSUB">>, sub, "tcp://127.0.0.1:5556"}]}]}]. | ||
[{<<"PUBSUB">>, sub, "tcp://127.0.0.1:5555"}, | ||
{<<"PUBSUB">>, pub, "tcp://127.0.0.1:5556"}]}]}]. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[{r0mq, | ||
[{services, | ||
[{<<"REQREP">>, req, "tcp://127.0.0.1:5559"}, | ||
{<<"REQREP">>, rep, "tcp://127.0.0.1:5560"}]}]}]. | ||
[{<<"REQREP">>, rep, "tcp://127.0.0.1:5559"}, | ||
{<<"REQREP">>, req, "tcp://127.0.0.1:5560"}]}]}]. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-module(r0mq_pub_service). | ||
|
||
%% A pub service. | ||
%% | ||
%% See http://wiki.github.com/rabbitmq/rmq-0mq/pubsub | ||
|
||
%% Callbacks | ||
-export([init/3, create_socket/0, | ||
start_listening/2, zmq_message/3, amqp_message/5]). | ||
|
||
-include_lib("amqp_client/include/amqp_client.hrl"). | ||
|
||
-record(state, {queue}). | ||
|
||
%% -- Callbacks -- | ||
|
||
create_socket() -> | ||
{ok, Out} = zmq:socket(pub, [{active, true}]), | ||
Out. | ||
|
||
init(Options, Connection, ConsumeChannel) -> | ||
Exchange = case r0mq_util:get_option(name, Options) of | ||
missing -> throw({?MODULE, no_name_supplied, Options}); | ||
Name -> Name | ||
end, | ||
case r0mq_util:ensure_exchange(Exchange, <<"fanout">>, Connection) of | ||
{error, _, _Spec} -> | ||
%io:format("Error declaring exchange ~p~n", [Spec]), | ||
throw({cannot_declare_exchange, Exchange}); | ||
{ok, Exchange} -> | ||
%io:format("Exchange OK ~p~n", [Exchange]), | ||
{ok, Queue} = r0mq_util:create_bind_private_queue( | ||
Exchange, <<"">>, ConsumeChannel), | ||
%io:format("Using queue ~p~n", [Queue]), | ||
{ok, #state{queue = Queue}} | ||
end. | ||
|
||
start_listening(Channel, State = #state{queue = Queue}) -> | ||
Consume = #'basic.consume'{ queue = Queue, | ||
no_ack = true, | ||
exclusive = true }, | ||
amqp_channel:subscribe(Channel, Consume, self()), | ||
{ok, State}. | ||
|
||
zmq_message(Data, _Channel, _State) -> | ||
throw({?MODULE, unexpected_zmq_message, Data}). | ||
|
||
amqp_message(_Env, #amqp_msg{ payload = Payload }, Sock, _Channel, State) -> | ||
zmq:send(Sock, Payload), | ||
{ok, State}. |
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
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
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
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
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
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