Created
August 23, 2011 16:23
-
-
Save codysoyland/1165753 to your computer and use it in GitHub Desktop.
Riak postcommit ZeroMQ publisher
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
-module(riak_zmq). | |
-export([postcommit_publish/1, get_zmq_publisher/0, zmq_publisher/0, zmq_publisher/1]). | |
postcommit_publish(RObj) -> | |
Body = riak_object:get_value(RObj), | |
{ok, Pid} = get_zmq_publisher(), | |
Pid ! {send, Body}. | |
get_zmq_publisher() -> | |
case pg2:get_closest_pid([zmq]) of | |
{error, {no_such_group, _}} -> | |
pg2:create([zmq]), | |
get_zmq_publisher(); | |
{error, {no_process, _}} -> | |
Pid = spawn(?MODULE, zmq_publisher, []), | |
pg2:join([zmq], Pid), | |
{ok, Pid}; | |
Pid -> | |
{ok, Pid} | |
end. | |
zmq_publisher() -> | |
{ok, _Pid} = zmq:start_link(), | |
{ok, Socket} = zmq:socket(pub), | |
zmq:bind(Socket, "tcp://127.0.0.1:5550"), | |
zmq_publisher(Socket). | |
zmq_publisher(Socket) -> | |
receive | |
{send, Msg} -> zmq:send(Socket, Msg), zmq_publisher(Socket) | |
end. |
@codysoyland Yes, your postcommit hook can make sure the application (and thus its supervisor and worker processes) are started. Rejiggered your code here: https://github.com/seancribbs/riak_zmq
Very cool. thanks. I was looking into how to turn it into an OTP app. Again, totally new to this (I've only dabbled with OTP).
Hi, could you explain please what this is for, for the newbbie I am. I am appealed by riak for availability on one hand, and by 0MQ for ease of use and scallability on the other hand. Is riak_zmq the glue between both ?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way I can start the named process automatically when Riak starts? I'm new to Erlang, so I wasn't sure the best way to do this. I took the pg2 idea from the Riak RabbitMQ postcommit hook (https://github.com/jbrisbin/riak-rabbitmq-commit-hooks). Any guidance here would be appreciated.