上一篇贴出了发送信息的配置,这一篇看看接受信息的配置
applicationContext-receive.xml配置如下:
上篇中将消息发送到了名称为simpleSend的队列上,所以这里amqpTemplate中的queue定义为simpleSend,另外不管是发送消息还是接受消息都需要声明队列<rabbit:queue name="simpleSend" />
<?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:aop="http://www.springframework.org/schema/aop" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:rabbit="http://www.springframework.org/schema/rabbit" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.4.xsd"> <rabbit:connection-factory id="connectionFactory" host="192.168.1.175" port="5672" channel-cache-size="25" /> <rabbit:template id="amqpTemplate" connection-factory="connectionFactory" queue="simpleSend"/> <rabbit:admin connection-factory="connectionFactory" /> <rabbit:queue name="simpleSend" /> <!-- <rabbit:listener-container connection-factory="connectionFactory"> <rabbit:listener ref="foo" method="listen" queue-names="simpleSend" /> </rabbit:listener-container> <bean id="foo" class="io.github.itnaxi.amqp.Foo" /> --> </beans>
接下来写测试案例HomeControllerReceiveTest:
import io.github.itnaxi.amqp.AbstractConfig; import javax.annotation.Resource; import org.apache.log4j.Logger; import org.junit.Test; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(locations={"/springMVC.xml","/receive/applicationContext-receive.xml"}) public class HomeControllerReceiveTest extends AbstractConfig{ private final Logger log=Logger.getLogger(HomeControllerReceiveTest.class); @Resource private RabbitTemplate rabbitTemplate; @Test public void testReceive() { log.info(rabbitTemplate.receiveAndConvert().toString()); } } 执行testReceive可以看到控制台输出如下: foo 表示接收成功
相关推荐
NULL 博文链接:https://wubin850219.iteye.com/blog/1050328
使用spring amqp与rabbitmq实现的消息发送和接收。
RabbitMQ是一套开源的消息队列服务软件 是由LShift提供的一个AMQP的开源实现 由以高性能 健壮以及可伸缩性出名的Erlang写成 具有很高的稳定性和可靠性 二、使用 1、准备和配置 首先是引入RabbitMQ的依赖 若使用...
spring-amqp-logback/log4jBest practice for logging with AMQP+LOGBACK/log4j (使用Rabbitmq+logback/log4j来中心化存储你的业务日志)包含 日志发布端(logback and log4j) 和 日志接收端 两个最佳实践例子。...
SpringAMQP为高级消息队列协议提供了类似的功能集。SpringBoot还为RabbitTemplate和RabbitMQ提供自动配置选项。SpringWebSocket本身包含对STOMP消息传递的支持,SpringBoot通过启动器和少量自动配置支持它。...
mq-client一个简单的基于Java的消息队列MQ客户端,封装了基于JMS的ActiveMQ和基于AMQP的RabbitMQ技术栈Spring JmsTemplateSpring AMQP使用可以直接作为消息发送接收模块集成到主项目中使用
与SpringAMQP完美的整合,API丰富 具有丰富的模式,表达式配置,HA模式,纳入规模模式 保证数据不丢失的情况下,做到高可用 AMQP全称:高级消息队列协议 AMQP翻译:高级消息子系统协议 1.2,AMQP核心概念 服务器:又...
1、提交代码触发post请求给bus/refresh 2、server端接收到请求并发送给Spring Cloud Bus 3、Spring Cloud bus接到消息并通知给其它客户端 4、其它客户端接收到通知,请求Server端获取最新配置 5、全部客户端均获取到...
RabbitMQ SpringBoot入门基本网址: : 兔子MQ 安装并启动服务器 使用命令“ rabbitmq-server”启动服务器,然后使用来宾/来宾启动 或添加用户 使用Spring Boot 了解AMQP结构在/ config中queue()方法创建一个AMQP...
目标是提供一个值得信赖的驱动程序,用于发送/接收消息以测试依赖于 AMQP 的接口(并且真正的服务器不可用)。 这意味着许多操作不可用,嵌入式服务器不符合 AMQ 规范,但将充分支持客户端 api。 此版本支持: ...
使用者使用者是一种从消息代理接收消息并处理这些消息的软件。 在我们的示例中,这可能是订单服务,需要所有客户的地址才能为这些客户创建订单。 它将通过从事件中读取ID并调用客户服务以加载相应客户的地址来处理...