A high-performance, open-source java RPC framework.
Mango is a high-performance, open-source java RPC framework.
The minimum requirements to run the quick start are:
Add dependencies to pom.
<dependency>
<groupId>com.mindflow</groupId>
<artifactId>mango-core</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>com.mindflow</groupId>
<artifactId>mango-registry-zk</artifactId>
<version>1.0.1</version>
</dependency>
<!-- dependencies blow were only needed for spring integrated -->
<dependency>
<groupId>com.mindflow</groupId>
<artifactId>mango-springsupport</artifactId>
<version>1.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>4.3.6</version>
</dependency>
Create an interface for both service provider and consumer.
public interface DemoService {
void hello(String msg);
String echo(String msg);
Map<String, String> introduce(String name, List<String> hobbies);
}
Write an implementation, create and start RPC Server.
```
@Service(“demoService”)
public class DemoServiceImpl implements DemoService {
@Override
public void hello(String msg) {
System.out.println(msg);
}
@Override
public String echo(String msg) {
return "hello, "+msg;
}
@Override
public Map
System.out.println("name:"+name + ", hobbies:"+hobbies);
Map<String, String> map = new HashMap<>();
map.put("name", name);
return map;
}
}
mango-server.xml
<?xml version=”1.0” encoding=”UTF-8”?>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="mango.demo"></context:component-scan>
<mango:application name="mango-server" ></mango:application>
<mango:protocol name="mango" port="21918"></mango:protocol>
<mango:registry protocol="zookeeper" address="localhost:2181"></mango:registry>
<!--export services-->
<mango:service interface="mango.demo.service.DemoService" ref="demoService" group="group1" version="1.0.0" ></mango:service>
<mango:service interface="mango.demo.service.UserService" ref="userService" version="1.0.0" ></mango:service>
ServerApp.java
public class ServerApp {
public static void main( String[] args ) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:mango-server.xml");
System.out.println("server start...");
}
}
4. Create and start RPC Client.
mango-client.xml
<?xml version=”1.0” encoding=”UTF-8”?>
<context:annotation-config></context:annotation-config>
<context:component-scan base-package="mango.demo.client"></context:component-scan>
<mango:application name="mango-client" ></mango:application>
<mango:protocol name="mango" port="21918"></mango:protocol>
<mango:registry protocol="zookeeper" address="localhost:2181"></mango:registry>
<!--refer services-->
<mango:reference id="demoService" interface="mango.demo.service.DemoService" group="group1" ></mango:reference>
<mango:reference id="userService" interface="mango.demo.service.UserService"></mango:reference>
ClientApp.java
public class ClientApp {
public static void main( String[] args ) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:mango-client.xml");
DemoService service = (DemoService) ctx.getBean("demoService");
service.hello("rpc");
System.out.println("echo:"+service.echo("rpc"));
List<String> hobbies = new ArrayList<>();
hobbies.add("NBA");
hobbies.add("Reading");
Map<String, String> map = service.introduce("hh", hobbies);
System.out.println("map:"+map);
}
}
```
In developing.