first commit

This commit is contained in:
cys841515238
2023-03-02 16:13:28 +08:00
commit 2733a60b97
741 changed files with 76931 additions and 0 deletions

View File

@@ -0,0 +1,19 @@
package com.peanut.modules.mq.service;
/**
* rabbiMq服务
* @author AnYuan
*/
public interface RabbitMqService {
/**
* 统一发送mq
*
* @param exchange 交换机
* @param routingKey 路由key
* @param msg 消息
* @param ttl 过期时间
*/
void send(String exchange, String routingKey, String msg, Long ttl);
}

View File

@@ -0,0 +1,33 @@
package com.peanut.modules.mq.service.impl;
import com.peanut.modules.mq.service.RabbitMqService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
/**
* rabbitmq服务
* @author AnYuan
*/
@Service
@Slf4j
public class RabbitMqServiceImpl implements RabbitMqService {
@Autowired
private RabbitTemplate rabbitTemplate;
@Override
public void send(String exchange, String routingKey, String msg, Long ttl) {
MessageProperties messageProperties = new MessageProperties();
// 第二种方式设置消息过期时间
messageProperties.setExpiration(ttl.toString());
// 构建一个消息对象
Message message = new Message(msg.getBytes(), messageProperties);
// 发送RabbitMq消息
rabbitTemplate.convertAndSend(exchange, routingKey, message);
}
}