Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/microcmpt/msa-rpc4j
Lightweight RPC communication framework based on netty and protostuff.
https://github.com/microcmpt/msa-rpc4j
msa-regcovery netty protostuff spring spring-boot zookeeper
Last synced: 25 days ago
JSON representation
Lightweight RPC communication framework based on netty and protostuff.
- Host: GitHub
- URL: https://github.com/microcmpt/msa-rpc4j
- Owner: microcmpt
- License: apache-2.0
- Created: 2018-05-13T02:26:31.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2018-06-01T03:29:07.000Z (over 6 years ago)
- Last Synced: 2024-09-28T16:41:53.528Z (about 1 month ago)
- Topics: msa-regcovery, netty, protostuff, spring, spring-boot, zookeeper
- Language: Java
- Homepage: https://github.com/msa-component/msa-rpc4j
- Size: 65.4 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# msa-rpc4j
[![Build Status](https://travis-ci.org/microcmpt/msa-rpc4j.svg?branch=master)](https://travis-ci.org/microcmpt/msa-rpc4j) [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)
### Introduction
msa-rpc4j是一款轻量级rpc nio通讯框架,底层通讯采用了netty nio通讯框架,rpc调用速度更快,序列化采用protostuff,序列化速度性能更优,为了保持高可用,采用zookeeper作为
服务注册中心,所以msa-rpc4j是一款具有高性能、高可用的通讯框架。
### Quick Start
##### 服务端
##### step1:引入msa-rpc4j-server
maven:
```$xsltcom.github.microcmpt
msa-rpc-server
1.0.1```
gradle:
```$xslt
compile group: 'com.github.microcmpt', name: 'msa-rpc-server', version: '1.0.1'
```
##### step2:定义一个服务端接口HelloRpc4jService
```
public interface HelloRpc4jService {
/**
* Hello string.
*
* @param str the str
* @return the string
*/
String hello(String str);
}
```
##### step3:实现服务端业务逻辑HelloRpc4jServiceImpl类
```
@RpcService(value = HelloRpc4jService.class)
public class HelloRpc4jServiceImpl implements HelloRpc4jService {
/**
* Hello string.
*
* @param str the str
* @return the string
*/
public String hello(String str) {
return "Hello, " + str;
}
}
```
##### 消费端
##### step1:引入msa-rpc-client
maven:
```$xsltcom.github.microcmpt
msa-rpc-client
1.0.1```
gradle:
```$xslt
compile group: 'com.github.microcmpt', name: 'msa-rpc-client', version: '1.0.1'
```
##### step2:配置RpcClientFactory
```
ZkServiceDiscovery discovery = new ZkServiceDiscovery();
discovery.setZkAddress("localhost:2181");
RpcClient client = new RpcClient(discovery);
RpcClientFactory factory = new RpcClientFactory(new DefaultInvocationProxy(rpcClient));
```
##### step3:通过RpcClientFactory实例创建HelloRpc4jService代理类
```
HelloRpc4jService client = factory.newClient(HelloRpc4jService.class);
String resp = client.hello("rpc4j");
System.out.println("返回结果:" + resp);
```
### Annotation
#### @RpcService
@RpcService用于标记该服务为暴露出去的API服务,服务端启动时自动注册到注册中心