Git Product home page Git Product logo

mango-1's Introduction

Mango

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.0</version>
    </dependency>

    <dependency>
        <groupId>com.mindflow</groupId>
        <artifactId>mango-registry-zk</artifactId>
        <version>1.0.0</version>
    </dependency>
    
    <!-- dependencies blow were only needed for spring integrated -->
    <dependency>
        <groupId>com.mindflow</groupId>
        <artifactId>mango-springsupport</artifactId>
        <version>1.0.0</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.

mango-1's People

Contributors

tfdream avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.