RMQ Direct
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11792398.html
RMQ Direct
Project Directory
Maven Dependency
<?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>org.fool.rmq</groupId>
<artifactId>rmq</artifactId>
<version>1.0-SNAPSHOT</version> <parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.0.RELEASE</version>
</parent> <dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency> <dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies> <build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
application.properties
spring.application.name=rmq
server.port= spring.rabbitmq.host=localhost
spring.rabbitmq.port=
spring.rabbitmq.username=admin
spring.rabbitmq.password=admin rmq.config.exchange=log.direct
rmq.config.queue.info=log.info
rmq.config.queue.info.routing.key=log.info.routing.key
rmq.config.queue.error=log.error
rmq.config.queue.error.routing.key=log.error.routing.key
Source Code
Application.java
package org.fool.rmq; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication; @SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
RmqConfig.java
package org.fool.rmq.config; import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; @Configuration
public class RmqConfig { @Bean
public Queue queue() {
return new Queue("hello-rmq");
}
}
LogProducer.java
package org.fool.rmq.direct; import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component; import java.util.Date; @Component
public class LogProducer {
@Autowired
private AmqpTemplate rmqTemplate; @Value("${rmq.config.exchange}")
private String exchange; @Value("${rmq.config.queue.info.routing.key}")
private String infoRoutingKey; @Value("${rmq.config.queue.error.routing.key}")
private String errorRoutingKey; public void send() {
String message = "Hello " + new Date();
rmqTemplate.convertAndSend(exchange, infoRoutingKey, message);
rmqTemplate.convertAndSend(exchange, errorRoutingKey, message);
}
}
LogInfoConsumer.java
package org.fool.rmq.direct; import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component; @Component
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "${rmq.config.queue.info}", autoDelete = "true"),
exchange = @Exchange(value = "${rmq.config.exchange}", type = ExchangeTypes.DIRECT),
key = "${rmq.config.queue.info.routing.key}"
))
public class LogInfoConsumer {
@RabbitHandler
public void handle(String message) {
System.out.println("consume info: " + message);
}
}
LogErrorConsumer.java
package org.fool.rmq.direct; import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component; @Component
@RabbitListener(bindings = @QueueBinding(
value = @Queue(value = "${rmq.config.queue.error}", autoDelete = "true"),
exchange = @Exchange(value = "${rmq.config.exchange}", type = ExchangeTypes.DIRECT),
key = "${rmq.config.queue.error.routing.key}"
))
public class LogErrorConsumer {
@RabbitHandler
public void handle(String message) {
System.out.println("consume error: " + message);
}
}
ApplicationTest.java
package org.fool.rmq.test; import org.fool.rmq.Application;
import org.fool.rmq.direct.LogProducer;
import org.fool.rmq.producer.Producer;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ApplicationTest { @Autowired
private Producer producer; @Autowired
private LogProducer logProducer; @Test
public void test() {
producer.send();
} @Test
public void testDirect() {
logProducer.send();
}
}
Console Output
RMQ Management
RMQ Direct的更多相关文章
- RMQ Fanout
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11795256.html RMQ Fanout Project Directory Maven Depe ...
- RMQ Topic
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11794927.html RMQ Topic Project Directory Maven Depen ...
- RabbitMQ学习之:(六)Direct Exchange (转贴+我的评论)
From: http://lostechies.com/derekgreer/2012/04/02/rabbitmq-for-windows-direct-exchanges/ RabbitMQ fo ...
- RMQ Terminology
原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11784644.html RMQ模型架构 RMQ Terminology Message 消息,消息是不 ...
- BZOJ 3489: A simple rmq problem
3489: A simple rmq problem Time Limit: 40 Sec Memory Limit: 600 MBSubmit: 1594 Solved: 520[Submit] ...
- UVA 11235Frequent values(RMQ)
训练指南P198 题意:给出一个非降序排列的整数数组a1, a2…… an,你的任务是对于一系列询问(i,j),回答ai, ai+1 ……aj 中出现的次数最多的次数 这题不仅学到了rmq的应用还学到 ...
- MMAP和DIRECT IO区别
看完此文,题目不言自明.转自 http://blog.chinaunix.net/uid-27105712-id-3270102.html 在Linux 开发中,有几个关系到性能的东西,技术人员非常关 ...
- 51nod1174(RMQ)
题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1174 题意:中文题诶- 思路:RMQ模板题 关于RMQ: h ...
- direct path read
在11g中,全表扫描可能使用direct path read方式,绕过buffer cache,这样的全表扫描就是物理读了. 在10g中,都是通过gc buffer来读的,所以不存在direct pa ...
随机推荐
- MK66FN2M0VLQ18
NXP Kinetis K66: 180MHz Cortex-M4F MCU, 2MB Flash, 256KB SRAM, Dual USBs (FS + HS), Ethernet, 144-LQ ...
- cenos 7 中firewalld开放服务端口
转载 CentOS 7 为firewalld添加开放端口及相关资料 1.运行.停止.禁用firewalld 启动:# systemctl start firewalld 查看状态:# syste ...
- (转)SQLite部署-无法加载 DLL“SQLite.Interop.dll”: 找不到指定的模块
本文转载自:http://www.cnblogs.com/muzhiye/p/4284070.html 近期刚使用SQLite,主要引用的是System.Data.SQLite.dll这个dll,在部 ...
- 三十二、python操作XML文件
'''XML:模块 xml总结 1.解析 str 文件 tree,ElementTree,type root,Element,type2.操作 Element: tag,text,find,iter, ...
- springmvc+ehcache简单例子
这里采用的是spring3.2.ehcache2.7.tomcat7.0(必须) 1.web.xml <?xml version="1.0" encoding="U ...
- VMware 虚拟化编程(10) — VMware 数据块修改跟踪技术 CBT
目录 目录 前文列表 数据块修改跟踪技术 CBT 为虚拟机开启 CBT CBT 修改数据块偏移量获取函数 QueryChangedDiskAreas changeId 一个 QueryChangedD ...
- sort_values()和sort_index()函数
sort_values() 1 可用于对dateframe的多列同时进行排序 True是升序,False是降序,默认是升序 kk.sort_values(by=['listing_id','order ...
- 应用安全-CMF/CMS漏洞整理
CMS识别 云悉 http://whatweb.bugscaner.com/batch.html CakePHP CakePHP <= / Cache Corruption Exploit 2 ...
- 深度探索区块链/基于Gossip的P2P数据分发(4)
一.概述 背书节点模拟执行签名的结果会经过排序服务(Ording service)广播给所有的节点. 它提供的是一种原子广播服务(Atomic Broadcast),即在逻辑上所有节点接收到的消息顺序 ...
- JQuery关于span标签的取值赋值
span取值赋值方法有别于一般的页面元素.JQ://赋值$("#spanid").html("hello world") //取值$("#spanid ...