|
|
@@ -62,13 +62,19 @@ public abstract class Subscribe implements WsHandler {
|
|
|
}
|
|
|
//获取所有设备id
|
|
|
List<String> params = message.getParams();
|
|
|
- if(CollectionUtil.isEmpty(params)){
|
|
|
+ if(CollectionUtil.isEmpty(params)&&this.needParam()){
|
|
|
return;
|
|
|
}
|
|
|
+ List<TopicWrapper> subScribeTopic =null;
|
|
|
//需要处理的主题
|
|
|
- List<TopicWrapper> subScribeTopic =
|
|
|
- params.stream().map(param -> getTopic(message.getProductName(), param, loginUser.getTenantId()))
|
|
|
- .collect(Collectors.toList());
|
|
|
+ if (CollectionUtil.isNotEmpty(params)) {
|
|
|
+ subScribeTopic =
|
|
|
+ params.stream().map(param -> getTopic(message.getProductName(), param, loginUser.getTenantId()))
|
|
|
+ .collect(Collectors.toList());
|
|
|
+ }else {
|
|
|
+ subScribeTopic = Collections.singletonList(getTopic(message.getProductName(), null, loginUser.getTenantId()));
|
|
|
+ }
|
|
|
+
|
|
|
MessagingRequest.Type type = message.getType();
|
|
|
if(MessagingRequest.Type.sub==type){
|
|
|
//订阅主题
|
|
|
@@ -85,10 +91,18 @@ public abstract class Subscribe implements WsHandler {
|
|
|
* @param topicWrapper
|
|
|
*/
|
|
|
public void subscribe(ChannelContext channelContext, TopicWrapper topicWrapper){
|
|
|
+ //将主题与ws通道绑定
|
|
|
+ Object result = Optional.ofNullable(channelContext.get(SUBSCRIBE_TOPIC)).orElse(new HashSet<>());
|
|
|
+ Set<String> subscribeTopicSet= (Set<String>) result;
|
|
|
+ if(subscribeTopicSet.contains(topicWrapper.getTopic())){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ subscribeTopicSet.add(topicWrapper.getTopic());
|
|
|
+ channelContext.set(SUBSCRIBE_TOPIC,subscribeTopicSet);
|
|
|
//同一主题只订阅一次
|
|
|
- Set<ChannelContext> channelContexts = Optional.ofNullable(subscribeTopics.get(topicWrapper)).orElse(new HashSet<>());
|
|
|
- if(!subscribeTopics.containsKey(topicWrapper)){
|
|
|
- channelContexts.add(channelContext);
|
|
|
+ Set<ChannelContext> channelContexts = Optional.ofNullable(subscribeTopics.get(topicWrapper.getTopic())).orElse(new HashSet<>());
|
|
|
+ channelContexts.add(channelContext);
|
|
|
+ if(!subscribeTopics.containsKey(topicWrapper.getTopic())){
|
|
|
redisTemplate.execute(new RedisCallback<Object>() {
|
|
|
@Override
|
|
|
public Object doInRedis(RedisConnection connection) throws DataAccessException {
|
|
|
@@ -99,11 +113,6 @@ public abstract class Subscribe implements WsHandler {
|
|
|
});
|
|
|
}
|
|
|
subscribeTopics.put(topicWrapper.getTopic(),channelContexts);
|
|
|
- //将主题与ws通道绑定
|
|
|
- Object result = Optional.ofNullable(channelContext.get(SUBSCRIBE_TOPIC)).orElse(new HashSet<>());
|
|
|
- Set<String> subscribeTopicSet= (Set<String>) result;
|
|
|
- subscribeTopicSet.add(topicWrapper.getTopic());
|
|
|
- channelContext.set(SUBSCRIBE_TOPIC,subscribeTopicSet);
|
|
|
};
|
|
|
|
|
|
/**
|