幸运礼物-mq异步结算-随机队列

This commit is contained in:
khalil
2025-01-10 21:42:52 +08:00
parent 9ec794deda
commit f2d40af975
3 changed files with 21 additions and 2 deletions

View File

@@ -120,7 +120,8 @@ public class Lucky24GiftSendService {
jedisService.hwrite(RedisKey.lucky_24_status.getKey(), caches);
rocketMQService.asyncSendBatchLucky24Message(messageList);
//rocketMQService.asyncSendBatchLucky24Message(messageList);
rocketMQService.sendBatchLucky24Message(messageList);
}
public Lucky24Record drawMultiple2(Lucky24GiftConfig config, Lucky24GiftConfig partitionConfig, long senderUid, Users sender, int partitionId,

View File

@@ -47,6 +47,23 @@ public class RocketMQService {
}
}
/**
* 送礼物消息发送到MQ
*
* @param lucky24Messages
*/
public void sendBatchLucky24Message(Collection<Lucky24Message> lucky24Messages) {
List<Message<String>> messageList = lucky24Messages.stream()
.map(giftMessage -> MessageBuilder.withPayload(JSON.toJSONString(giftMessage)).build())
.collect(Collectors.toList());
SendResult sendResult = rocketMQTemplate.syncSend(MqConstant.LUCKY_24_TOPIC, messageList);
if (SendStatus.SEND_OK.equals(sendResult.getSendStatus())){
log.info("sendLucky24Message success result: {} message: {}", JSON.toJSONString(sendResult), messageList);
} else {
log.error("sendLucky24Message fail result: {} message: {}", JSON.toJSONString(sendResult), messageList);
}
}
/**
* 送礼物消息发送到MQ
*

View File

@@ -14,7 +14,8 @@ import org.springframework.stereotype.Component;
@Slf4j
@Component
@ConditionalOnProperty(name = "spring.application.name", havingValue = "web")
@RocketMQMessageListener(topic = MqConstant.LUCKY_24_TOPIC, consumerGroup = MqConstant.LUCKY_24_CONSUME_GROUP, consumeMode = ConsumeMode.ORDERLY)
//@RocketMQMessageListener(topic = MqConstant.LUCKY_24_TOPIC, consumerGroup = MqConstant.LUCKY_24_CONSUME_GROUP, consumeMode = ConsumeMode.ORDERLY)
@RocketMQMessageListener(topic = MqConstant.LUCKY_24_TOPIC, consumerGroup = MqConstant.LUCKY_24_CONSUME_GROUP)
public class Lucky24MessageConsumer extends AbstractMessageListener<Lucky24Message> {
@Autowired