一 部署Motan运行环境
1 升级spring到4.2.4 Release
2 引入相关Motan的jar包
<!-- Motan start --> <dependency> <groupId>com.weibo</groupId> <artifactId>motan-core</artifactId> <version>${motan.version}</version> </dependency> <dependency> <groupId>com.weibo</groupId> <artifactId>motan-registry-zookeeper</artifactId> <version>${motan.version}</version> </dependency> <dependency> <groupId>com.weibo</groupId> <artifactId>motan-registry-consul</artifactId> <version>${motan.version}</version> </dependency> <dependency> <groupId>com.weibo</groupId> <artifactId>serialization-extension</artifactId> <version>${motan.version}</version> </dependency> <dependency> <groupId>com.weibo</groupId> <artifactId>motan-springsupport</artifactId> <version>${motan.version}</version> </dependency> <dependency> <groupId>com.weibo</groupId> <artifactId>motan-transport-netty</artifactId> <version>${motan.version}</version> </dependency> <!-- <dependency> <groupId>com.weibo</groupId> <artifactId>motan-protocol-yar</artifactId> <version>${motan.version}</version> </dependency> --> <dependency> <groupId>org.jboss.netty</groupId> <artifactId>netty</artifactId> <version>3.2.5.Final</version> </dependency> <!-- zookeeper start--> <dependency> <groupId>com.101tec</groupId> <artifactId>zkclient</artifactId> <version>${zkclient.version}</version> </dependency> <dependency> <groupId>log4j</groupId> <artifactId>log4j</artifactId> <version>${log4j.version}</version> </dependency> <dependency> <groupId>org.apache.zookeeper</groupId> <artifactId>zookeeper</artifactId> <version>3.4.8</version> </dependency> <!-- zookeeper end--> <dependency> <groupId>com.caucho</groupId> <artifactId>hessian</artifactId> <version>4.0.38</version> </dependency> <dependency> <groupId>com.codahale.metrics</groupId> <artifactId>metrics-core</artifactId> <version>3.0.2</version> </dependency> <!-- consul start--> <dependency> <groupId>com.ecwid.consul</groupId> <artifactId>consul-api</artifactId> <version>1.1.4</version> </dependency> <!-- consul end--> <!-- Motan end -->
二 单机版HelloWorld
创建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="helloServiceImpl" class="com.csair.csmbp.service.impl.DemoServiceImpl" />
<!-- 单机exporting service by Motan -->
<motan:service interface="com.csair.csmbp.service.DemoService" ref="helloServiceImpl" export="8002" />
</beans>
<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="helloServiceImpl" class="com.csair.csmbp.service.impl.DemoServiceImpl" />
<!-- 单机exporting service by Motan -->
<motan:service interface="com.csair.csmbp.service.DemoService" ref="helloServiceImpl" export="8002" />
</beans>
Server启动类:
package com.csair.csmbp.microServer; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import com.weibo.api.motan.common.MotanConstants; import com.weibo.api.motan.util.MotanSwitcherUtil; public class Server { public static void main(String[] args) throws InterruptedException { ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:motan_server.xml"); System.out.println("server start..."); MotanSwitcherUtil.setSwitcherValue(MotanConstants.REGISTRY_HEARTBEAT_SWITCHER, true); System.out.println("service registry..."); } }
创建motan_client:
写道
<?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="com.csair.csmbp.service.DemoService" directUrl="localhost:8002"/>
</beans>
<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="com.csair.csmbp.service.DemoService" directUrl="localhost:8002"/>
</beans>
创建client调用类
package com.csair.csmbp.service.impl; import org.springframework.context.ApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import com.csair.csmbp.service.DemoService; /** * Class description goes here. * * @author deanPhipray * @since 2015-3-2 */ @Transactional @Service(value="rpcDemoService") public class RpcDemoServiceImpl { public static void main(String[] args) throws InterruptedException { ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath:motan_client.xml"); DemoService service = (DemoService) ctx.getBean("remoteService"); System.out.println(service.rpcHelloWorld("motan")); } }
服务端和客户端都需要用户接口类
package com.csair.csmbp.service; import com.csair.csmbp.dao.DemoDao; import com.csair.csmbp.model.Demo; import com.csair.csmbp.service.base.BaseServcie; /** * 用户service * * @author DeanPhipray * */ public interface DemoService extends BaseServcie<Demo,DemoDao> { /** * * @param userId * @return */ public String rpcHelloWorld(String name); }
三 集群版HelloWorld
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="helloServiceImpl" class="com.csair.csmbp.service.impl.DemoServiceImpl" /> <!-- 集群exporting service by Motan --> <motan:registry regProtocol="zookeeper" name="my_zookeeper" address="10.108.68.140:2181,10.108.68.140:2182,10.108.68.140:2183"/> <motan:service interface="com.csair.csmbp.service.DemoService" ref="helloServiceImpl" registry="my_zookeeper" export="8002" /> </beans>
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:registry regProtocol="zookeeper" name="my_zookeeper" address="10.108.68.140:2181,10.108.68.140:2182,10.108.68.140:2183"/> <motan:referer id="remoteService" interface="com.csair.csmbp.service.DemoService" registry="my_zookeeper" requestTimeout="5000"/> </beans>
相关推荐
motan.xsd文件,解决motan框架和spring整合快捷键的烦恼
motan关联zoo+Java进行相关的配置 调用的实例 备份资源
motan.xsd 相关配置使用参考 https://blog.csdn.net/linuu/article/details/53115290
motan.xsd文件,解决motan框架和spring整合快捷键的烦恼
Motan 是一套高性能、易于使用的分布式远程服务调用(RPC)框架。目前是新浪微博的主要框架。
motan,用于快速开发高性能分布式服务的远程过程调用(rpc)框架。.zip
莫坦的例子 Motan使用有关交叉语言调用的示例。 每种语言的服务定义 ... HelloWorldService //用于...例如motan-go-example为Golang, motan-java-example的Java, motan-openresty-example用于openResty-Lua中, motan-se
Motan Overview Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services. Motan-go is golang implementation. Motan-...
Sprint Boot莫坦项目介绍基于spring boot motan整合的demo(支持初始化和同步初始化),motan配置信息放置在application.yml中,详细配置请参考官网此demo基于zookeeper注册中心,如果要直接启动,需要安装zookeeper...
Java分布式RPC服务框架教程,包括DubboDubbox,Motan,gRPC..zip
基于SpringBoot 2.0,SpringMVC,Mybatis,mybatis-plus,motan/dubbo分布式,Redis缓存,Shiro权限管理,redis管理Session,Quartz分布式集群调度,Restful服务;系统管理:包括用户管理、权限管理、数据字典、系统...
rpcx是一个类似阿里巴巴 Dubbo 和微博 Motan 的分布式的RPC服务框架,基于Golang net/rpc实现。 与gRPC比较,完胜gRPC, 更不用说其它的"老"的RPC框架了。
NULL 博文链接:https://softwarexiang120.iteye.com/blog/2339986
Motan是用于快速开发高性能分布式服务的跨语言远程过程调用(RPC)框架。 Motan生态系统中的相关项目: 是golang的实现。 是PHP客户端,可以直接或通过Motan-go代理与Motan服务器进行交互。 是基于的Lua(Luajit...
springboot框架 一、Spring Boot基础应用 Spring Boot特征 概念: 约定优于配置,简单来说就是你所期待的配置与约定的配置一致,那么就可以不做任何配置,约定不符合期待时才需要对约定进行替换配置。...
motan-openresty:基于OpenResty的跨语言RPC框架,用于快速开发高性能分布式服务
rpc-framework-tutorials Java分布式RPC服务框架教程,包括Dubbo / Dubbox,Motan,gRPC。达博阿里巴巴达 Alibaba 。沙发-RPC 支付宝 。莫坦微。gRPC Google 。英国广播公司百度节约阿夫罗芒果本人基于Netty4 + ...
pq-rpc-framework Java分布式RPC服务框架示例,包括 Dubbo/Dubbox, Motan, gRPC.
springcloud整合分布式事务框架TX-LCN
rpcx是一个类似阿里巴巴 Dubbo 和微博 Motan 的分布式的RPC服务框架,基于Golang ...2013 年微博 RPC 框架 Motan 在前辈大师们(福林、fishermen、小麦、王喆等)的精心设计和辛勤工作中诞生,向各位大师们致敬。