当前位置:网站首页>rambbmitmq消费方
rambbmitmq消费方
2022-06-22 05:11: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 {
// 监听testQueue这个队列
@RabbitListener(queues = "testQueue")
public void test(String msg){
// 打印接收到的消息
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(){
// 队列名称
return new Queue("testQueue");
}
/**
* 交换机
* @return
*/
@Bean
DirectExchange testExchange(){
return new DirectExchange("testExchange");
}
/**
* 将交换机与队列进行绑定
*/
@Bean
Binding testBinding(){
return BindingBuilder.
// 绑定消息队列到交换机
bind(testQueue()).
to(testExchange()).
// routingKey 为 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>边栏推荐
猜你喜欢

Will swift compile to native code- Does Swift compile to native code?

Golang concise architecture practice

Progress information collection for progress control of Zhiyuan project management SPM system

Using Matplotlib to realize GUI interaction effect

7. Gateway global filter

Geographic location type of redis

What problems will be encountered during the implementation of MES management system

在Vs Code中搭建JSP开发环境

这是一个图片

It is easy to analyze and improve R & D efficiency by understanding these five figures
随机推荐
Pull down refresh, push up load (easy to use, finally)
10道不得不会的 Redis 面试题
A domestic developer opened the "programmer's Guide to cooking" and became popular!
VirtualBox 6.1.34 release
[user guide] create an environment using public CONDA
[fault diagnosis] stitch Py script failure
CS 611 Game
NLP 的 不可能三角?
1108. Defanging an IP Address
汉诺塔问题
Remote dictionary server (redis) - a kV based NoSQL database management system used as a cache
软件架构与模式:结构、组件、关系
Solve the shortage of developers. Maybe it can help you
[camp] at the beginning, improve [leopard] power - vivo activity plug-in management platform
mysql day01课堂笔记
Getting the return value of DPI function is always 96 | getting the return value of DPI function is incorrect | why the return value of getdpiformonitor/getdevicecaps is incorrect
Graph calculation on nlive:nepal's graph calculation practice
在Vs Code中搭建JSP开发环境
Virtual address space
Go learning (II. Built in container)