package com.xcong.excoin.rabbit.producer; import com.alibaba.fastjson.JSONObject; import com.xcong.excoin.configurations.RabbitMqConfig; import com.xcong.excoin.modules.contract.parameter.dto.ChangeBondDto; import lombok.extern.slf4j.Slf4j; import net.sf.json.JSON; 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 org.web3j.abi.datatypes.Int; import java.math.BigDecimal; import java.util.HashMap; import java.util.Map; 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.toString(), correlationData); } /** * 发送跟单调整保证金信息 * * @param id */ public void sendChangeFollowOrderBond(ChangeBondDto changeBondDto) { CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString()); String msg = JSONObject.toJSONString(changeBondDto); log.info("发送跟单保证金调整消息: {}, {}", msg, correlationData.getId()); rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_FOLLOW_CHANGE_BOND, msg, correlationData); } }