refactoring mqtt
This commit is contained in:
parent
331548bfa7
commit
1f31bd7d18
@ -51,6 +51,8 @@ import javax.security.cert.X509Certificate;
|
|||||||
import java.net.InetSocketAddress;
|
import java.net.InetSocketAddress;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
import static io.netty.handler.codec.mqtt.MqttConnectReturnCode.*;
|
||||||
import static io.netty.handler.codec.mqtt.MqttMessageType.*;
|
import static io.netty.handler.codec.mqtt.MqttMessageType.*;
|
||||||
@ -79,6 +81,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
private volatile InetSocketAddress address;
|
private volatile InetSocketAddress address;
|
||||||
private volatile GatewaySessionCtx gatewaySessionCtx;
|
private volatile GatewaySessionCtx gatewaySessionCtx;
|
||||||
|
|
||||||
|
private Map<String,MqttQoS> mqttQoSMap = new ConcurrentHashMap<>();
|
||||||
|
|
||||||
public MqttTransportHandler(SessionMsgProcessor processor, DeviceService deviceService, DeviceAuthService authService, RelationService relationService,
|
public MqttTransportHandler(SessionMsgProcessor processor, DeviceService deviceService, DeviceAuthService authService, RelationService relationService,
|
||||||
MqttTransportAdaptor adaptor, SslHandler sslHandler, QuotaService quotaService) {
|
MqttTransportAdaptor adaptor, SslHandler sslHandler, QuotaService quotaService) {
|
||||||
this.processor = processor;
|
this.processor = processor;
|
||||||
@ -228,6 +232,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
String topicName = subscription.topicName();
|
String topicName = subscription.topicName();
|
||||||
//TODO: handle this qos level.
|
//TODO: handle this qos level.
|
||||||
MqttQoS reqQoS = subscription.qualityOfService();
|
MqttQoS reqQoS = subscription.qualityOfService();
|
||||||
|
mqttQoSMap.put(topicName, reqQoS);
|
||||||
try {
|
try {
|
||||||
if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
|
if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
|
||||||
AdaptorToSessionActorMsg msg = adaptor.convertToActorMsg(deviceSessionCtx, SUBSCRIBE_ATTRIBUTES_REQUEST, mqttMsg);
|
AdaptorToSessionActorMsg msg = adaptor.convertToActorMsg(deviceSessionCtx, SUBSCRIBE_ATTRIBUTES_REQUEST, mqttMsg);
|
||||||
@ -244,6 +249,8 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
grantedQoSList.add(getMinSupportedQos(reqQoS));
|
grantedQoSList.add(getMinSupportedQos(reqQoS));
|
||||||
} else if (topicName.equals(GATEWAY_ATTRIBUTES_TOPIC)) {
|
} else if (topicName.equals(GATEWAY_ATTRIBUTES_TOPIC)) {
|
||||||
grantedQoSList.add(getMinSupportedQos(reqQoS));
|
grantedQoSList.add(getMinSupportedQos(reqQoS));
|
||||||
|
}else if (topicName.equals(GATEWAY_RPC_TOPIC)) {
|
||||||
|
grantedQoSList.add(getMinSupportedQos(reqQoS));
|
||||||
} else {
|
} else {
|
||||||
log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
|
log.warn("[{}] Failed to subscribe to [{}][{}]", sessionId, topicName, reqQoS);
|
||||||
grantedQoSList.add(FAILURE.value());
|
grantedQoSList.add(FAILURE.value());
|
||||||
@ -262,6 +269,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
}
|
}
|
||||||
log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId());
|
log.trace("[{}] Processing subscription [{}]!", sessionId, mqttMsg.variableHeader().messageId());
|
||||||
for (String topicName : mqttMsg.payload().topics()) {
|
for (String topicName : mqttMsg.payload().topics()) {
|
||||||
|
mqttQoSMap.remove(topicName);
|
||||||
try {
|
try {
|
||||||
if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
|
if (topicName.equals(DEVICE_ATTRIBUTES_TOPIC)) {
|
||||||
AdaptorToSessionActorMsg msg = adaptor.convertToActorMsg(deviceSessionCtx, UNSUBSCRIBE_ATTRIBUTES_REQUEST, mqttMsg);
|
AdaptorToSessionActorMsg msg = adaptor.convertToActorMsg(deviceSessionCtx, UNSUBSCRIBE_ATTRIBUTES_REQUEST, mqttMsg);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user