springboot项目使用rabbitMQ

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);
	}
	
	

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值