GithubHelp home page GithubHelp logo

realforce1024 / motan Goto Github PK

View Code? Open in Web Editor NEW

This project forked from weibocom/motan

0.0 1.0 0.0 3.62 MB

A remote procedure call(RPC) framework for rapid development of high performance distributed services.

License: Other

Java 86.44% Shell 0.14% JavaScript 4.27% CSS 6.29% HTML 2.85%

motan's Introduction

Motan

License ![Maven Central](https://img.shields.io/maven-central/v/com.weibo/motan.svg?label=Maven Central) Build Status

Overview

Motan is a remote procedure call(RPC) framework for rapid development of high performance distributed services.

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.

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.7 or above
  • A java-based project management software like Maven or Gradle
  1. Add dependencies to pom.

     <dependency>
         <groupId>com.weibo</groupId>
         <artifactId>motan-core</artifactId>
         <version>0.1.1</version>
     </dependency>
     <dependency>
         <groupId>com.weibo</groupId>
         <artifactId>motan-transport-netty</artifactId>
         <version>0.1.1</version>
     </dependency>
     
     <!-- dependencies blow were only needed for spring-based features -->
     <dependency>
         <groupId>com.weibo</groupId>
         <artifactId>motan-springsupport</artifactId>
         <version>0.1.1</version>
     </dependency>
     <dependency>
         <groupId>org.springframework</groupId>
         <artifactId>spring-context</artifactId>
         <version>4.2.4.RELEASE</version>
     </dependency>
  2. Create an interface for both service provider and consumer.

    src/main/java/quickstart/FooService.java

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

    src/main/java/quickstart/FooServiceImpl.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 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">
    
        <!-- service implemention bean -->
        <bean id="serviceImpl" class="quickstart.FooServiceImpl" />
        <!-- exporting service by motan -->
        <motan:service interface="quickstart.FooService" ref="serviceImpl" export="8002" />
    </beans>

    src/main/java/quickstart/Server.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.

  4. Create and start RPC Client.

    src/main/resources/motan_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: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">
    
        <!-- reference to the remote service -->
        <motan:referer id="remoteService" interface="quickstart.FooService" directUrl="localhost:8002"/>
    </beans>

    src/main/java/quickstart/Client.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.

Documents

Contributors

License

Motan is released under the Apache License 2.0.

motan's People

Contributors

fingki avatar guanly avatar half-dead avatar qdaxb avatar radarhere avatar rayzhang0603 avatar sumory avatar tangdi avatar wenqisun avatar zyseap 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.