• Stars
    star
    156
  • Rank 239,589 (Top 5 %)
  • Language
    Java
  • License
    Apache License 2.0
  • Created over 7 years ago
  • Updated 12 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A high-performance, open-source java RPC framework.

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.
    <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>
  1. 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);
}
  1. 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<String, String> introduce(String name, List<String> hobbies) {
        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"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:mango="http://code.mindflow.com/schema/mango"
       xmlns:util="http://www.springframework.org/schema/util"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.mindflow.com/schema/mango http://code.mindflow.com/schema/mango/mango.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="mango.demo"/>

    <mango:application name="mango-server" />
    
    <mango:protocol name="mango" port="21918"/>

    <mango:registry protocol="zookeeper" address="localhost:2181"/>

    <!--export services-->
    <mango:service interface="mango.demo.service.DemoService" ref="demoService" group="group1" version="1.0.0" />
    <mango:service interface="mango.demo.service.UserService" ref="userService" version="1.0.0" />

</beans>

ServerApp.java

public class ServerApp {

    public static void main( String[] args ) {

        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:mango-server.xml");
        System.out.println("server start...");
    }
}
  1. Create and start RPC Client. mango-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:context="http://www.springframework.org/schema/context"
       xmlns:util="http://www.springframework.org/schema/util"
       xmlns:mango="http://code.mindflow.com/schema/mango"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://code.mindflow.com/schema/mango http://code.mindflow.com/schema/mango/mango.xsd
       http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd
       http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd">

    <context:annotation-config/>
    <context:component-scan base-package="mango.demo.client"/>

    <mango:application name="mango-client" />
    
    <mango:protocol name="mango" port="21918"/>

    <mango:registry protocol="zookeeper" address="localhost:2181"/>

    <!--refer services-->
    <mango:reference id="demoService" interface="mango.demo.service.DemoService" group="group1" />
    <mango:reference id="userService" interface="mango.demo.service.UserService"/>

</beans>

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);
    }
}

2. Asynchronous calls

In developing.

More Repositories

1

awesome-backend-architecture

后端开发常用技术框架、数据库、开源中间件、微服务、系统架构集合。
144
star
2

blog

个人技术博客,博文写在 Issues 里。
129
star
3

rpc-framework-tutorials

Java分布式RPC服务框架教程,包括 Dubbo/Dubbox, Motan, gRPC.
Java
111
star
4

py4j

A opensource Java library for converting Chinese to Pinyin.
Java
51
star
5

cherry

A flexible, stable, easy-to-use plugin Framework for Java applications.
Java
46
star
6

juice

Java后端开发库,涵盖:常用工具类、SPI扩展、分布式锁、限流、分布式链路追踪等。
Java
38
star
7

job-schedule-tutorials

分布式任务调度框架教程, 包括: Quartz、Elastic-Job和TBSchedule.
Java
31
star
8

spring-boot-tutorials

Spring Boot Tutorials.
Java
23
star
9

netty-learning

Netty 4.x tutorials.
Java
19
star
10

zookeeper-in-action

ZooKeeper 3.4.x practice code with Apache Curator .
Java
9
star
11

daily-codelab

personal codelab.
Java
8
star
12

mq-learning

Kafka, RabbitMQ, RocketMQ learning.
Java
7
star
13

hbase-tutorials

HBase 1.2 tutorials
Java
7
star
14

system-design-notes

涵盖各类系统设计案例,并结合实际应用场景手把手教你快速入门,内附源码!
Java
6
star
15

spring4-tutorials

Spring 4.x tutorials.
Java
4
star
16

Elasticsearch-learning

Elasticsearch核心技术与实战 学习笔记。
3
star
17

lucene-analyzer-ik

IK analyzer plugin integrates with lucene5.x and solr 5.x , support customized dictionary.
Java
3
star
18

springmvc-tutorials

SpringMVC 4.x tutorials
Java
3
star
19

interview-notes

后端面试指南。
2
star
20

backend-snippet

common code snippets for backend development needs.
2
star
21

FileDownloader

File download library for Java and Android.
Java
2
star
22

golang-learning

Learning Golang.
1
star
23

java8-snippet

Java8 有用代码片段。
1
star
24

spring-cloud-tutorials

Spring Cloud tutorials.
Java
1
star
25

okurl

A light-weight HTTP client for Android and Java applications.
Java
1
star
26

okmail

An Email client for Java applications.
Java
1
star
27

design-patterns

📚 23种设计模式全归纳(附Java代码示例)
Java
1
star