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表即可.面试官不是很满意,提出: 用定时任务无法做到准实时 ...
随机推荐
- CF1009F Dominant Indices
传送门 还是放个链接让泥萌去学一下把 orzYYB 题目中要求的\(f_{x,j}\),转移是\(f_{x,j}=\sum_{y=son_x} f_{y,j-1}\),所以这个东西可以用长链剖分优化, ...
- webstorm11.0.3连接ftp
一.工具 webstorm11.0.3 ftp工具:Beyond Compare 3 二.步骤 1.打开项目工程,按照下图中路径,打开ftp配置界面 2.在ftp配置界面 (1)右上角+号新建配置,选 ...
- KEYCODE_DPAD_CENTER 和 KEYCODE_ENTER
KEYCODE_DPAD_CENTER或者是KEYCODE_ENTER时,会在view优先处理isConfirmKey,而在activity中的onKeyDown和up中接收不到该按键消息
- web前端最全各类资源
链接:http://www.sohu.com/a/157593700_132276
- 矩阵的SVD分解
转自 http://blog.csdn.net/zhongkejingwang/article/details/43053513(实在受不了CSDN的广告) 在网上看到有很多文章介绍SVD的,讲的也都 ...
- 【逆向工具】使用x64dbg+spy去除WinRAR5.40(64位)广告弹框
1 学习目标 WinRAR5.40(64位)的弹框广告去除,由于我的系统为x64版本,所以安装了WinRAR(x64)版本. OD无法调试64位的程序,可以让我熟悉x64dbg进行调试的界面. 其次是 ...
- MySQL— 索引
目录 一.索引 二.索引类型 三.索引种类 四.操作索引 五.创建索引的时机 六.命中索引 七.其它注意事项 八.LIMIT分页 九.执行计划 十.慢查询日志 一.索引 MySQL索引的建立对于MyS ...
- Ubuntu 16.04配置国内高速apt-get更新源【转】
转自:https://blog.csdn.net/twang0x80/article/details/79782753 Ubuntu 16.04下载软件速度有点慢,因为默认的是从国外下载软件,那就更换 ...
- C++:explicit关键字
在C++中,如果一个类的构造函数只有一个形参,在这种情况下,可以直接将一个对应于构造函数参数类型的数据直接赋值给类变量,编译器在编译时会自动进行类型转换,将对应于构造函数参数类型的数据转换为类的对象, ...
- 002_mtr_a network diagnostic tool
一. mtr combines the functionality of the traceroute and ping programs in a single network diagnostic ...