Java使用RabbitMQ之整合Spring(生产者)
依赖包
<!--RabbitMQ集成spring-->
<!-- https://mvnrepository.com/artifact/org.springframework.amqp/spring-rabbit -->
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.0.6.RELEASE</version>
</dependency>
生产者Spring配置文件:
<?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:context="http://www.springframework.org/schema/context"
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/rabbit
http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd"> <!-- 连接服务配置 -->
<rabbit:connection-factory id="connectionFactory"
host="10.15.1.26" username="admin" password="admin" port="5672"
virtual-host="/test_host" channel-cache-size="5"/> <!--MQ的管理,包括队列、交换器的声明等-->
<rabbit:admin connection-factory="connectionFactory"/> <!-- queue 队列声明 -->
<rabbit:queue durable="true"
auto-delete="false" exclusive="false" name="test.spring.queue"/> <!-- exchange queue binging key 绑定 -->
<rabbit:direct-exchange name="spring.exchange"
durable="true" auto-delete="false">
<rabbit:bindings>
<rabbit:binding queue="test.spring.queue" key="spring.queue.key"/>
</rabbit:bindings>
</rabbit:direct-exchange> <!-- spring template声明 -->
<rabbit:template id="amqpTemplate" exchange="spring.exchange" routing-key="spring.queue.key"
connection-factory="connectionFactory"/> </beans>
生产者源码:
package org.study.spring5; import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; /**
* RabbitMQ与Spring整合
* 生产者
*/
public class SpringProducer { public static void main(String args[]) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring/producer-spring-config.xml");
//获取RabbitMQ模板
AmqpTemplate template = applicationContext.getBean(AmqpTemplate.class);
//发送消息
String msg = "Hello !";
template.convertAndSend(msg);
System.out.println("发送:" + msg);
}
}
Java使用RabbitMQ之整合Spring(生产者)的更多相关文章
- Java使用RabbitMQ之整合Spring(消费者)
依赖包: <!--RabbitMQ集成spring--> <!-- https://mvnrepository.com/artifact/org.springframework.am ...
- RabbitMQ学习笔记三:Java实现RabbitMQ之与Spring集成
搭建好maven项目环境,加入RabbitMQ依赖包 <dependency> <groupId>org.springframework.amqp</groupId> ...
- Maven整合Spring与Solr
首先,在maven的pom.xml文件中配置对spring和solrj客户端的依赖: <project xmlns="http://maven.apache.org/POM/4.0.0 ...
- 【深度分析】:阿里,腾讯面试题 SpringBoot整合Spring MVC
Java学习总结 SpringBoot整合Spring MVC 1.SpringMVC概述 MVC(Model–view–controller)是软件工程中的一种软件架构模式,基于此模式把软件系统分为 ...
- RabbitMQ入门到进阶(Spring整合RabbitMQ&SpringBoot整合RabbitMQ)
1.MQ简介 MQ 全称为 Message Queue,是在消息的传输过程中保存消息的容器.多用于分布式系统 之间进行通信. 2.为什么要用 MQ 1.流量消峰 没使用MQ 使用了MQ 2.应用解耦 ...
- JMS(java消息服务)整合Spring项目案例
转载自云栖社区 摘要: Sprng-jms消息服务小项目 所需的包: spring的基础包 spring-jms-xx包 spring-message–xx包 commons-collection-x ...
- Spring Kafka整合Spring Boot创建生产者客户端案例
每天学习一点点 编程PDF电子书.视频教程免费下载:http://www.shitanlife.com/code 创建一个kafka-producer-master的maven工程.整个项目结构如下: ...
- 【Java EE 学习 81】【CXF框架】【CXF整合Spring】
一.CXF简介 CXF是Apache公司下的项目,CXF=Celtix+Xfire:它支持soap1.1.soap1.2,而且能够和spring进行快速无缝整合. 另外jax-ws是Sun公司发布的一 ...
- Java WebService 教程系列之 Spring 整合 CXF
Java WebService 教程系列之 Spring 整合 CXF 一.引入 jar 包 <dependency> <groupId>org.apache.cxf</ ...
随机推荐
- 001_HTTP参数中Etag的重要性
在研究tornado时,有个Etag比较好奇,从网上查询摘录如下:
- 初学Python——列表生成式、生成器和迭代器
一.列表生成式 假如现在有这样一个需求:快速生成一个列表[1,2,3,4,5,6,7,8,9,10],该如何实现? 在不知道列表生成式的情况下,可能会这样写: a=[1,2,3,4,5,6,7,8,9 ...
- 蓝牙speaker配对流程源码分析
这篇文章简单分析一下 蓝牙音箱配对流程.现在的音箱基本都支持security simple pairing.所以这里的流程基本上就是ssp的代码流程. 源码参考的是 Android 6.0 上面的bl ...
- EntityFramework Core并发深挖详解,一纸长文,你准备好看完了吗?
前言 之前有关EF并发探讨过几次,但是呢,博主感觉还是有问题,为什么会觉得有问题,其实就是理解不够透彻罢了,于是在项目中都是用的存储过程或者SQL语句来实现,利用放假时间好好补补EF Core并发的问 ...
- Ubuntu 18.04 根目录为啥只有 4G 大小
其实准确点儿的描述应该是:Ubuntu Server 18.04 ,设置 LVM,安装完成后根目录的容量为什么只有 4G?只有 Server 版有问题,Desktop 版没有问题,Ubuntu 16. ...
- MemSQL与MySQL不兼容问题总结
1.数据行Update更新数据行时,如果数据行没有变化,MySQL返回受影响的数据行数为1,但MemSQL返回的数据行数为0. 2.MemSQL不支持唯一约束 3.MemSQL不支持外键约束
- 如何在C#中使用Dapper(译)
前言: 对象关系映射(ORM)已经被使用了很长时间,以解决在编程过程中对象模型与数据模型在关系数据库中不匹配的问题. Dapper是由Stack OverFlow团队开发的开源的,轻量级的ORM.相比 ...
- Linq中比较字符串类型的日期
一.在使用Linq时,想要比较字符串类型的日期时,参考以下: SQL语句: )select * from TableName where StartTime > '2015-04-08' )se ...
- java 接口实现防盗门功能
Door: package locker; public abstract class Door { public abstract void open(); public abstract void ...
- java 抽象
MotoVehicle抽象类 package text1; /* * 抽象 */ public abstract class MotoVehicle { // 共同的属性 private String ...