小编use*_*860的帖子

如何在不启动每个节点的依赖项的情况下启动分布式Erlang应用程序?

我尝试以分布式方式运行一个简单的应用程序来测试故障转移接管功能但是失败了.

我想要的是:

应用程序myapp_api使用rest api,它将myapp应用程序作为依赖项.我想从myapp_api3个节点开始,我希望整个应用程序(myapp_api+ myapp)只能同时在一个节点上工作.

怎么了:

主app(myapp_api)按预期工作:仅在具有故障转移和接管的一个节点上.但由于某些原因,依赖myapp总是从每个节点开始.我希望它只能同时在一个节点上工作.

我所做的:

我以第一个节点的配置为例.

[
    {kernel,
    [{distributed, [{myapp_api,
        1000,
        ['n1@myhost', {'n2@myhost', 'n3@myhost'}]}]},
        {sync_nodes_optional, ['n2@myhost', 'n3@myhost']},
        {sync_nodes_timeout, 5000}
    ]}
].
Run Code Online (Sandbox Code Playgroud)

erl -sname nI -config nI.config -pa apps/*/ebin deps/*/ebin -s myapp_api在每个节点打电话 .

erlang failover distributed

5
推荐指数
1
解决办法
288
查看次数

为什么int32(0)不是reflect.DeepEqual在Golang中键入Zero?

我在go-swagger包中找到了这种验证.

// Required validates an interface for requiredness
func Required(path, in string, data interface{}) *errors.Validation {
    val := reflect.ValueOf(data)
    if reflect.DeepEqual(reflect.Zero(val.Type()), val) {
        return errors.Required(path, in)
    }
    return nil
}
Run Code Online (Sandbox Code Playgroud)

我试图使用它,这迫使我做了一些想法.

为什么以下不是真实的陈述?

exper := int32(0)
reflect.DeepEqual(
   reflect.Zero(reflect.ValueOf(exper).Type()), 
   reflect.ValueOf(exper)
)
Run Code Online (Sandbox Code Playgroud)

reflection go swagger

1
推荐指数
1
解决办法
122
查看次数

Erlang:为什么我不能链接两个gen_servers?

我有两个gen_server模块.
第一个serv.erl

-module(serv).
-behaviour(gen_server).
-export([init/1, 
     handle_call/3,
     handle_cast/2, 
     handle_info/2,
     code_change/3,
     terminate/2,
     start_link/0
    ]).
start_link() ->
    gen_server:start_link(?MODULE, [], []).

init([]) ->
    process_flag(trap_exit, true),
    spawn_link(user, start_link,[]),
    {ok, []}.

handle_call(_E, _From, State) ->
        {noreply, State}.

handle_cast(_Message, State) ->
    {noreply, State}.

terminate(_Reason, _State) ->
    ok.

handle_info(Message, State) ->
    {noreply, State}.

code_change(_OldVersion, State, _Extra) ->
    {ok, State}.
Run Code Online (Sandbox Code Playgroud)

user.erl(除了init/1完全相同):

init([]) ->
     {ok, []}.
Run Code Online (Sandbox Code Playgroud)

我以为服务器会永远存在.如果第一台服务器死了,另一台服务器会收到{'EXIT',Pid,Reason}消息.

但是如果你通过serv:start_link()启动模块,用户模块将在启动后立即退出,并显示消息{'EXIT',Pid,normal}.为什么用户会死?

erlang spawn gen-server

0
推荐指数
1
解决办法
870
查看次数

标签 统计

erlang ×2

distributed ×1

failover ×1

gen-server ×1

go ×1

reflection ×1

spawn ×1

swagger ×1