From d61072f997839b4564ce35132d5902a1b6f7d54f Mon Sep 17 00:00:00 2001
From: Helius <wangdoubleone@gmail.com>
Date: Mon, 03 Aug 2020 17:39:10 +0800
Subject: [PATCH] modify
---
src/main/java/com/xcong/excoin/rabbit/producer/OrderProducer.java | 205 ++++++++++++++++++++++++++------------------------
1 files changed, 107 insertions(+), 98 deletions(-)
diff --git a/src/main/java/com/xcong/excoin/rabbit/producer/OrderProducer.java b/src/main/java/com/xcong/excoin/rabbit/producer/OrderProducer.java
index 29b946e..400cf46 100644
--- a/src/main/java/com/xcong/excoin/rabbit/producer/OrderProducer.java
+++ b/src/main/java/com/xcong/excoin/rabbit/producer/OrderProducer.java
@@ -1,6 +1,7 @@
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.amqp.rabbit.core.RabbitTemplate.ConfirmCallback;
@@ -13,120 +14,128 @@
/**
* rabbitMq示例生产者
*/
+@Slf4j
@Component
public class OrderProducer implements ConfirmCallback {
- /**
- * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
- */
- private RabbitTemplate rabbitTemplate;
+ /**
+ * 配置中配置的RabbitTemplate的是prototype类型,不能直接注入
+ */
+ private RabbitTemplate rabbitTemplate;
- /**
- * 在构造方法上注入RabbitTemplate
- *
- * @param
- */
- @Autowired
- public OrderProducer(RabbitTemplate rabbitTemplate) {
- this.rabbitTemplate = rabbitTemplate;
- rabbitTemplate.setConfirmCallback(this);
- }
+ /**
+ * 在构造方法上注入RabbitTemplate
+ *
+ * @param
+ */
+ @Autowired
+ public OrderProducer(RabbitTemplate rabbitTemplate) {
+ this.rabbitTemplate = rabbitTemplate;
+ rabbitTemplate.setConfirmCallback(this);
+ }
- /**
- * P发送消息方法 开多止盈
- */
- public void sendMorePro(String content) {
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送开多止盈:"+content+"==pid:"+correlationData.getId());
+ /**
+ * P发送消息方法 开多止盈
+ */
+ public void sendMorePro(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送开多止盈:" + content + "==pid:" + correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_MOREPRO, content, correlationData);
- }
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_MOREPRO, content, correlationData);
+ }
- /**
- * 开空止盈
- * @param content
- */
- public void sendLessPro(String content) {
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送开空止盈:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LESSPRO, content, correlationData);
- }
+ /**
+ * 开空止盈
+ *
+ * @param content
+ */
+ public void sendLessPro(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送开空止盈:" + content + "==pid:" + correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LESSPRO, content, correlationData);
+ }
- /**
- * 开多止损
- * @param content
- */
- public void sendMoreLoss(String content) {
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送开多止损:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_MORELOSS, content, correlationData);
- }
+ /**
+ * 开多止损
+ *
+ * @param content
+ */
+ public void sendMoreLoss(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送开多止损:" + content + "==pid:" + correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_MORELOSS, content, correlationData);
+ }
- /**
- * 开空止损
- * @param content
- */
- public void sendLessLoss(String content) {
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送开空止损:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LESSLOSS, content, correlationData);
- }
+ /**
+ * 开空止损
+ *
+ * @param content
+ */
+ public void sendLessLoss(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送开空止损:" + content + "==pid:" + correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LESSLOSS, content, correlationData);
+ }
- /**
- * 发送委托交易消息
- * @param content
- */
- public void sendLimit(String content){
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送限价委托:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LIMIT, content, correlationData);
- }
+ /**
+ * 发送委托交易消息
+ *
+ * @param content
+ */
+ public void sendLimit(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送限价委托:" + content + "==pid:" + correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_LIMIT, content, correlationData);
+ }
- /**
- * 发送爆仓消息
- * @param content
- */
- public void sendCoinout(String content){
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送爆仓:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_COINOUT, content, correlationData);
- }
+ /**
+ * 发送爆仓消息
+ *
+ * @param content
+ */
+ public void sendCoinout(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ System.out.println("发送爆仓:" + content + "==pid:" + correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_COINOUT, content, correlationData);
+ }
- /**
- * 发送价格操作消息
- * @param content
- */
- public void sendPriceOperate(String content){
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送价格操作:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_PRICEOPERATE, content, correlationData);
- }
+ /**
+ * 发送价格操作消息
+ *
+ * @param content
+ */
+ public void sendPriceOperate(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ log.info("发送价格操作 : {}==pid : {}", content, correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_PRICEOPERATE, content, correlationData);
+ }
- /**
- * 发送平仓
- * @param content
- */
- public void sendCloseTrade(String content){
- CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
- System.out.println("发送平仓消息:"+content+"==pid:"+correlationData.getId());
- rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_CLOSETRADE, content, correlationData);
- }
+ /**
+ * 发送平仓
+ *
+ * @param content
+ */
+ public void sendCloseTrade(String content) {
+ CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
+ log.info("发送平仓消息:{}==pid : {}", content, correlationData.getId());
+ rabbitTemplate.convertAndSend(RabbitMqConfig.EXCHANGE_A, RabbitMqConfig.ROUTINGKEY_CLOSETRADE, content, correlationData);
+ }
- /**
- * 用于确认消息是否成功发送到队列
- */
- @Override
- public void confirm(CorrelationData correlationData, boolean ack, String cause) {
- if (ack) {
- //System.out.println("消息发送成功"+correlationData.getId());
- //LogUtil.info("消息发送成功,correlationId={}", correlationData.getId());
- } else {
- System.out.println("消息发送失败"+correlationData.getId());
- //LogUtil.info("消息发送失败,correlationId={}", correlationData.getId());
- }
- }
+ /**
+ * 用于确认消息是否成功发送到队列
+ */
+ @Override
+ public void confirm(CorrelationData correlationData, boolean ack, String cause) {
+ if (ack) {
+ //System.out.println("消息发送成功"+correlationData.getId());
+ //LogUtil.info("消息发送成功,correlationId={}", correlationData.getId());
+ } else {
+ System.out.println("消息发送失败" + correlationData.getId());
+ //LogUtil.info("消息发送失败,correlationId={}", correlationData.getId());
+ }
+ }
}
--
Gitblit v1.9.1