Browse Source

execute processMsgQueue on connected callback in separate thread because producer.send() will execute in Producer worker thread and can block messages producing

pull/5039/head
Sergey Matvienko 5 years ago
committed by Andrew Shvayka
parent
commit
cbe51cee57
  1. 2
      common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java
  2. 4
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/TransportService.java
  3. 5
      common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

2
common/transport/mqtt/src/main/java/org/thingsboard/server/transport/mqtt/MqttTransportHandler.java

@ -825,7 +825,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
ctx.writeAndFlush(createMqttConnAckMsg(CONNECTION_ACCEPTED, connectMessage));
deviceSessionCtx.setConnected(true);
log.info("[{}] Client connected!", sessionId);
processMsgQueue(ctx);
transportService.getCallbackExecutor().execute(() -> processMsgQueue(ctx)); //this callback will execute in Producer worker thread and hard or blocking work have to be submitted to the separate thread.
}
@Override

4
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/TransportService.java

@ -56,6 +56,8 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MC
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceTokenRequestMsg;
import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceX509CertRequestMsg;
import java.util.concurrent.ExecutorService;
/**
* Created by ashvayka on 04.10.18.
*/
@ -131,4 +133,6 @@ public interface TransportService {
void log(SessionInfoProto sessionInfo, String msg);
void notifyAboutUplink(SessionInfoProto sessionInfo, TransportProtos.UplinkNotificationMsg build, TransportServiceCallback<Void> empty);
ExecutorService getCallbackExecutor();
}

5
common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/service/DefaultTransportService.java

@ -1141,4 +1141,9 @@ public class DefaultTransportService implements TransportService {
callback.onError(e);
}
}
@Override
public ExecutorService getCallbackExecutor() {
return transportCallbackExecutor;
}
}

Loading…
Cancel
Save