这边文章将偏实战, 至于motan,可以去了解如何实现、比普通的http请求的优越之处等
这里贴出应用motan的代码
Client端
ClassPathXmlApplicationContext ctx= new ClassPathXmlApplicationContext("classpath:motan_client.xml");
NaturalRankingService naturalRankingService = ctx.getBean(NaturalRankingService.class);
NaturalResponse naturalResponse = naturalRankingService.recommend(recommendRequest);
client端配置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">
<!-- 配置注册中心,客户端与服务端使用相同的配置中心
-->
<motan:registry regProtocol="zookeeper" name="client_zookeeper" address="172.0.0.1:2181,172.0.0.2:2181,172.0.0.3:2181"/>
<!--codec,serialization一定要跟服务端配置的保持一致,否则无法正常调用 -->
<motan:protocol id="client_protocol" default="false" name="motan" codec="motan2" serialization="fastjson"
requestTimeout="1000" maxContentLength="2048576"
maxClientConnection="300" minClientConnection="100" loadbalance="roundrobin"/>
<!-- mock测试: filter="statistic,mock" check="true" directUrl="127.0.0.1:8002" mock="true" -->
<motan:basicReferer registry="client_zookeeper"
group="ads-ranking-natural" accessLog="false" shareChannel="false"
id="clientBasicConfig"
filter="statistic"
/>
<!-- reference to the remote service directUrl="localhost:8002" -->
<motan:referer id="NaturalRankingService" interface="com.zz.common.interfaces.NaturalRankingService"
basicReferer="clientBasicConfig"
/>
</beans>
jar包中的接口service
public interface NaturalRankingService {
public NaturalResponse recommend(RecommendRequest request) ;
}
jar包依赖
<dependencies>
<!-- dependencies blow were only needed for motan-based features -->
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-core</artifactId>
<version>${motanVersion}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-transport-netty</artifactId>
<version>${motanVersion}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-springsupport</artifactId>
<version>${motanVersion}</version>
</dependency>
<dependency>
<groupId>com.weibo</groupId>
<artifactId>motan-registry-zookeeper</artifactId>
<version>RELEASE</version>
</dependency>
<!-- dependencies blow were only needed for spring-based features -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${spring.version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${slf4jVersion}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4jVersion}</version>
</dependency>
</dependencies>
server端实现 server端也加入上面的jar
public class NaturalRankinServicegImpl implements NaturalRankingService {
@Override
public NaturalResponse recommend(RecommendRequest request) {
//实现代码
return null;
}
}
server端的配置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">
<!-- 配置注册中心,客户端与服务端使用相同的配置中心
-->
<motan:registry regProtocol="zookeeper" name="server_zookeeper" address="172.0.0.1:2181,172.0.0.2:2181,172.0.0.3:2181"/>
<!-- 协议配置。为防止多个业务配置冲突,推荐使用id表示具体协议。serialization="kryo" codec="compressMotan"-->
<motan:protocol id="server_protocol" default="false" name="motan" codec="motan2" serialization="fastjson"
requestTimeout="1000" maxServerConnection="8000" maxContentLength="2048576"
maxWorkerThread="300" minWorkerThread="100" />
<!-- service implemention bean -->
<bean id="NaturalRankinServicegImpl" class="io.batcloud.service.impl.NaturalRankinServicegImpl" />
<!-- exporting service by motan -->
<motan:basicService requestTimeout="1000" export="server_protocol:8102" registry="server_zookeeper"
group="ads-ranking-natural" accessLog="false" shareChannel="false"
id="serviceBasicConfig" filter="statistic"/>
<motan:service interface="com.zz.common.interfaces.NaturalRankingService" ref= "NaturalRankinServicegImpl" basicService="serviceBasicConfig" />
</beans>
这样便完成了motan RPC的调用应用, 当然中间还有 服务注册中心zookeeper的应用
分享到:
相关推荐
rpcx是一个类似阿里巴巴 Dubbo 和微博 Motan 的分布式的RPC服务框架,基于Golang net/rpc实现。 谈起分布式的RPC框架,比较出名的是阿里巴巴的dubbo,包括由当当网维护的dubbox。 不知道dubbo在阿里的内部竞争中败给...
motan,用于快速开发高性能分布式服务的远程过程调用(rpc)框架。.zip
Motan 是一套高性能、易于使用的分布式远程服务调用(RPC)框架。目前是新浪微博的主要框架。
Motan是用于快速开发高性能分布式服务的跨语言远程过程调用(RPC)框架。 Motan生态系统中的相关项目: 是golang的实现。 是PHP客户端,可以直接或通过Motan-go代理与Motan服务器进行交互。 是基于的Lua(Luajit...
基于dubbo实现的rpc框架RPC 框架指的是:可以让客户端直接调用服务端方法就像调用本地方法一样简单的框架,比如我前面介绍的 Dubbo、Motan、gRPC 这些.zip
基于dubbo实现的rpc框架RPC 框架指的是:可以让客户端直接调用服务端方法就像调用本地方法一样简单的框架,比如我前面介绍的 Dubbo、Motan、gRPC 这些.zip
市面上常见的RPC框架很多,grpc,motan,dubbo等,但是随着越来越多的元素加入,复杂的架构设计等因素似使得这些框架和spring一样,虽然号称是轻量级,但是用起来却是让我们很蹩脚,大量的配置,繁杂的API设计,其实...
这个是java的jboot远程调用的内容,在使用的时候得有consul和motan安装好并且运行。
分布式服务/框架 ...多种RPC : 支持 Dubbo, SpringCloud,Motan, Sofa-rpc, brpc, tars 等知名RPC框架 日志存储 : 支持 mysql, oracle, mongodb, redis, zookeeper 等方式 复杂场景 : 支持RPC嵌套调用事务
1:为什么要写这个RPC市面上常见的RPC框架很多,grpc,motan,dubbo等,但是随着越来越多的元素加入,复杂的架构设计等因素似使得这些框架和spring一样,虽然号称是轻量级,但是用起来却是让我们很蹩脚,大量的配置...
Eagle是一个分布式的RPC框架,支持灵活的配置,支持分布式追踪,支持、、 等序列化协议,默认序列化使用kryo 。提供Spring 和SpringBoot插件,方便与Spring和SpringBoot集成。 特点 借助实现服务注册和发现。 分布式...
项目名称 ...支持Spring Boot Starter,也支持Spring Cloud的服务注册发现,使用brpc-java替换Feign HTTP调用,提升性能。 支持服务器推送机制,并支持扩展服务器推送协议。 支持多种命名服务,例如Zookee
5、RPC远程调用 motan dubbo grpc zbus 6、MQ消息队列 rabbitmq redismq 阿里云商业MQ activemq zbus 7、缓存 ehcache redis 分布式二级缓存ehredis 8、分布式session 9、分布式锁 10、任务...
Pepper Metrics Project Overview Pepper Metrics基于理论,即...对Motan/Dubbo的RPC调用进行性能分析(支持调用方及服务方) 对多种时序数据库数据源的支持,目前默认为Prometheus 开箱即用的Grafana Dashboard,方便
产品特点-易于使用:游戏开发需要将基本组件和服务集成并直接调用。 对熟悉柚子的人特别友好。 -组件化:将功能分为多个组件,并根据需要加载。 -分布式:它可以部署在多个节点中或作为一个过程打包在一起。 -微服务...
各种RPC:支持Dubbo , SpringCloud , Motan , Sofa-rpc , brpc , tars和其它公知的RPC框架 日志存储:支持mysql , oracle , mongodb , redis , zookeeper等。 复杂场景:支持RPC嵌套调用事务 必要前提 ...
多种RPC:支持 Dubbo,SpringCloud,Motan,Sofa-rpc,brpc,tars 等知名RPC框架 日志存储:支持 mysql,oracle,mongodb,redis,zookeeper 等方式 复杂场景:支持RPC嵌套调用事务 必要前提: 必须使用 JDK8+ TCC...
rpcx-java的无需维护:目前没有资源维护这个项目。欢迎有时间的开发者接手。... String ( "addr" , "192.168.31.82:8997" , "server address" ))type Echo intfunc ( t * Echo ) Echo ( ctx context....