A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Related tags

Miscellaneous motan
Overview

Motan

License Maven Central Build Status OpenTracing-1.0 Badge Skywalking Tracing

Overview

Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Related projects in Motan ecosystem:

Features

  • Create distributed services without writing extra code.
  • Provides cluster support and integrate with popular service discovery services like Consul or Zookeeper.
  • Supports advanced scheduling features like weighted load-balance, scheduling cross IDCs, etc.
  • Optimization for high load scenarios, provides high availability in production environment.
  • Supports both synchronous and asynchronous calls.
  • Support cross-language interactive with Golang, PHP, Lua(Luajit), etc.

Quick Start

The quick start gives very basic example of running client and server on the same machine. For the detailed information about using and developing Motan, please jump to Documents.

The minimum requirements to run the quick start are:

  • JDK 1.7 or above
  • A java-based project management software like Maven or Gradle

Synchronous calls

  1. Add dependencies to pom.
<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-core</artifactId>
       <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-transport-netty</artifactId>
    <version>1.0.0</version>
</dependency>

<!-- dependencies below were only needed for spring-based features -->
<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-springsupport</artifactId>
    <version>1.0.0</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>
  1. Create an interface for both service provider and consumer.

    src/main/java/quickstart/FooService.java

    package quickstart;
    
    public interface FooService {
        public String hello(String name);
    }
  2. Write an implementation, create and start RPC Server.

    src/main/java/quickstart/FooServiceImpl.java

    package quickstart;
    
    public class FooServiceImpl implements FooService {
    
        public String hello(String name) {
            System.out.println(name + " invoked rpc service");
            return "hello " + name;
        }
    }

    src/main/resources/motan_server.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:motan="http://api.weibo.com/schema/motan"
        xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
    
        <!-- service implementation bean -->
        <bean id="serviceImpl" class="quickstart.FooServiceImpl" />
        <!-- exporting service by motan -->
        <motan:service interface="quickstart.FooService" ref="serviceImpl" export="8002" />
    </beans>

    src/main/java/quickstart/Server.java

    package quickstart;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    public class Server {
    
        public static void main(String[] args) throws InterruptedException {
            ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:motan_server.xml");
            System.out.println("server start...");
        }
    }

    Execute main function in Server will start a motan server listening on port 8002.

  3. Create and start RPC Client.

    src/main/resources/motan_client.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:motan="http://api.weibo.com/schema/motan"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
       http://api.weibo.com/schema/motan http://api.weibo.com/schema/motan.xsd">
    
        <!-- reference to the remote service -->
        <motan:referer id="remoteService" interface="quickstart.FooService" directUrl="localhost:8002"/>
    </beans>

    src/main/java/quickstart/Client.java

    package quickstart;
    
    import org.springframework.context.ApplicationContext;
    import org.springframework.context.support.ClassPathXmlApplicationContext;
    
    
    public class Client {
    
        public static void main(String[] args) throws InterruptedException {
            ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:motan_client.xml");
            FooService service = (FooService) ctx.getBean("remoteService");
            System.out.println(service.hello("motan"));
        }
    }

    Execute main function in Client will invoke the remote service and print response.

Asynchronous calls

  1. Based on the Synchronous calls example, add @MotanAsync annotation to interface FooService.

    package quickstart;
    import com.weibo.api.motan.transport.async.MotanAsync;
    
    @MotanAsync
    public interface FooService {
        public String hello(String name);
    }
  2. Include the plugin into the POM file to set target/generated-sources/annotations/ as source folder.

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>build-helper-maven-plugin</artifactId>
        <version>1.10</version>
        <executions>
            <execution>
                <phase>generate-sources</phase>
                <goals>
                    <goal>add-source</goal>
                </goals>
                <configuration>
                    <sources>
                        <source>${project.build.directory}/generated-sources/annotations</source>
                    </sources>
                </configuration>
            </execution>
        </executions>
    </plugin>
  3. Modify the attribute interface of referer in motan_client.xml from FooService to FooServiceAsync.

    <motan:referer id="remoteService" interface="quickstart.FooServiceAsync" directUrl="localhost:8002"/>
  4. Start asynchronous calls.

    public static void main(String[] args) {
        ApplicationContext ctx = new ClassPathXmlApplicationContext(new String[] {"classpath:motan_client.xml"});
    
        FooServiceAsync service = (FooServiceAsync) ctx.getBean("remoteService");
    
        // sync call
        System.out.println(service.hello("motan"));
    
        // async call
        ResponseFuture future = service.helloAsync("motan async ");
        System.out.println(future.getValue());
    
        // multi call
        ResponseFuture future1 = service.helloAsync("motan async multi-1");
        ResponseFuture future2 = service.helloAsync("motan async multi-2");
        System.out.println(future1.getValue() + ", " + future2.getValue());
    
        // async with listener
        FutureListener listener = new FutureListener() {
            @Override
            public void operationComplete(Future future) throws Exception {
                System.out.println("async call "
                        + (future.isSuccess() ? "success! value:" + future.getValue() : "fail! exception:"
                                + future.getException().getMessage()));
            }
        };
        ResponseFuture future3 = service.helloAsync("motan async multi-1");
        ResponseFuture future4 = service.helloAsync("motan async multi-2");
        future3.addListener(listener);
        future4.addListener(listener);
    }

