package com.xcong.excoin.rabbit.producer;
|
|
import cn.hutool.core.util.IdUtil;
|
import com.xcong.excoin.configurations.RabbitMqConfig;
|
import lombok.extern.slf4j.Slf4j;
|
import org.springframework.amqp.rabbit.connection.CorrelationData;
|
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Component;
|
|
/**
|
* @author wzy
|
* @date 2020-05-25
|
**/
|
@Slf4j
|
@Component
|
public class TestProducer implements RabbitTemplate.ConfirmCallback {
|
|
private RabbitTemplate rabbitTemplate;
|
|
@Autowired
|
public TestProducer(RabbitTemplate rabbitTemplate) {
|
this.rabbitTemplate = rabbitTemplate;
|
rabbitTemplate.setConfirmCallback(this);
|
}
|
|
public void sendTestMsg(String content) {
|
CorrelationData correlationData = new CorrelationData(IdUtil.simpleUUID());
|
rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_ONE, RabbitMqConfig.ROUTING_KEY_TEST, content, correlationData);
|
}
|
|
|
@Override
|
public void confirm(CorrelationData correlationData, boolean ack, String cause) {
|
log.info("#----->{}#", correlationData);
|
if (ack) {
|
log.info("success");
|
} else {
|
log.info("--->{}", cause);
|
}
|
}
|
}
|