|
@@ -15,7 +15,9 @@ import reactor.core.publisher.Flux;
|
|
import reactor.core.publisher.Mono;
|
|
import reactor.core.publisher.Mono;
|
|
|
|
|
|
import javax.annotation.Nonnull;
|
|
import javax.annotation.Nonnull;
|
|
|
|
+import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.Collections;
|
|
|
|
+import java.util.List;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.BiConsumer;
|
|
import java.util.function.Function;
|
|
import java.util.function.Function;
|
|
|
|
|
|
@@ -32,6 +34,7 @@ public class DeviceMessageConnector implements DecodedClientMessageHandler {
|
|
private final static String[] allConfigHeader = {
|
|
private final static String[] allConfigHeader = {
|
|
PropertyConstants.productId.getKey(),
|
|
PropertyConstants.productId.getKey(),
|
|
PropertyConstants.deviceName.getKey(),
|
|
PropertyConstants.deviceName.getKey(),
|
|
|
|
+ PropertyConstants.orgId.getKey()
|
|
};
|
|
};
|
|
|
|
|
|
//设备注册中心
|
|
//设备注册中心
|
|
@@ -41,8 +44,6 @@ public class DeviceMessageConnector implements DecodedClientMessageHandler {
|
|
|
|
|
|
private final MessageHandler messageHandler;
|
|
private final MessageHandler messageHandler;
|
|
|
|
|
|
- private final DeviceSessionManager sessionManager;
|
|
|
|
-
|
|
|
|
private final static BiConsumer<Throwable, Object> doOnError = (error, val) -> log.error(error.getMessage(), error);
|
|
private final static BiConsumer<Throwable, Object> doOnError = (error, val) -> log.error(error.getMessage(), error);
|
|
|
|
|
|
private final static Function<DeviceOperator, Mono<Values>> configGetter = operator -> operator.getSelfConfigs(allConfigHeader);
|
|
private final static Function<DeviceOperator, Mono<Values>> configGetter = operator -> operator.getSelfConfigs(allConfigHeader);
|
|
@@ -56,7 +57,6 @@ public class DeviceMessageConnector implements DecodedClientMessageHandler {
|
|
this.registry = registry;
|
|
this.registry = registry;
|
|
this.eventBus = eventBus;
|
|
this.eventBus = eventBus;
|
|
this.messageHandler = messageHandler;
|
|
this.messageHandler = messageHandler;
|
|
- this.sessionManager = sessionManager;
|
|
|
|
sessionManager
|
|
sessionManager
|
|
.onRegister()
|
|
.onRegister()
|
|
.flatMap(session -> {
|
|
.flatMap(session -> {
|
|
@@ -118,10 +118,16 @@ public class DeviceMessageConnector implements DecodedClientMessageHandler {
|
|
.getDevice(deviceId)
|
|
.getDevice(deviceId)
|
|
.flatMap(configGetter)
|
|
.flatMap(configGetter)
|
|
.defaultIfEmpty(emptyValues)
|
|
.defaultIfEmpty(emptyValues)
|
|
- .map(configs -> {
|
|
|
|
|
|
+ .flatMapIterable(configs -> {
|
|
configs.getAllValues().forEach(deviceMessage::addHeader);
|
|
configs.getAllValues().forEach(deviceMessage::addHeader);
|
|
String productId = deviceMessage.getHeader(PropertyConstants.productId).orElse("null");
|
|
String productId = deviceMessage.getHeader(PropertyConstants.productId).orElse("null");
|
|
- return createDeviceMessageTopic(productId, deviceId, deviceMessage);
|
|
|
|
|
|
+ String topic = createDeviceMessageTopic(productId, deviceId, deviceMessage);
|
|
|
|
+ List<String> topics = new ArrayList<>(2);
|
|
|
|
+ topics.add(topic);
|
|
|
|
+ configs.getValue(PropertyConstants.orgId)
|
|
|
|
+ .ifPresent(orgId -> topics.add("/org/" + orgId + topic));
|
|
|
|
+
|
|
|
|
+ return topics;
|
|
});
|
|
});
|
|
}
|
|
}
|
|
return Mono.just("/device/unknown/message/unknown");
|
|
return Mono.just("/device/unknown/message/unknown");
|