Documents

Contributors

License

Motan is released under the Apache License 2.0.

Comments
  • 服务端抛出自定义业务异常,在客户端得到的也是MotanServiceException异常信息。

    服务端抛出自定义业务异常,在客户端得到的也是MotanServiceException异常信息。

    跟踪到如下图的客户端的异常信息位置,抛出的也是MotanServiceException异常信息,怎么样能在客户端得到自定义异常信息。 看到之前提出的issue是说可以的,但是我跟踪了代码为啥就不行? 一直走到图中biz exception cause is null这个分支。 补充:服务端和客户端都都是用自定义业务异常类的。

    image

    opened by cheniqit 18
  • motan是否有兴趣加入opentracing标准化追踪?

    motan是否有兴趣加入opentracing标准化追踪?

    你好,我是OpenTracing组织的中国区成员, OpenTracing已经是CNCF级别的追踪标准。

    OpenTracing官网:http://opentracing.io

    motan作为RPC框架,面向微服务的框架,希望能够积极加入。 我希望通过你们的帮助,通过RP提交相应的支持模块,保证OpenTracing的兼容性。

    如果你们感兴趣,请直接回复我。

    opened by wu-sheng 16
  • async-call support for motan

    async-call support for motan

    When we use Motan to make a rpc call, the thread will be blocked until response returned from remote server. This makes code simple but not good enough in some scenarios.

    For example, if we query three lists, the block version is:

    list1 = remoteService.query(param1);
    list2 = remoteService.query(param2);
    list3 = remoteService.query(param3);
    result = merge(list1,list2,list3);
    

    If each query takes 200ms, all queries will take 600ms. But if three query run in parallel. It will take only 200ms.

    There're many ways of parallel executing. We're looking for a way to make rpc call more efficiently without make the code too complex.

    Here's some way we've considered:

    generation async code with JAP

    We could generate async code by compiler, it likes:

    server:
    @Async
    public String hello(String name);
    
    client:
    Future resultFuture = remoteService.hello("motan");
    String result = resultFuture.get();
    

    lambda

    Future resultFuture = MotanAsyncInvoker.invoke(() -> {
        // do something
    });
    String result = resultFuture.get();
    

    async context

    remoteService.hello("motan");
    Future resultFuture pFuture = RpcContext.getContext().getFuture();
    String result = resultFuture.get();
    

    We may start to implement this feature in a few months, after php-yar support and some doc work.

    Any thoughts?

    feature 
    opened by qdaxb 15
  • 异步调用返回的结果貌似混淆了

    异步调用返回的结果貌似混淆了

    代码如下: future = service.asyncCall(param); listener = new FutureListener({...}); future.addListener(listener);

    发现经常出现不同param的调用结果出现在同一个回调返回中,比如param1和param2分别对应的结果都出现在同一次operationComplete中(比如param1对应的那次),那么相应的就是param2对应的operationComplete拿不到任何数据

    @rayzhang0603

    opened by rayeaster 14
  • 服务端已经启动成功,但是为什么客户端启动的时候,一直报找不到订阅消息的错误?

    服务端已经启动成功,但是为什么客户端启动的时候,一直报找不到订阅消息的错误?

    服务端日志; 2016-06-22 17:44:22.393 INFO 8072 --- [pool-3-thread-1] serviceStatsLog : [motan-totalAccessStatistic] app: motan module: motan total_count: 0 slow_count: 0 biz_excp: 0 other_excp: 0 avg_time: 0.00ms biz_time: 0.00ms avg_tps: 0 2016-06-22 17:44:22.396 INFO 8072 --- [pool-3-thread-1] serviceStatsLog : [motan-memoryStatistic] 124.68MB of 1797.50 MB (6.9%) used 2016-06-22 17:44:22.397 INFO 8072 --- [pool-3-thread-1] serviceStatsLog : [motan-statisticCallback] identity: motan://192.168.20.208:8002/activeGroup/com.epai.contract.iface.ActivityService/1.0/service connectionCount: 0 taskCount: 0 queueCount: 0 maxThreadCount: 800 maxTaskCount: 800 2016-06-22 17:44:22.397 INFO 8072 --- [pool-3-thread-1] serviceStatsLog : [motan-statisticCallback] identity: motan://192.168.20.208:8003/dataCrawlGroup/com.epai.contract.iface.DataCrawlService/1.0/service connectionCount: 0 taskCount: 0 queueCount: 0 maxThreadCount: 800 maxTaskCount: 800

    错误描述: Caused by: com.weibo.api.motan.exception.MotanFrameworkException: error_message: Failed to subscribe motan://192.168.20.208:0/com.epai.contract.iface.ActivityService?group=activeGroup to zookeeper(zookeeper://127.0.0.1:2181/com.weibo.api.motan.registry.RegistryService?group=default_rpc), cause: null, status: 503, error_code: 20001,r= at com.weibo.api.motan.registry.zookeeper.ZookeeperRegistry.doSubscribe(ZookeeperRegistry.java:98) ~[motan-registry-zookeeper-0.1.1.jar:na] at com.weibo.api.motan.registry.support.AbstractRegistry.subscribe(AbstractRegistry.java:101) ~[motan-core-0.1.1.jar:na] at com.weibo.api.motan.registry.support.FailbackRegistry.subscribe(FailbackRegistry.java:107) ~[motan-core-0.1.1.jar:na] ... 36 common frames omitted

    opened by lijhua 14
  • 优雅关机的问题

    优雅关机的问题

    现在有个疑惑就是无法优雅的关机,根据官方文档上描述的设置了REGISTRY_HEARTBEAT_SWITCHER为false后就不会处理请求了,但是我模拟的场景依然可以处理请求数据。操作步骤如下

    1.在192.168.199.195上启动一个服务并设置REGISTRY_HEARTBEAT_SWITCHER为true,此时在管理后台可以查询到服务列表,并且也处于server状态

    2.在192.168.199.103的客户端去调用该服务,可以成功返回

    3.设置192.168.199.195上的REGISTRY_HEARTBEAT_SWITCHER为false,此时在管理后台查询服务时,Unavailable Server = 1.说明设置成功

    4.在192.168.199.103的客户端去调用该服务依然可以成功返回

    预期第四步应该是没有返回才对的,请帮忙解答一下

    opened by estn 13
  • 一个服务即作客户端又做服务端时,服务端发布不成功?

    一个服务即作客户端又做服务端时,服务端发布不成功?

    该服务的 motan_server.xml 配置如下:

    <motan:registry regProtocol="zookeeper" name="my_zookeeper" address="120.76.157.7:2181" />

    <motan:protocol id="tppUsersMotan" default="true" name="motan"
                    maxServerConnection="80000" maxContentLength="1048576"
                    maxWorkerThread="800" minWorkerThread="20"/>
    
      <motan:basicService export="tppUsersMotan:9090" registry="my_zookeeper"
                        group="motan-tpp-users-rpc" accessLog="false" shareChannel="true" module="giftformama-users-rpc" host="112.124.50.158"
                        application="giftformama" id="serviceBasicConfig"/>
    
    <!-- service implemention bean 发布服务接口 -->
    <bean id="usersServiceImpl" class="com.rekchina.giftformama.users.service.impl.UsersServiceImpl" />
    <bean id="userKidsServiceImpl" class="com.rekchina.giftformama.users.service.impl.UserKidsServiceImpl" />
    <bean id="authCodeServiceImpl" class="com.rekchina.giftformama.users.service.impl.AuthCodeServiceImpl" />
    <bean id="styleImagesServiceImpl" class="com.rekchina.giftformama.users.service.impl.StyleImagesServiceImpl" />
    <bean id="stylesServiceImpl" class="com.rekchina.giftformama.users.service.impl.StylesServiceImpl" />
    
    <!-- exporting service by motan -->
    <motan:service interface="com.rekchina.giftformama.users.service.UsersService" ref="usersServiceImpl" basicService="serviceBasicConfig" />
    <motan:service interface="com.rekchina.giftformama.users.service.UserKidsService" ref="userKidsServiceImpl" basicService="serviceBasicConfig" />
    <motan:service interface="com.rekchina.giftformama.users.service.AuthCodeService" ref="authCodeServiceImpl" basicService="serviceBasicConfig" />
    <motan:service interface="com.rekchina.giftformama.users.service.StyleImagesService" ref="styleImagesServiceImpl" basicService="serviceBasicConfig" />
    <motan:service interface="com.rekchina.giftformama.users.service.StylesService" ref="stylesServiceImpl" basicService="serviceBasicConfig" />
    

    该服务的 motan_client.xml 配置如下: <motan:registry regProtocol="zookeeper" name="my_zookeeper" address="120.76.157.7:2181" />

    <!-- motan协议配置 -->
    <motan:protocol default="true" name="motan" haStrategy="failover"
                    loadbalance="roundrobin" maxClientConnection="10" minClientConnection="2"/>
    
    <!-- 通用referer基础配置 -->
    <motan:basicReferer requestTimeout="200" accessLog="false"
                        retries="2" group="motan-tpp-rpc" module="giftformama-rpc"
                        application="giftformama" protocol="motan" registry="my_zookeeper"
                        id="refererBasicConfig" throwException="false" check="true"/>
    
    <!-- reference to the remote service 调用其他服务发布的接口 -->
    <motan:referer id="userAuthServiceImpl" interface="com.rekchina.giftformama.auth.service.UserAuthService" basicReferer="refererBasicConfig" />
    

    问题是:该服务端的方法有调用其他服务发布的接口,所以既有服务端配置也有客户端配置。单独发布测试都没有问题,一起发布就出现问题了。能调用其他服务端,但是自己服务端发布却失败。通过查看motan_manager,可以看到:发布服务端的server都为0,调用服务的client为1。发布时候没有报任何错误,正常发布,但是服务却不可用在Zookeeper上。

    PS:如果不用这种通用配置方式,而是使用简单的,将每个接口都发布一个端口,这样是可以的。这次不可以主要是换了一种配置方式,就是多个接口共享一个端口,可是这次没成功。麻烦看下,谢谢!

    opened by catslave 13
  • 客户端调用失败

    客户端调用失败

    服务端配置:

    <motan:protocol id="mmm_service_protocol_id" name="motan" />
    
    <motan:registry regProtocol="zookeeper" name="mmm_zk"
        address="10.0.10.241:2181" />
    
    <motan:basicService id="mmm_basic_id"
        export="mmm_service_protocol_id:8002" shareChannel="true"
        application="mmm_basic_application" registry="mmm_zk" />
    
    <motan:service interface="com.xyz.TestService"
        ref="testService" basicService="mmm_basic_id" />
    
    启动后信息: 2016-10-09 13:45:12,864 DEBUG [org.apache.zookeeper.ClientCnxn] - Got ping response for sessionid: 0x157a21e1f58000f after 1ms 2016-10-09 13:45:26,198 DEBUG [org.apache.zookeeper.ClientCnxn] - Got ping response for sessionid: 0x157a21e1f58000f after 1ms 2016-10-09 13:45:35,823 INFO [serviceStatsLog] - [motan-totalAccessStatistic] app: motan module: motan total_count: 0 slow_count: 0 biz_excp: 0 other_excp: 0 avg_time: 0.00ms biz_time: 0.00ms avg_tps: 0 2016-10-09 13:45:35,824 INFO [serviceStatsLog] - [motan-memoryStatistic] 25.65MB of 1810.00 MB (1.4%) used 2016-10-09 13:45:35,824 INFO [serviceStatsLog] - [motan-statisticCallback] identity: motan://10.0.20.239:8002/default_rpc//1.0/service connectionCount: 0 taskCount: 0 queueCount: 0 maxThreadCount: 800 maxTaskCount: 800 2016-10-09 13:45:39,531 DEBUG [org.apache.zookeeper.ClientCnxn] - Got ping response for sessionid: 0x157a21e1f58000f after 1ms 2016-10-09 13:45:52,866 DEBUG [org.apache.zookeeper.ClientCnxn] - Got ping response for sessionid: 0x157a21e1f58000f after 1ms

    客户端配置:

        <motan:registry regProtocol="zookeeper" name="mmm_zk"
        address="10.0.10.241:2181" />
    
    <motan:protocol default="true" name="motan" haStrategy="failover"
        loadbalance="roundrobin" maxClientConnection="10" minClientConnection="2" />
    
    <motan:basicReferer requestTimeout="5000" accessLog="false"
        connectTimeout="3000" retries="2" group="mmm_remote_service_rpc"
        application="motan_server_benchmark_application" protocol="motan"
        registry="mmm_zk" id="motan_client_basic_config" throwException="true"
        check="true" />
    
    <motan:referer id="testService" interface="com.xyz.TestService"
        basicReferer="motan_client_basic_config" />
    
    客户端启动信息: Caused by: com.weibo.api.motan.exception.MotanFrameworkException: error_message: ClusterSupport No service urls for the refer:motan://10.0.20.239:0/mmm_remote_service_rpc/com.xyz.TestService/1.0/referer, registries:[zookeeper://10.0.10.241:2181/com.weibo.api.motan.registry.RegistryService?group=default_rpc], status: 404, error_code: 10101,r=null at com.weibo.api.motan.cluster.support.ClusterSupport.init(ClusterSupport.java:102) at com.weibo.api.motan.config.handler.SimpleConfigHandler.buildClusterSupport(SimpleConfigHandler.java:55) at com.weibo.api.motan.config.RefererConfig.createClusterSupport(RefererConfig.java:184) at com.weibo.api.motan.config.RefererConfig.initRef(RefererConfig.java:128) at com.weibo.api.motan.config.RefererConfig.getRef(RefererConfig.java:85) at com.weibo.api.motan.config.springsupport.RefererConfigBean.getObject(RefererConfigBean.java:44) at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.doGetObjectFromFactoryBean(FactoryBeanRegistrySupport.java:166) ... 50 more

    如果在客户端指定directUrl启动则正常, 有原因的吗?

    opened by kividii 11
  • 无法获取服务

    无法获取服务

    com.weibo.api.motan.exception.MotanFrameworkException: error_message: Failed to subscribe motan://169.254.130.54:0/com.xxxxxxx.passport.service.AccountService?group=default_rpc to zookeeper(zookeeper://127.0.0.1:2181/com.weibo.api.motan.registry.RegistryService?group=default_rpc), cause: null, status: 503, error_code: 20001,r=

    一直报这个错误,按照官方demo跑不起来,

    服务端配置

    <motan:registry regProtocol="zookeeper" name="registry" address="127.0.0.1:2181" connectTimeout="2000" />

    <motan:protocol id="demoMotan" default="true" name="motan"
        maxServerConnection="80000" maxContentLength="1048576"
        maxWorkerThread="800" minWorkerThread="20" />
    
    <motan:basicService id="serviceBasicConfig"
        accessLog="false" shareChannel="true" application="myMotanDemo"
        registry="registry" />
    
    <bean id="accountService" class="com.xxxxxx.passport.service.imple.AccountServiceImple"></bean>
    <motan:service interface="com.xxxxxxx.passport.service.AccountService"
        ref="accountService" export="demoMotan:8002" basicService="serviceBasicConfig" />`
    

    客户端配置

    <motan:registry regProtocol="zookeeper" name="nas_registry" address="127.0.0.1:2181" connectTimeout="2000" />

    <motan:protocol name="motan" default="true" haStrategy="failover"
        loadbalance="roundrobin" maxClientConnection="10" minClientConnection="2" />
    
    <motan:basicReferer id="motantestClientBasicConfig"
        requestTimeout="200" accessLog="false" retries="2" application="myMotanDemo"
        protocol="motan" registry="nas_registry" throwException="false" check="true" />
    
    <motan:referer id="accountService"
        interface="com.xxxxxxx.passport.service.AccountService"
        connectTimeout="300" requestTimeout="300" basicReferer="motantestClientBasicConfig" />`
    
    opened by gongrico 11
  • No available referers for call  / request timeout:

    No available referers for call / request timeout:

    Dear all

    我在使用过程中发现这个问题,先上一下 stack 信息

    1. LocalFirstLoadBalance No available referers for call

    18:49:27,268 WARN warn:75 - RefererInvocationHandler invoke false, so return default value: uri=motan://192.168.1.73:0/com.csf.api.fund.service.IFundService requestId=1545443912993219049 interface=com.csf.api.fund.service.IFundService method=getDetail(java.lang.String) com.weibo.api.motan.exception.MotanServiceException: error_message: LocalFirstLoadBalance No available referers for call : referers_size=1 requestId=1545443912993219049 interface=com.csf.api.fund.service.IFundService method=getDetail(java.lang.String), status: 503, error_code: 10001,r=null at com.weibo.api.motan.cluster.loadbalance.AbstractLoadBalance.selectToHolder(AbstractLoadBalance.java:80) at com.weibo.api.motan.cluster.ha.FailoverHaStrategy.selectReferers(FailoverHaStrategy.java:90) at com.weibo.api.motan.cluster.ha.FailoverHaStrategy.call(FailoverHaStrategy.java:53) at com.weibo.api.motan.cluster.support.ClusterSpi.call(ClusterSpi.java:73) at com.weibo.api.motan.proxy.RefererInvocationHandler.invoke(RefererInvocationHandler.java:108) at com.sun.proxy.$Proxy44.getDetail(Unknown Source) at com.csf.business.fund.FundBaseControl.listKeys(FundBaseControl.java:29) at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) at org.jboss.resteasy.plugins.server.netty.RequestDispatcher.service(RequestDispatcher.java:83) at org.jboss.resteasy.plugins.server.netty.RequestHandler.messageReceived(RequestHandler.java:52) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783) at org.jboss.netty.handler.execution.ChannelEventRunnable.run(ChannelEventRunnable.java:69) at org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor$ChildExecutor.run(OrderedMemoryAwareThreadPoolExecutor.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

    1. NettyResponseFuture request timeout

    com.weibo.api.motan.exception.MotanServiceException: error_message: NettyResponseFuture request timeout: serverPort=192.168.1.73:8002 requestId=1545439090469502977 interface=com.csf.api.fund.service.IFundService method=getDetail(java.lang.String) cost=500, status: 503, error_code: 10003,r=null at com.weibo.api.motan.transport.netty.NettyResponseFuture.timeoutSoCancel(NettyResponseFuture.java:234) at com.weibo.api.motan.transport.netty.NettyResponseFuture.getValue(NettyResponseFuture.java:137) at com.weibo.api.motan.proxy.RefererInvocationHandler.invoke(RefererInvocationHandler.java:109) at com.sun.proxy.$Proxy44.getDetail(Unknown Source) at com.csf.business.fund.FundBaseControl.listKeys(FundBaseControl.java:29) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:137) at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:179) at org.jboss.resteasy.plugins.server.netty.RequestDispatcher.service(RequestDispatcher.java:83) at org.jboss.resteasy.plugins.server.netty.RequestHandler.messageReceived(RequestHandler.java:52) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:80) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:783) at org.jboss.netty.handler.execution.ChannelEventRunnable.run(ChannelEventRunnable.java:69) at org.jboss.netty.handler.execution.OrderedMemoryAwareThreadPoolExecutor$ChildExecutor.run(OrderedMemoryAwareThreadPoolExecutor.java:316) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745)

    配置说明:
    motan-base-config.xml

    < motan:protocol id="motan-protocol" default="true" name="motan" serialization="hessian2" codec="motan" iothreads="8" requestTimeout="500" minClientConnection="50" maxClientConnection="500" minWorkerThread="50" maxWorkerThread="1024" maxContentLength="10485760" maxServerConnection="100000" poolLifo="true" lazyInit="false" cluster="default" loadbalance="localFirst" haStrategy="failover" async="false" switcherService="localSwitcherService" / >

    < motan:basicService id="serviceBasicConfig" registry="consul-registry" shareChannel="true" accessLog="false" throwException="true" group="dev-fund-service" module="dev-fund-dao" application="dev-fund-service" filter="switcher" export="motan-protocol:8002" requestTimeout="1000" / >

    < motan:basicReferer id="clientBasicConfig" registry="consul-registry" connectTimeout="500" requestTimeout="500" protocol="motan-protocol" throwException="true" check="true" accessLog="false" group="dev-fund-dao" module="dev-fund-dao" application="dev-fund-dao" version="1.0" retries="2"/ >

    背景:

    1. consul 作为 registory 工具
    2. 服务发布,尝试过 单机与 多机,server / client 放在同一个机器上,和不同机器上分别实现,都尝试过  

    问题排查:

    1. 出现timeout 时,我检察是否是应用出现的问题,// 服务正常,日志监控不曾出现 timeout 数据处理
    2. 加大connectTimeout 参数 解决不了问题
    3. switcherService 修改, 修改为 localSwitcherService 本地优先
    4. 根据 错误码说明:   503 10001 No available referers for call request // 在消费方所有referers被标为不可用,检查是否所有的请求都失败
     这里我的情况是,大部分成功,部分现现以上问题
    

    发现还是经常找不到服务,根据自己测试的情况来看,应该问题出在 服务发现上,出现服务不可用,才会出现以上情况的

    opened by yelllowhat 10
  • 两种不同方式,但是用client连接到服务失败,这是为什么?

    两种不同方式,但是用client连接到服务失败,这是为什么?

    第一步: 首先我用简单的main方法加载xml来启动motan服务,启动成功。 然后用client去连接用main方法启动的服务,是连接成功的。

    第二步: 我想集成到项目中,并用tomcat启动,发现启动成功。 但是我用第一步的clent去连接服务的时候,发现连接失败。报错如下:

    info - ClusterSupport config change notify: registry=local://127.0.0.1:0/com.weibo.api.motan.registry.RegistryService service=motan://192.168.31.244:0/default_rpc/com.mk.hotel.hotelinfo.HotelService/1.0/referer urls=[motan://localhost:10068/default_rpc/com.mk.hotel.hotelinfo.HotelService/1.0/service] 11:51:16.766 [RMI TCP Connection(2)-127.0.0.1] INFO info - refresh weight. weight= 11:51:16.766 [RMI TCP Connection(2)-127.0.0.1] INFO info - ignore weightString: 11:51:16.800 [RMI TCP Connection(2)-127.0.0.1] INFO info - NettyEndpointFactory create client: url=motan://localhost:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:51:16.910 [RMI TCP Connection(2)-127.0.0.1] INFO info - init compress codec 11:51:16.914 [RMI TCP Connection(2)-127.0.0.1] INFO info - init nettyclient. url:localhost-com.mk.hotel.hotelinfo.HotelService, use codec:DefaultRpcCodec 11:51:17.018 [New I/O client boss #1] ERROR error - NettyChannelHandler exceptionCaught: remote=null local=null event=java.net.ConnectException: Connection refused java.net.ConnectException: Connection refused at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method) ~[na:1.7.0_79] at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:739) ~[na:1.7.0_79] at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.connect(NioClientSocketPipelineSink.java:384) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.processSelectedKeys(NioClientSocketPipelineSink.java:354) ~[netty-3.2.5.Final.jar:na] at org.jboss.netty.channel.socket.nio.NioClientSocketPipelineSink$Boss.run(NioClientSocketPipelineSink.java:276) ~[netty-3.2.5.Final.jar:na] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [na:1.7.0_79] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [na:1.7.0_79] at java.lang.Thread.run(Thread.java:745) [na:1.7.0_79] 11:51:17.032 [RMI TCP Connection(2)-127.0.0.1] ERROR error - NettyClient init pool create connect Error: url=motan://localhost:10068/com.mk.hotel.hotelinfo.HotelService com.weibo.api.motan.exception.MotanServiceException: error_message: NettyChannel failed to connect to server, url: motan://localhost:10068/com.mk.hotel.hotelinfo.HotelService, result: true, success: false, connected: false, status: 503, error_code: 10001,r= at com.weibo.api.motan.transport.netty.NettyChannel.open(NettyChannel.java:150) ~[motan-transport-netty-0.1.1.jar:na] at com.weibo.api.motan.transport.netty.NettyChannelFactory.makeObject(NettyChannelFactory.java:53) ~[motan-transport-netty-0.1.1.jar:na] at org.apache.commons.pool.impl.GenericObjectPool.addObject(GenericObjectPool.java:1617) ~[commons-pool-1.5.4.jar:1.5.4] at com.weibo.api.motan.transport.AbstractPoolClient.initPool(AbstractPoolClient.java:64) ~[motan-core-0.1.1.jar:na] at com.weibo.api.motan.transport.netty.NettyClient.open(NettyClient.java:217) [motan-transport-netty-0.1.1.jar:na]

    顺便,我贴上两次启动服务的日志都是一样的: main方法启动服务: 11:37:51.118 [main] INFO info - RequestRouter addProvider: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc all_public_method_count=13 11:37:51.138 [main] INFO info - NettyEndpointFactory create no_share_channel server: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:37:51.200 [main] INFO info - NettyServer ServerChannel start Open: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:37:51.285 [main] INFO info - NettyServer ServerChannel finish Open: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:37:51.286 [main] INFO info - DefaultRpcExporter node init Success: [DefaultRpcExporter] url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:37:51.287 [main] INFO info - DefaultRpcProtocol export Success: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:37:51.298 [main] INFO info - [LocalRegistryService] Url (motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc) will register to Registry [local://127.0.0.1:0/default_rpc/com.weibo.api.motan.registry.RegistryService/1.0/service] 11:37:51.298 [main] INFO info - LocalRegistryService register: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc

    用tomcate启动服务: 11:39:58.706 [RMI TCP Connection(2)-127.0.0.1] INFO info - RequestRouter addProvider: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc all_public_method_count=13 11:39:58.715 [RMI TCP Connection(2)-127.0.0.1] INFO info - NettyEndpointFactory create no_share_channel server: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:39:58.745 [RMI TCP Connection(2)-127.0.0.1] INFO info - NettyServer ServerChannel start Open: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:39:58.820 [RMI TCP Connection(2)-127.0.0.1] INFO info - NettyServer ServerChannel finish Open: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:39:58.821 [RMI TCP Connection(2)-127.0.0.1] INFO info - DefaultRpcExporter node init Success: [DefaultRpcExporter] url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:39:58.822 [RMI TCP Connection(2)-127.0.0.1] INFO info - DefaultRpcProtocol export Success: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc 11:39:58.830 [RMI TCP Connection(2)-127.0.0.1] INFO info - [LocalRegistryService] Url (motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc) will register to Registry [local://127.0.0.1:0/default_rpc/com.weibo.api.motan.registry.RegistryService/1.0/service] 11:39:58.830 [RMI TCP Connection(2)-127.0.0.1] INFO info - LocalRegistryService register: url=motan://192.168.59.3:10068/com.mk.hotel.hotelinfo.HotelService?group=default_rpc

    opened by cheniqit 10
  • protocol's lazyInit attribute does not take effect under motan-transport-netty4

    protocol's lazyInit attribute does not take effect under motan-transport-netty4

    When we use motan-transport-netty4, and configure the <motan:protocol lazyInit="true"/>, but it does not take effect. while it works well under motan-transport-netty. Could you guys please help to fix it to make them consistent?

    opened by SimonLiuhd 1
  • Please support the feature of specifying client local address when it connects to the server

    Please support the feature of specifying client local address when it connects to the server

    Dear motan team,

    When a interface has multiple IP address, we want to specify a IP to connect with the server. Could you please support the feature of specifying client local address when it cpnnect to the server?

    1. When the client local address parameter is specified, We use the io.netty.bootstrap#connect(SocketAddress remoteAddress, SocketAddress localAddress) to build the ChannelFuture instance and then get the io.netty.channel.Channel object;
    2. When the client local address parameter is not specified Keep the current logic: use the io.netty.bootstrap#connect(SocketAddress remoteAddress) to build the ChannelFuture instance and then get the io.netty.channel.Channel object;

    Thanks a lot.

    opened by SimonLiuhd 4
  • Is there heartbeat for motan to check RPC connections?

    Is there heartbeat for motan to check RPC connections?

    Dear all,

    Here is our case: We have no registry center, and have 2 intances for the same service, using VIP banded to one instance, and client calls the service via the VIP. when the VIP is switched to another instance, the client does not check the original RPC connection, which will lead to invocations fail. But after about 20 minutes, the connection recovers (rebuild the connections, invocations are successful).

    So my quesrions are as bellows:

    1. Does exist the configuration paramters to make the invalid RPC connections are checked automatically, let them fast fail or are released, and then rebuild the connections?
    2. Can the parameters minEvictableIdleTimeMillis, softMinEvictableIdleTimeMillis and timeBetweenEvictionRunsMillis do this function? (If they can, how to configure them? From the source code, it seams that they are hardcode if I do not make a mistake)
    3. Which conditions the connections can be recovered in above case? (where the about 20 minutes comes from?) BTW, we have the net.ipv4.tcp_keepalive_time=1200, does it have the relations wth that?

    Thanks in advance.

    opened by SimonLiuhd 7
  • 关于RefererConfigBean的问题

    关于RefererConfigBean的问题

    场景:有这样一个工程M1:假设他定义了一个接口A,这个接口A需要暴露给其他服务M2、M3等服务调用,但同时M1也需要调用接口A,为了避免后续服务拆分,所以在M1工程中都统一使用MotanReferer注入bean,但是问题来了,如果统一使用MotanReferer注入bean,如果发布的bean和注入bean都在同一个工程,但依旧会走motan那套服务发现,没有办法直接引用本地的bean进行交互调用。

    opened by crab890715 1
Releases(1.1.14)
Owner
Weibo R&D Open Source Projects
Weibo R&D Open Source Projects
Tars is a high-performance RPC framework based on name service and Tars protocol, also integrated administration platform, and implemented hosting-service via flexible schedule.

TARS - A Linux Foundation Project TARS Foundation Official Website TARS Project Official Website WeChat Group: TARS01 WeChat Offical Account: TarsClou

THE TARS FOUNDATION PROJECTS 9.6k Jan 1, 2023
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP

Hprose 3.0 for PHP Introduction Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform

Hprose 2k Jan 4, 2023
A light-weight RPC implement of google protobuf RPC framework.

sofa-pbrpc A light-weight RPC implementation of Google's protobuf RPC framework. Wiki: https://github.com/baidu/sofa-pbrpc/wiki Features High performa

Baidu 2.1k Dec 10, 2022
Php-rpc-server - JSON RPC server implementation for PHP.

JSON RPC Server implementation for PHP. The json-rpc is a very simple protocol. You can see this by reading the protocol specification. This library i

null 4 Sep 28, 2022
Leaf's very own high-speed, high-performance server

[WIP] Leaf Eien Server Eien is Leaf's implementation of a high-speed, high-performance server based on powerful tools like Open Swoole and Swoole. Eie

Leaf Framework 8 Dec 28, 2022
A collection of samples that demonstrate how to call Google Cloud services from PHP.

PHP Docs Samples A collection of samples that demonstrate how to call Google Cloud services from PHP. See our other Google Cloud Platform github repos

Google Cloud Platform 875 Dec 29, 2022
A collection of samples that demonstrate how to call Google Cloud services from PHP.

PHP Docs Samples A collection of samples that demonstrate how to call Google Cloud services from PHP. See our other Google Cloud Platform github repos

Google Cloud Platform 796 Dec 22, 2021
Production-grade rapid controller development with built in love for API and Search

Installation For CakePHP 4.x compatible version: composer require friendsofcake/crud For CakePHP 3.x compatible version: composer require friendsofca

Friends Of Cake 357 Jan 2, 2023
High-performance, low-memory-footprint, single-file embedded database for key/value storage

LDBA - a fast, pure PHP, key-value database. Information LDBA is a high-performance, low-memory-footprint, single-file embedded database for key/value

Simplito 12 Nov 13, 2022
High performance pocketmine 4.0 vote plugin

Voting38 This is a threaded high performance voting plugin for PocketMine-MP API 4.0 You can configure messages and voting rewards in the config. Ther

KingOfTurkey38 7 Jun 1, 2022
High performance mine reset plugin for PocketMine-MP 4.0.0

MineReset38 High performance mine reset plugin for PocketMine-MP 4.0.0 Unlike other plugins, this plugin is not threaded but asynchronous. When a mine

KingOfTurkey38 6 Dec 17, 2022
A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products.

A high-performance license server system service for creating and managing products, major versions, and software licenses for the purpose of selling installable software products. Comes with a SDK and command-line tool. Works anywhere that PHP runs.

CubicleSoft 32 Dec 5, 2022
A high-performance event loop library for PHP

?? A high-performance event loop library for PHP ??

workbunny 13 Dec 22, 2022
High performance view templating API for PHP applications using tags & expressions inspired by Java JSTL and C compiler

View Language API Table of contents: About Expressions Tags Configuration Compilation Installation Unit Tests Examples Reference Guide About This API

Lucian Gabriel Popescu 0 Jan 9, 2022
Some Joomla! 4.x Web Services Api Examples and Experiments to raise the level of awareness of the huge potiental of Joomla! 4.x Web Services.

j4x-api-examples WHY? If you are a Joomla! developer or want to become a Joomla! developer there is a new resource for you The Official New Joomla! Ma

Mr Alexandre ELISÉ 11 Nov 29, 2022
A high-level machine learning and deep learning library for the PHP language.

Rubix ML A high-level machine learning and deep learning library for the PHP language. Developer-friendly API is delightful to use 40+ supervised and

Rubix 1.7k Jan 1, 2023
Zephir is a compiled high level language aimed to the creation of C-extensions for PHP.

Zephir - is a high level programming language that eases the creation and maintainability of extensions for PHP. Zephir extensions are exported to C c

Zephir Language 3.2k Jan 2, 2023