6.1. Erlang 支持

快速开始

建议先使用 Java 定义接口 jar,并使用 erlanalysis 工具解析Java接口至Erlang lib

导入依赖库

使用 Rebar 编译工具

{deps, [
    {dubboerl, {git, "https://github.com/apache/dubbo-erlang.git", {branch, "master"}}}
]}.

导入接口库

Suppose the interface lib you exported is called dubbo_service.

  • If you didn’t upload your lib to your Git repository, It is recommended that you copy the dubbo_service lib into the project’s apps directory.
  • If it is upload to your Git repository, you can import like this:
{deps, [
    {dubboerl, {git, "https://github.com/apache/dubbo-erlang.git", {branch, "master"}}},
    {dubbo_service,{git,"${INTERFACE_LIB_URL}",{branch,"master"}}} %% replace ${INTERFACE_LIB_URL} with your lib git repos url
]}.

消费者配置

Please reference Reference Config

Init dubbolib in your project

It is need you

dubboerl:init().

如何调用?

同步调用

Request = #userInfoRequest{requestId = 123, username = "testname"},
{ok,RequestRef,Response,RpcContent}  = userOperator:queryUserInfo(Request,#{sync=> true}).

If it occur error, is reponse {error,Reason}.

异步调用

Default is Async call.

Request = #userInfoRequest{requestId = 123, username = "testname"},
{ok,RequestRef} = userOperator:queryUserInfo(Request).
%% you can receive the message after.
handle_cast({msg_back,RequestRef,Response,RpcContent},State).

示例

参考项目 dubboerl_demo

消费者配置

基础配置

消费者配置项需要添加到 sys.config 文件 dubboerl 应用配置项里。

{dubboerl,[
    %% other config ...
    {consumer,[
        {<<"interface fullname">>,[Option]},
        %% eg:
        {<<"org.apache.dubbo.erlang.sample.service.facade.UserOperator">>,[]},
    ]}
]}

Option 配置项待添加中。

提供者配置

在 erlang 中配置服务提供者

基本配置

提供者配置项需要添加到 sys.config 文件 dubboerl 应用配置项里。

{dubboerl,[
    %% other config ...
    {provider,[
        {module_implements,interface_module,interface_fullname,[Options]},
        %% eg:
        {userOperator_impl,userOperator,<<"org.apache.dubbo.erlang.sample.service.facade.UserOperator">>,[Option]}
    ]}
]}
ConfigName Type DefaultValue Remarks
module_implements atom() - The service implements module name
interface_module atom() - Interface module name is transfer form Java jar
interface_fullname binary() - Interface full name is the Java class name

序列化配置项

在 erlang 中配置序列化方式,当前该库只实现了 dubbo:// 通讯协议。序列化方式实现了 hessianjson 两种方式。

配置样例

序列化配置需要添加到 sys.config 文件 dubboerl 应用配置项里。

{dubboerl,[
    %% other config ...
    {protocol,hessian}
]}
ConfigName Type DefaultValue Remarks
protocol atom() hessian hessian,json