项目作者: TFdream

项目描述 :
A high-performance, open-source java RPC framework.
高级语言: Java
项目地址: git://github.com/TFdream/mango.git
创建时间: 2017-06-12T12:21:59Z
项目社区:https://github.com/TFdream/mango

开源协议:Apache License 2.0

下载


Mango

License Release Version Build Status

Overview

Mango is a high-performance, open-source java RPC framework.

Features

  • Supports various serialization protocol, like protostuff, Kryo, Hessian, msgpack, Jackson, Fastjson.
  • Supports advanced features like load-balance(random, Round-Robin), HA strategy(Failfast, Failover).
  • Supports service discovery services like ZooKeeper or Consul.
  • Supports oneway, synchronous or asynchronous invoking.
  • Supports SPI extension.
  • Easy integrated with Spring Framework 4.x.

Requirements

The minimum requirements to run the quick start are:

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

Quick Start

1. Synchronous calls

  1. Add dependencies to pom.

    1. <dependency>
    2. <groupId>com.mindflow</groupId>
    3. <artifactId>mango-core</artifactId>
    4. <version>1.0.1</version>
    5. </dependency>
    6. <dependency>
    7. <groupId>com.mindflow</groupId>
    8. <artifactId>mango-registry-zk</artifactId>
    9. <version>1.0.1</version>
    10. </dependency>
    11. <!-- dependencies blow were only needed for spring integrated -->
    12. <dependency>
    13. <groupId>com.mindflow</groupId>
    14. <artifactId>mango-springsupport</artifactId>
    15. <version>1.0.1</version>
    16. </dependency>
    17. <dependency>
    18. <groupId>org.springframework</groupId>
    19. <artifactId>spring-context</artifactId>
    20. <version>4.3.6</version>
    21. </dependency>
  2. Create an interface for both service provider and consumer.

    1. public interface DemoService {
    2. void hello(String msg);
    3. String echo(String msg);
    4. Map<String, String> introduce(String name, List<String> hobbies);
    5. }
  3. Write an implementation, create and start RPC Server.
    ```
    @Service(“demoService”)
    public class DemoServiceImpl implements DemoService {

    @Override
    public void hello(String msg) {

    1. System.out.println(msg);

    }

    @Override
    public String echo(String msg) {

    1. return "hello, "+msg;

    }

    @Override
    public Map introduce(String name, List hobbies) {

    1. System.out.println("name:"+name + ", hobbies:"+hobbies);
    2. Map<String, String> map = new HashMap<>();
    3. map.put("name", name);
    4. return map;

    }

}

  1. mango-server.xml

<?xml version=”1.0” encoding=”UTF-8”?>

  1. <context:annotation-config></context:annotation-config>
  2. <context:component-scan base-package="mango.demo"></context:component-scan>
  3. <mango:application name="mango-server" ></mango:application>
  4. <mango:protocol name="mango" port="21918"></mango:protocol>
  5. <mango:registry protocol="zookeeper" address="localhost:2181"></mango:registry>
  6. <!--export services-->
  7. <mango:service interface="mango.demo.service.DemoService" ref="demoService" group="group1" version="1.0.0" ></mango:service>
  8. <mango:service interface="mango.demo.service.UserService" ref="userService" version="1.0.0" ></mango:service>

  1. ServerApp.java

public class ServerApp {

  1. public static void main( String[] args ) {
  2. ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:mango-server.xml");
  3. System.out.println("server start...");
  4. }

}

  1. 4. Create and start RPC Client.
  2. mango-client.xml

<?xml version=”1.0” encoding=”UTF-8”?>

  1. <context:annotation-config></context:annotation-config>
  2. <context:component-scan base-package="mango.demo.client"></context:component-scan>
  3. <mango:application name="mango-client" ></mango:application>
  4. <mango:protocol name="mango" port="21918"></mango:protocol>
  5. <mango:registry protocol="zookeeper" address="localhost:2181"></mango:registry>
  6. <!--refer services-->
  7. <mango:reference id="demoService" interface="mango.demo.service.DemoService" group="group1" ></mango:reference>
  8. <mango:reference id="userService" interface="mango.demo.service.UserService"></mango:reference>

  1. ClientApp.java

public class ClientApp {

  1. public static void main( String[] args ) {
  2. ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:mango-client.xml");
  3. DemoService service = (DemoService) ctx.getBean("demoService");
  4. service.hello("rpc");
  5. System.out.println("echo:"+service.echo("rpc"));
  6. List<String> hobbies = new ArrayList<>();
  7. hobbies.add("NBA");
  8. hobbies.add("Reading");
  9. Map<String, String> map = service.introduce("hh", hobbies);
  10. System.out.println("map:"+map);
  11. }

}
```

2. Asynchronous calls

In developing.