MCPcopy Index your code
hub / github.com/weibocom/motan

github.com/weibocom/motan @1.2.6

Chat with this repo
repository ↗ · DeepWiki ↗ · release 1.2.6 ↗ · + Follow
6,161 symbols 21,748 edges 640 files 1,139 documented · 18% updated 7mo ago1.2.6 · 2025-09-15★ 5,878361 open issues
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Motan

License Maven Central codecov 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.8 or above
  • A java-based project management software like Maven or Gradle

Synchronous calls

  1. Add dependencies to pom.

<properties>
    <motan.version>1.1.12</motan.version> 
</properties>
<dependencies>
<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-core</artifactId>
    <version>${motan.version}</version>
</dependency>
<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-transport-netty</artifactId>
    <version>${motan.version}</version>
</dependency>


<dependency>
    <groupId>com.weibo</groupId>
    <artifactId>motan-springsupport</artifactId>
    <version>${motan.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>4.2.4.RELEASE</version>
</dependency>
</dependencies>
  1. Create an interface for both service provider and consumer.

src/main/java/quickstart/FooService.java

```java
package quickstart;

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

src/main/java/quickstart/FooServiceImpl.java

```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
<?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">


    <bean id="serviceImpl" class="quickstart.FooServiceImpl" />

    <motan:service interface="quickstart.FooService" ref="serviceImpl" export="8002" />
</beans>
```

src/main/java/quickstart/Server.java

```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.

  1. Create and start RPC Client.

src/main/resources/motan_client.xml

```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">


    <motan:referer id="remoteService" interface="quickstart.FooService" directUrl="localhost:8002"/>
</beans>
```

src/main/java/quickstart/Client.java

```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.

    ```java 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.

    ```xml org.codehaus.mojo build-helper-maven-plugin 1.10 generate-sources add-source

${project.build.directory}/generated-sources/annotations

                </sources>
            </configuration>
        </execution>
    </executions>
</plugin>
```
  1. Modify the attribute interface of referer in motan_client.xml from FooService to FooServiceAsync.

    xml <motan:referer id="remoteService" interface="quickstart.FooServiceAsync" directUrl="localhost:8002"/>

  2. Start asynchronous calls.

    ```java 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.

Extension points exported contracts — how you extend this code

ProviderB (Interface)
@author maijunsheng @version 创建时间:2013-6-18 [6 implementers]
motan-core/src/test/java/com/weibo/api/motan/transport/ProviderB.java
TracerFactory (Interface)
@Description TracerFactory @author zhanglei @date Dec 8, 2016 [6 implementers]
motan-extension/filter-extension/filter-opentracing/src/main/java/com/weibo/api/motan/filter/opentracing/TracerFactory.java
HttpMessageHandler (Interface)
@author zhanglei28 @date 2023/11/22. [14 implementers]
motan-transport-netty4/src/main/java/com/weibo/api/motan/transport/netty4/http/HttpMessageHandler.java
PbParamService (Interface)
Created by zhanglei28 on 2017/9/12. [9 implementers]
motan-demo/motan-demo-api/src/main/java/com/weibo/motan/demo/service/PbParamService.java
MeshTransport (Interface)
@author zhanglei28 @date 2021/6/28. 向mesh发送管理指令 [4 implementers]
motan-registry-weibomesh/src/main/java/com/weibo/api/motan/registry/weibomesh/MeshTransport.java
RestServer (Interface)
(no doc) [4 implementers]
motan-extension/protocol-extension/motan-protocol-restful/src/main/java/com/weibo/api/motan/protocol/restful/RestServer.java
RegistryService (Interface)
Created by Zhang Yu on 2015/11/2 0002. [2 implementers]
motan-manager/src/main/java/com/weibo/service/RegistryService.java
UserOrBuilder (Interface)
(no doc) [3 implementers]
motan-extension/serialization-extension/src/test/java/com/weibo/api/motan/serialize/protobuf/gen/UserProto.java

Core symbols most depended-on inside this repo

put
called by 596
motan-core/src/main/java/com/weibo/api/motan/protocol/v2motan/GrowableByteBuffer.java
getName
called by 567
motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/FeatureOrBuilder.java
add
called by 309
motan-demo/motan-demo-api/src/main/java/com/weibo/motan/demo/service/RestfulService.java
size
called by 307
motan-core/src/main/java/com/weibo/api/motan/util/ConcurrentHashSet.java
equals
called by 300
motan-core/src/test/java/com/weibo/api/motan/proxy/RefererInvocationHandlerTest.java
get
called by 289
motan-core/src/main/java/com/weibo/api/motan/protocol/v2motan/GrowableByteBuffer.java
call
called by 277
motan-core/src/main/java/com/weibo/api/motan/rpc/Caller.java
getUrl
called by 274
motan-core/src/main/java/com/weibo/api/motan/rpc/Node.java

Shape

Method 4,273
Function 1,181
Class 591
Interface 107
Enum 9

Languages

Java81%
TypeScript19%

Modules by API surface

motan-manager/src/main/resources/static/lib/angular/angular.js426 symbols
motan-extension/serialization-extension/src/test/java/com/weibo/api/motan/serialize/protobuf/gen/UserProto.java172 symbols
motan-manager/src/main/resources/static/lib/modules/angular-ui-grid/ui-grid.js123 symbols
motan-manager/src/main/resources/static/lib/angular/angular-ui-router/angular-ui-router.js98 symbols
motan-core/src/main/java/com/weibo/api/motan/config/AbstractInterfaceConfig.java81 symbols
motan-manager/src/main/resources/static/lib/modules/angular-daterangepicker/moment.js75 symbols
motan-manager/src/main/resources/static/lib/angular/angular-ui-bootstrap/ui-bootstrap.js75 symbols
motan-manager/src/main/resources/static/lib/jquery/jquery.min.js64 symbols
motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/Rectangle.java62 symbols
motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/FeatureDatabase.java60 symbols
motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/RouteNote.java58 symbols
motan-demo/motan-demo-api/src/main/java/io/grpc/examples/routeguide/Feature.java58 symbols

Dependencies from manifests, versioned

cglib:cglib-nodep2.2 · 1×
com.101tec:zkclient0.11 · 1×
com.alibaba:druid1.0.16 · 1×
com.caucho:hessian4.0.66 · 1×
com.codahale.metrics:metrics-core3.0.1 · 1×
com.ecwid.consul:consul-api1.3.0 · 1×
com.google.protobuf:protobuf-java3.16.3 · 1×
com.squareup:javapoet1.8.0 · 1×
com.sun.xml.bind:jaxb-core2.3.0 · 1×
com.sun.xml.bind:jaxb-impl2.3.0 · 1×

Datastores touched

(mysql)Database · 1 repos
motan-managerDatabase · 1 repos

For agents

$ claude mcp add motan \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact