mq延时任务,添加移除房间管理员缓存,
This commit is contained in:
@@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSON;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.client.producer.SendCallback;
|
||||
import org.apache.rocketmq.client.producer.SendResult;
|
||||
import org.apache.rocketmq.common.message.MessageConst;
|
||||
import org.apache.rocketmq.spring.core.RocketMQTemplate;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
@@ -189,4 +190,29 @@ public class MQMessageProducer {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param queueName
|
||||
* @param object
|
||||
* @param delayMillis 对应定时的延时时间毫秒
|
||||
* @param <T>
|
||||
*/
|
||||
public <T extends BaseMqMessage> SendResult sendDelay(String queueName, T object, Integer delayMillis) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
if (delayMillis == null) {
|
||||
delayMillis = 0;
|
||||
}
|
||||
try {
|
||||
String objectJson = JSON.toJSONString(object);
|
||||
log.info("queueName : {}, message : {}, delayMillis:{}", queueName, objectJson, delayMillis);
|
||||
SendResult sendResult = rocketMQTemplate.syncSendDelayTimeMills(queueName, objectJson, delayMillis);
|
||||
log.info("queueName : {}, message : {}, delayMillis:{},sendResult:{}", queueName, objectJson, delayMillis, sendResult);
|
||||
return sendResult;
|
||||
} catch (Exception e) {
|
||||
log.error(e.getMessage(), e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,23 @@
|
||||
package com.accompany.mq.consumer;
|
||||
|
||||
import cn.hutool.core.date.DateUtil;
|
||||
import com.accompany.business.message.UserEventBeginEndMessage;
|
||||
import com.accompany.mq.constant.MqConstant;
|
||||
import com.accompany.mq.listener.AbstractMessageListener;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Slf4j
|
||||
@Component
|
||||
@ConditionalOnProperty(name = "spring.application.name", havingValue = "admin")
|
||||
@RocketMQMessageListener(topic = MqConstant.USER_ENEVT_DELAY_TOPIC, consumerGroup = MqConstant.USER_ENEVT_DELAY_CONSUME_GROUP)
|
||||
public class UserEventBeginEndConsumer extends AbstractMessageListener<UserEventBeginEndMessage> {
|
||||
@Override
|
||||
protected void onMessage(UserEventBeginEndMessage eventBeginEndMessage) throws Exception {
|
||||
log.info("onMessage gameMsgMessage: {}, begin:{},now:{}", eventBeginEndMessage.toString(), eventBeginEndMessage.getMsgDate(), DateUtil.formatDateTime(new Date()));
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user