当前位置:网站首页>Rambbmitmq consumer
Rambbmitmq consumer
2022-06-22 05:16:00 【a good idea】
#spring.rabbitmq.port=
server.port=
spring.application.name=
spring.rabbitmq.host=
spring.rabbitmq.username=
spring.rabbitmq.password=
spring.rabbitmq.port=
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication(scanBasePackages={"com.demo"})
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}
package com.demo.common;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
@Component
public class MyRabbitListener {
// monitor testQueue This line
@RabbitListener(queues = "testQueue")
public void test(String msg){
// Print received messages
System.out.println("msg--------------------------------------------------------"+msg);
}
}
package com.demo.common;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitConfig {
@Bean
Queue testQueue(){
// Queue name
return new Queue("testQueue");
}
/**
* Switch
* @return
*/
@Bean
DirectExchange testExchange(){
return new DirectExchange("testExchange");
}
/**
* Bind the switch to the queue
*/
@Bean
Binding testBinding(){
return BindingBuilder.
// Bind message queue to switch
bind(testQueue()).
to(testExchange()).
// routingKey by testKey
with("testKey");
}
}
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.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>
<exclusions>
<exclusion>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.amqp</groupId>
<artifactId>spring-rabbit-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>边栏推荐
猜你喜欢

How much is London gold

Database - basic knowledge

Detailed explanation of deep learning technology for building an image search engine that can find similar images

2022 refrigeration and air conditioning equipment operation test paper and refrigeration and air conditioning equipment operation test skills

Concurrent programming - thread pool

ActiveMQ knowledge summary of Message Oriented Middleware

Remote dictionary server (redis) - a kV based NoSQL database management system used as a cache

Squoosh - Google's free open source image compression tool, reducing the image size by 90%! Support API development calls

风阀执行EN 1634-1耐火测试完整性能坚持 4小时吗?

In 2022, the super intern plans to make a breakthrough in the offer of it famous enterprises, and the nine high salary skills help the dream of famous enterprises
随机推荐
Liunx virtual machine environment uses docker to install Oracle database and Navicat to connect
SQL分类,用户属性
mysql day01课堂笔记
9 practical shell scripts, recommended collection!
NHibernate method for viewing generated SQL statements
拉取码云某一个分支的所有数据覆盖本地代码
Kubernetes——裸机搭建集群环境
Monorepo Sliding methodology: Reference module Hot Update
1108. Defanging an IP Address
Literacy of C language concept knowledge (supplemented and updated from time to time)
QT save qtextedit memory to Txt file
6. Local - custom filter factory
Please, use three JS make 2D pictures have 3D effect cool, OK
7. Gateway global filter
Non recursive printing Fibonacci sequence
jedispool的使用
Monorepo silk slide methodology: reference module hot update
A domestic developer opened the "programmer's Guide to cooking" and became popular!
Use keytool to access the JKS file get SSL certificate
Pull all data of a branch of the code cloud to cover the local code