feat: 二阶段
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
package demo.kafka;
|
||||
|
||||
public class CheckItemDetailVo {
|
||||
private String itemId;
|
||||
private String itemName;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package demo.kafka;
|
||||
|
||||
public class CheckItemDetailVo {
|
||||
private String itemId;
|
||||
private String itemName;
|
||||
private Integer score;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package demo.kafka;
|
||||
|
||||
import java.util.List;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
|
||||
public class PatrolService {
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
private static final String TOPIC = "patrol-store-food-safe:%s";
|
||||
|
||||
public void sendFoodSafeData(String tenantId, List<CheckItemDetailVo> thousandsData) {
|
||||
String topic = String.format(TOPIC, tenantId);
|
||||
kafkaTemplate.send(topic, thousandsData);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package demo.kafka;
|
||||
|
||||
import org.springframework.kafka.annotation.KafkaListener;
|
||||
|
||||
public class PatrolNotifyListener {
|
||||
@KafkaListener(topics = "patrol-notify-topic", groupId = "patrol-group")
|
||||
public void handle(String message) {
|
||||
PatrolNotifyVo vo = JSONObject.parseObject(message, PatrolNotifyVo.class);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package demo.kafka;
|
||||
|
||||
import org.apache.kafka.clients.producer.ProducerRecord;
|
||||
import org.springframework.kafka.core.KafkaTemplate;
|
||||
|
||||
public class PatrolNotifyProducer {
|
||||
private KafkaTemplate kafkaTemplate;
|
||||
private static final String TOPIC = "patrol-notify-topic";
|
||||
|
||||
public void sendRecord(PatrolNotifyVo vo) {
|
||||
ProducerRecord<String, PatrolNotifyVo> record = new ProducerRecord<>(TOPIC, vo);
|
||||
kafkaTemplate.send(record);
|
||||
}
|
||||
|
||||
public void sendJson(PatrolNotifyVo vo) {
|
||||
String json = JSON.toJSONString(vo);
|
||||
kafkaTemplate.send(TOPIC, json);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package demo.kafka;
|
||||
|
||||
public class PatrolNotifyVo {
|
||||
private String storeId;
|
||||
private String status;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package demo.mq;
|
||||
|
||||
public class DutyImNotice {
|
||||
private String tenantId;
|
||||
private String id;
|
||||
private String content;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package demo.mq;
|
||||
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.apache.rocketmq.spring.core.RocketMQListener;
|
||||
|
||||
@RocketMQMessageListener(topic = DutyImNoticeProducer.MQ_TOPIC, consumerGroup = "duty-im-group")
|
||||
public class DutyImNoticeConsumer implements RocketMQListener<DutyImNotice> {
|
||||
public void onMessage(DutyImNotice message) {
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package demo.mq;
|
||||
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
public class DutyImNoticeProducer {
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
public static final String MQ_TOPIC = "duty-im-notice-topic";
|
||||
|
||||
public void addMq(DutyImNotice message, long timestamp) {
|
||||
String uniqueKey = message.getTenantId() + "_" + message.getId();
|
||||
Message<DutyImNotice> mqMessage = MessageBuilder.withPayload(message)
|
||||
.setHeader("KEYS", uniqueKey)
|
||||
.setHeader("executeTime", timestamp)
|
||||
.build();
|
||||
rocketMQTemplate.asyncSend(MQ_TOPIC, mqMessage);
|
||||
}
|
||||
|
||||
public void convertSend(DutyImNotice message) {
|
||||
rocketMQTemplate.convertAndSend(MQ_TOPIC, message);
|
||||
}
|
||||
|
||||
public void sendJson(DutyImNotice message) {
|
||||
String body = JSON.toJSONString(message);
|
||||
rocketMQTemplate.syncSend(MQ_TOPIC, body);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package demo.mq;
|
||||
|
||||
public final class CapitalMqConstants {
|
||||
public static final String TOPIC = "capital-topic";
|
||||
public static final String TAG_WALLET_DEDUCT = "WALLET_DEDUCT";
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package demo.mq;
|
||||
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
|
||||
public class WalletDeductProducer {
|
||||
private RocketMQTemplate rocketMQTemplate;
|
||||
|
||||
public void send(WalletDeductReq req) {
|
||||
rocketMQTemplate.syncSend(CapitalMqConstants.TOPIC + ":" + CapitalMqConstants.TAG_WALLET_DEDUCT, req);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
package demo.mq;
|
||||
|
||||
public class WalletDeductReq {
|
||||
private String walletId;
|
||||
private Long amount;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
package demo.mq;
|
||||
|
||||
public class WalletDeductReq {
|
||||
private String walletId;
|
||||
private Long amount;
|
||||
private String remark;
|
||||
}
|
||||
Reference in New Issue
Block a user