赞
踩
注意一点,在发送消息的时候对template进行配置mandatory=true保证监听有效
生产端还可以配置其他属性,比如发送重试,超时时间、次数、间隔等
消费端核心配置
@RabbitListener注解的使用
由于类配置写在代码里非常不友好,所以强烈建议大家使用配置文件配置
相关代码
rabbitmq-common子项目
package com.swx.rabbitmqcommon.entity; import java.io.Serializable; /** * @author Songwanxi * @site www.lentter.club * @company * @create 2020-03-04 11:34 * * 支付完毕后下单操作实体类 */ public class Order implements Serializable { private String id; private String name; public Order() { } public Order(String id, String name) { super(); this.id = id; this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
rabbitmq-springcloud-consumer子项目
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 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.2.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <groupId>com.swx</groupId> <artifactId>rabbitmq-springcloud-consumer</artifactId> <version>0.0.1-SNAPSHOT</version> <name>rabbitmq-springcloud-consumer</name> <description>Demo project for Spring Boot</description> <properties> <java.version>1.8</java.version> </properties> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>com.swx</groupId> <artifactId>rabbitmq-common</artifactId> <version>0.0.1-SNAPSHOT</version> </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-e
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。