package com.test;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.rabbit.support.CorrelationData;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.UUID;

public class RmqProducer implements RabbitTemplate.ConfirmCallback {
    private RabbitTemplate template;

    @Autowired
    public RmqProducer(RabbitTemplate template){
        this.template = template;
    }

    /* (non-Javadoc)
     * @see com.stnts.tita.rm.api.mq.MQProducer#sendDataToQueue(java.lang.String, java.lang.Object)
     */
    public void sendMessage(String content) {
        try {
            CorrelationData correlationId = new CorrelationData(UUID.randomUUID().toString());
            template.convertAndSend("spring-boot-exchange", "spring-boot-routingKey",content,correlationId);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void confirm(CorrelationData correlationData, boolean ack, String cause) {
        System.out.println(" 回调id:" + correlationData+"ack:"+ack);
    }
}
