add containsTopic method

This commit is contained in:
gongdewei
2021-05-25 16:34:15 +08:00
parent 4261eba5ba
commit f91c1c00d1
3 changed files with 17 additions and 0 deletions
@@ -31,6 +31,13 @@ public interface MessageExchangeService {
void subscribe(Topic topic, int timeout, MessageHandler messageHandler) throws MessageExchangeException;
/**
* Whether exists the specify topic
* @param topic
* @return
*/
boolean containsTopic(Topic topic);
interface MessageHandler {
/**
* handle message
@@ -101,6 +101,11 @@ public class MessageExchangeServiceImpl implements MessageExchangeService {
}
}
@Override
public boolean containsTopic(Topic topic) {
return topicMap.containsKey(topic);
}
@Override
public void pushMessage(Topic topic, byte[] messageBytes) throws MessageExchangeException {
TopicData topicData = topicMap.get(topic);
@@ -79,6 +79,11 @@ public class RedisMessageExchangeServiceImpl implements MessageExchangeService {
}
}
@Override
public boolean containsTopic(Topic topic) {
return redisTemplate.hasKey(topic.getTopic()).block();
}
@Override
public void pushMessage(Topic topic, byte[] messageBytes) throws MessageExchangeException {
String key = topic.getTopic();