rabbitmq学习11:基于rabbitmq和spring-amqp的远程接口调用
2012-10-08 12:56
447 查看
RabbitMQ学习笔记;spring-amqp;接口调用
此远程接口调用是基于RPC的
先来看看提供暴露接口方法的配置
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="connectionFactory"
class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<constructor-arg value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<bean id="amqpAdmin"
class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="connectionFactory" />
</bean>
<bean id="rabbitTemplate"
class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<constructor-arg ref="connectionFactory"></constructor-arg>
</bean>
<bean id="testService" class="com.abin.test.TestServiceImpl"></bean>
<bean
class="org.springframework.amqp.rabbit.remoting.RabbitInvokerServiceExporter">
<property name="connectionFactory" ref="connectionFactory" />
<property name="serviceInterface"
value="com.abin.test.TestService" />
<property name="service" ref="testService" />
<property name="exchange" value="service_exhange" />
<property name="exchangeTypes" value="topic" />
<property name="routingKey" value="routing.example.service" />
<property name="queueName" value="incoming_queue_name" />
<property name="poolsize" value="5" />
</bean>
</beans>
RabbitInvokerServiceExporter类用于把接口services放到一个类型为“direct”的queue或者exchange中,并处理远程接口调用的回调。
远程调用配置如下:
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 创建connectionFactory -->
<bean id="connectionFactory"
class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<constructor-arg value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<!-- 创建rabbitAdmin 代理类 -->
<bean id="rabbitAdmin"
class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="connectionFactory" />
</bean>
<!-- 创建rabbitTemplate 消息模板类 -->
<bean id="rabbitTemplate"
class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<constructor-arg ref="connectionFactory"></constructor-arg>
</bean>
<bean id="testService"
class="org.springframework.amqp.rabbit.remoting.RabbitInvokerProxyFactoryBean">
<property name="connectionFactory" ref="connectionFactory" />
<property name="serviceInterface"
value="com.abin.test.TestService">
</property>
<property name="exchange" value="service_exhange" />
<property name="exchangeTypes" value="topic" />
<property name="routingKey" value="routing.example.service" />
</bean>
<bean id="testAction" class="com.abin.action.TestAction">
<property name="testService" ref="testService" />
</bean>
</beans>
RabbitInvokerProxyFactoryBean类通过拦截器方法调用在rabbitmq中已提供的远程接口信息。
上述用到的程序在附件中。还可以参考https://github.com/momania/spring-rabbitmq
此远程接口调用是基于RPC的
先来看看提供暴露接口方法的配置
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <bean id="connectionFactory"
class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<constructor-arg value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<bean id="amqpAdmin"
class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="connectionFactory" />
</bean>
<bean id="rabbitTemplate"
class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<constructor-arg ref="connectionFactory"></constructor-arg>
</bean>
<bean id="testService" class="com.abin.test.TestServiceImpl"></bean>
<bean
class="org.springframework.amqp.rabbit.remoting.RabbitInvokerServiceExporter">
<property name="connectionFactory" ref="connectionFactory" />
<property name="serviceInterface"
value="com.abin.test.TestService" />
<property name="service" ref="testService" />
<property name="exchange" value="service_exhange" />
<property name="exchangeTypes" value="topic" />
<property name="routingKey" value="routing.example.service" />
<property name="queueName" value="incoming_queue_name" />
<property name="poolsize" value="5" />
</bean>
</beans>
RabbitInvokerServiceExporter类用于把接口services放到一个类型为“direct”的queue或者exchange中,并处理远程接口调用的回调。
远程调用配置如下:
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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"> <!-- 创建connectionFactory -->
<bean id="connectionFactory"
class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory">
<constructor-arg value="localhost" />
<property name="username" value="guest" />
<property name="password" value="guest" />
</bean>
<!-- 创建rabbitAdmin 代理类 -->
<bean id="rabbitAdmin"
class="org.springframework.amqp.rabbit.core.RabbitAdmin">
<constructor-arg ref="connectionFactory" />
</bean>
<!-- 创建rabbitTemplate 消息模板类 -->
<bean id="rabbitTemplate"
class="org.springframework.amqp.rabbit.core.RabbitTemplate">
<constructor-arg ref="connectionFactory"></constructor-arg>
</bean>
<bean id="testService"
class="org.springframework.amqp.rabbit.remoting.RabbitInvokerProxyFactoryBean">
<property name="connectionFactory" ref="connectionFactory" />
<property name="serviceInterface"
value="com.abin.test.TestService">
</property>
<property name="exchange" value="service_exhange" />
<property name="exchangeTypes" value="topic" />
<property name="routingKey" value="routing.example.service" />
</bean>
<bean id="testAction" class="com.abin.action.TestAction">
<property name="testService" ref="testService" />
</bean>
</beans>
RabbitInvokerProxyFactoryBean类通过拦截器方法调用在rabbitmq中已提供的远程接口信息。
上述用到的程序在附件中。还可以参考https://github.com/momania/spring-rabbitmq
相关文章推荐
- rabbitmq学习11:基于rabbitmq和spring-amqp的远程接口调用
- RabbitMQ学习之基于spring-rabbitmq的RPC远程调用
- RabbitMQ学习之基于spring-rabbitmq的RPC远程调用
- RabbitMQ学习之基于spring-rabbitmq的RPC远程调用
- RabbitMQ学习之基于spring-rabbitmq的RPC远程调用
- 基于spring-cloud相关技术整合,实现接口调用、服务容错、动态路由配置等
- 一个简单基于RabbitMQ的RPC(远程调用模型)
- RMI远程方法调用示例【基于Spring配置文件】
- spring boot中用RabbitMQ调用接口
- 基于Spring注解的WebService接口,服务端编码与客户端调用
- 使用cxf框架搭建基于Spring远程调用Web服务
- RabbitMQ教程之php-amqplib(七)远程调用
- spring cloud使用Feign实现远程接口的调用
- RabbitMQ基于Spring AMQP的Java Config 简单配置实例
- 基于Spring的远程调用的实现
- spring cloud客户端远程调用服务端接口
- 基于两个项目 之间的RabbitMQ 发送和接收,并调用邮件接口,发送邮件
- Java 基于spring 暴露接口 供外部调用
- 服务调用RMI远程方法调用示例【基于Spring配置文件】
- 《Spring技术内幕》学习笔记18——Spring使用Hessian实现远程调用