spring继承Rabbitmq client-----------------------待研究
一:概述
1.官网
https://spring.io/
2.进入project

3.找到spring AMQP

二:程序
1.结构

2.pom
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion> <groupId>SpringRabbitmq</groupId>
<artifactId>mq</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- https://mvnrepository.com/artifact/com.rabbitmq/amqp-client -->
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.6.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.10</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.7.5</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/log4j/log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit</artifactId>
<version>2.0.2.RELEASE</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework/spring-context -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.3.RELEASE</version>
</dependency> </dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
3.Java
package spring; import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.context.support.GenericXmlApplicationContext; public class SpringMain {
public static void main(String[] args)throws Exception{
ApplicationContext context = new GenericXmlApplicationContext("classpath:rabbit-context.xml");
//RabbitMq模板
RabbitTemplate template=context.getBean(RabbitTemplate.class);
//发送消息
template.convertAndSend("spring.MyConsumer");
Thread.sleep(2000); }
}
4.Java
package spring;
public class MyConsumer {
public void listen(String foo) {
System.out.println("消费者:"+foo);
}
}
5.rabbit-context.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: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/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.7.xsd">
<!-- 定义MQ工厂-->
<rabbit:connection-factory id="connectionFactory"
host="127.0.0.1" port="5672" virtual-host="/cjhost"
username="caojun" password="123456"/>
<!-- 定义MQ模板,指定要连接的工厂以及交换机-->
<rabbit:template id="amqpTemplate"
connection-factory="connectionFactory"
exchange="myExchange"/>
<!-- MQ管理,包括队列,交换机声明等-->
<rabbit:admin connection-factory="connectionFactory" />
<!--定义队列-->
<rabbit:queue name="myQueue" auto-declare="true" durable="true" />
<!--定义交换机-->
<rabbit:topic-exchange name="myExchange" auto-declare="true">
<rabbit:bindings>
<rabbit:binding queue="myQueue" pattern="foo.*" />
</rabbit:bindings>
</rabbit:topic-exchange> <!--队列监听-->
<rabbit:listener-container connection-factory="connectionFactory">
<rabbit:listener ref="foo" method="listen" queue-names="myQueue" />
</rabbit:listener-container> <bean id="foo" class="spring.MyConsumer" />
</beans>
·
spring继承Rabbitmq client-----------------------待研究的更多相关文章
- 从头开始搭建一个Spring boot+RabbitMQ环境
*:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...
- Spring boot+RabbitMQ环境
Spring boot+RabbitMQ环境 消息队列在目前分布式系统下具备非常重要的地位,如下的场景是比较适合消息队列的: 跨系统的调用,异步性质的调用最佳. 高并发问题,利用队列串行特点. 订阅模 ...
- 五.Spring与RabbitMQ集成--HelloWorld
spring对RabbitMQ做了很好的集成,我们称之为spring AMQP,其官方文档写得十分详尽,文档地址:https://docs.spring.io/spring-amqp/referenc ...
- Caused by: com.rabbitmq.client.ShutdownSignalException: connection error
周五下午的时候升级了一个环境,跑了批处理sh升级脚本后,启动时报下列错误: INFO | jvm 1 | 2017/02/24 17:39:09 | java.io.IOException INFO ...
- 六.Spring与RabbitMQ集成--HelloWorld
spring对RabbitMQ做了很好的集成,我们称之为spring AMQP,其官方文档写得十分详尽,文档地址:https://docs.spring.io/spring-amqp/referenc ...
- RabbitMQ.Client API (.NET)中文文档
主要的名称空间,接口和类 核心API中定义接口和类 RabbitMQ.Client 名称空间: 1 using RabbitMQ.Client; 核心API接口和类 IModel :表示一个AMQP ...
- 170613、Spring整合RabbitMQ实例
一.rabbitMQ简介 1.1.rabbitMQ的优点(适用范围)1. 基于erlang语言开发具有高可用高并发的优点,适合集群服务器.2. 健壮.稳定.易用.跨平台.支持多种语言.文档齐全.3. ...
- spring boot rabbitmq 多MQ配置 自动 创建 队列 RPC
源码地址:https://github.com/hutuchong518/RabbitmqStudy 需求: spring boot 整合 rabbitmq rpc功能, 需要将 请求和响应 ...
- Spring Boot RabbitMQ 延迟消息实现完整版
概述 曾经去网易面试的时候,面试官问了我一个问题,说 下完订单后,如果用户未支付,需要取消订单,可以怎么做 我当时的回答是,用定时任务扫描DB表即可.面试官不是很满意,提出: 用定时任务无法做到准实时 ...
随机推荐
- div 只显示两行超出部分隐藏
; -webkit-box-orient: vertical;line-height: 26px } <td rowspan="2" colspan="2" ...
- cdn.dns,cms
CDN CDN的全称是Content Delivery Network,即内容分发网络.其基本思路是尽可能避开互联网上有可能影响数据传输速度和稳定性的瓶颈和环节,使内容传输的更快.更稳定.通过在网络各 ...
- vue学习一:新建或打开vue项目(vue-cli2)
vue-cli3的操作参考文章:vue/cli 3.0脚手架搭建,浅谈vue-cli 3 和 vue-cli 2的区别 1.前期准备: node.js环境,安装node npm或者cnpm(npm的淘 ...
- Vue.js用脚手架创建项目
安装全局脚手架 cnpm install vue-cli -g vue --version 用脚手架创建项目 创建项目 运行项目 停止项目:Ctrl+C 修改端口 config - index.js ...
- OLAP和OLTP的区别(基础知识) 【转】
联机分析处理 (OLAP) 的概念最早是由关系数据库之父E.F.Codd于1993年提出的,他同时提出了关于OLAP的12条准则.OLAP的提出引起了很大的反响,OLAP作为一类产品同联机事务处理 ( ...
- Node 7.6默认支持Async/Await
Node.js 7.6正式默认支持async/await功能,并能够使低内存设备获得更出色的性能. Node 7.6对async/await的支持来自于将V8(Chromium JavaScript引 ...
- 支付宝&微信统一支付
1.实体对应关系: Application — 支付记录实体 -- 支付记录详情 2.流程 1.生成订单选择支付类型 2.支付宝:PC端.手机端.扫码:微信:微信公众号支付.扫码支付.H5支付. ...
- Oracle查询表主键、外键
项目中用到的一些Sql(oracle下的)总结: 1.查找表的所有索引(包括索引名,类型,构成列) select t.*,i.index_type from user_ind_columns t,us ...
- js常用函数整理
类型转换:parseInt\parseFloat\toString 类型判断:typeof;eg:if(typeof(var)!="undefined")\isNaN 字符处理函数 ...
- php数据类型之自动转换和强制转换
PHP在PHP 5.x阶段都是完全的弱类型的编程语言.所谓弱类型,就是在声明变量的时候,不需要指定变量的类型.我要声明一个整型的变量,我不用在前面非得写上类型,再写变量.而PHP 7 的性能有很大的提 ...