nsq的erlang客户端

nsq是基于golang开发的分布式消息系统,这里仅仅贴个和erlang之间的通信demo

rebar-creator create-app test_nsq

 

rebar.config

% -*- erlang -*-
{erl_opts, [debug_info]}.
{deps, [
  {ensq,".*",{git, "https://github.com/project-fifo/ensq.git", {tag, "0.1.5"}}}
]}.
{cover_enabled, true}.
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]}.
{sub_dirs, ["apps/test_nsq", "rel"]}.

 

my_nsq.erl

-module(my_nsq).

-export([connect/0,send/0]).

connect() ->
    ensq:start(),
    DiscoveryServers = [{"localhost", 4161}], %% Discovery Server
    Channels = [
        {
            <<"channel1">>,         %% Channel name
            ensq_debug_callback     %% 预定义的调试模块,可修改为自己的
        },
        {
            <<"channel2">>,
            ensq_debug_callback
        }
    ],
    ensq_topic:discover(
        my_topic,                               %% Topic
        DiscoveryServers,                       %% Discovery servers to use
        Channels,                               %% Channels to join.
        [{"localhost", 4150}]).                 %% Targets for SUBing


send() ->
    %% Sending a message to a topic
    ensq:send(my_topic, <<"hello channel1!">>),
    ensq:send(my_topic, <<"hello channel2!">>).

 

nsq的客户端库列表参考

 

posted @ 2015-12-13 22:59  自由出土文物  阅读(343)  评论(0)    收藏  举报