yml文件配置
注意格式
server:
port: 8090
spring:
rabbitmq:
host: 127.0.0.1
port: 5672
username: guest
password: guest
virtual-host: /
datasource:
url: jdbc:mysql://127.0.0.1:3309/test?useUnicode=true&characterEncoding=UTF-8&serverTimezone=GMT%2B8&useSSL=false
username: root
password: root
driver-class-name: com.mysql.cj.jdbc.Driver
xml文件使用
<!-- amqp的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-configuration-processor</artifactId>
<optional>true</optional>
</dependency>
消费者
package com.java.demo;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
/**
*
* @ClassName: ConsumerListner
* @Description: 消费者监听类
* @author _只一个
* @date 2020年9月25日
*
*/
@Component
public class ConsumerListner {
/**
*
* @Title: msg
* @Description: 消费者消费队列中的消息(消费新增的队列)
* @param @param msg 参数
* @return void 返回类型
* @throws
* @author _只一个
* @date 2020年9月25日
* @param msg
*/
@RabbitListener(queues = "data-add")
public void add(String msg) {
System.out.println("已消费消息" + msg);
}
}