xiaoyong931011
2021-03-04 6bfa9de6c86de3b6de5d59e0dc9eebbba13bdb1f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.xcong.excoin.rabbit.producer;
 
 
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;
 
import java.util.UUID;
 
/**
 * @author wzy
 * @date 2021-03-04
 **/
@Slf4j
@Component
public class FollowProducer implements RabbitTemplate.ConfirmCallback {
 
    private RabbitTemplate rabbitTemplate;
 
    @Autowired
    public FollowProducer(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        rabbitTemplate.setConfirmCallback(this);
    }
 
    @Override
    public void confirm(CorrelationData correlationData, boolean b, String s) {
 
    }
 
    /**
     * 发送跟单下单消息
     *
     * @param id
     */
    public void sendAddFollowOrder(Long id) {
        CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
        log.info("发送跟单下单消息: {}, {}", id, correlationData.getId());
        rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_FOLLOW_ORDER, id, correlationData);
    }
}