used timeout from yml
This commit is contained in:
parent
5d6ec0dd0e
commit
2a2441b248
@ -199,7 +199,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId());
|
log.debug("[{}][{}] device is related to edge [{}]. Saving RPC request to edge queue", tenantId, deviceId, edgeId.getId());
|
||||||
saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId());
|
saveRpcRequestToEdgeQueue(request, rpcRequest.getRequestId());
|
||||||
sent = true;
|
sent = true;
|
||||||
} else if (!rpcSequenceEnabled || toDeviceRpcPendingMap.isEmpty()) {
|
} else if (isSendNewRpcAvailable()) {
|
||||||
sent = rpcSubscriptions.size() > 0;
|
sent = rpcSubscriptions.size() > 0;
|
||||||
Set<UUID> syncSessionSet = new HashSet<>();
|
Set<UUID> syncSessionSet = new HashSet<>();
|
||||||
rpcSubscriptions.forEach((key, value) -> {
|
rpcSubscriptions.forEach((key, value) -> {
|
||||||
@ -231,6 +231,18 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isSendNewRpcAvailable() {
|
||||||
|
if (rpcSequenceEnabled) {
|
||||||
|
for (ToDeviceRpcRequestMetadata rpc : toDeviceRpcPendingMap.values()) {
|
||||||
|
if (!rpc.isDelivered()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
private Rpc createRpc(ToDeviceRpcRequest request, RpcStatus status) {
|
private Rpc createRpc(ToDeviceRpcRequest request, RpcStatus status) {
|
||||||
Rpc rpc = new Rpc(new RpcId(request.getId()));
|
Rpc rpc = new Rpc(new RpcId(request.getId()));
|
||||||
rpc.setCreatedTime(System.currentTimeMillis());
|
rpc.setCreatedTime(System.currentTimeMillis());
|
||||||
@ -347,7 +359,6 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
.setMethodName(body.getMethod())
|
.setMethodName(body.getMethod())
|
||||||
.setParams(body.getParams())
|
.setParams(body.getParams())
|
||||||
.setExpirationTime(request.getExpirationTime())
|
.setExpirationTime(request.getExpirationTime())
|
||||||
.setTimeout(request.getTimeout())
|
|
||||||
.setRequestIdMSB(request.getId().getMostSignificantBits())
|
.setRequestIdMSB(request.getId().getMostSignificantBits())
|
||||||
.setRequestIdLSB(request.getId().getLeastSignificantBits())
|
.setRequestIdLSB(request.getId().getLeastSignificantBits())
|
||||||
.setOneway(request.isOneway())
|
.setOneway(request.isOneway())
|
||||||
@ -563,7 +574,7 @@ class DeviceActorMessageProcessor extends AbstractContextAwareMsgProcessor {
|
|||||||
systemContext.getTbRpcService().save(tenantId, new RpcId(requestMd.getMsg().getMsg().getId()), status, response);
|
systemContext.getTbRpcService().save(tenantId, new RpcId(requestMd.getMsg().getMsg().getId()), status, response);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
if (!requestMd.isDelivered() && hasError) {
|
if (hasError) {
|
||||||
sendNextPendingRequest(context);
|
sendNextPendingRequest(context);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -88,7 +88,6 @@ public abstract class AbstractRpcController extends BaseController {
|
|||||||
deviceId,
|
deviceId,
|
||||||
oneWay,
|
oneWay,
|
||||||
expTime,
|
expTime,
|
||||||
timeout,
|
|
||||||
body,
|
body,
|
||||||
persisted,
|
persisted,
|
||||||
additionalInfo
|
additionalInfo
|
||||||
|
|||||||
@ -101,7 +101,7 @@ public class DefaultTbRuleEngineRpcService implements TbRuleEngineDeviceRpcServi
|
|||||||
@Override
|
@Override
|
||||||
public void sendRpcRequestToDevice(RuleEngineDeviceRpcRequest src, Consumer<RuleEngineDeviceRpcResponse> consumer) {
|
public void sendRpcRequestToDevice(RuleEngineDeviceRpcRequest src, Consumer<RuleEngineDeviceRpcResponse> consumer) {
|
||||||
ToDeviceRpcRequest request = new ToDeviceRpcRequest(src.getRequestUUID(), src.getTenantId(), src.getDeviceId(),
|
ToDeviceRpcRequest request = new ToDeviceRpcRequest(src.getRequestUUID(), src.getTenantId(), src.getDeviceId(),
|
||||||
src.isOneway(), src.getExpirationTime(), src.getTimeout(), new ToDeviceRpcRequestBody(src.getMethod(), src.getBody()), src.isPersisted(), src.getAdditionalInfo());
|
src.isOneway(), src.getExpirationTime(), new ToDeviceRpcRequestBody(src.getMethod(), src.getBody()), src.isPersisted(), src.getAdditionalInfo());
|
||||||
forwardRpcRequestToDeviceActor(request, response -> {
|
forwardRpcRequestToDeviceActor(request, response -> {
|
||||||
if (src.isRestApiCall()) {
|
if (src.isRestApiCall()) {
|
||||||
sendRpcResponseToTbCore(src.getOriginServiceId(), response);
|
sendRpcResponseToTbCore(src.getOriginServiceId(), response);
|
||||||
|
|||||||
@ -334,7 +334,6 @@ message ToDeviceRpcRequestMsg {
|
|||||||
int64 requestIdLSB = 6;
|
int64 requestIdLSB = 6;
|
||||||
bool oneway = 7;
|
bool oneway = 7;
|
||||||
bool persisted = 8;
|
bool persisted = 8;
|
||||||
int64 timeout = 9;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
message ToDeviceRpcResponseMsg {
|
message ToDeviceRpcResponseMsg {
|
||||||
|
|||||||
@ -87,9 +87,11 @@ public class DataConstants {
|
|||||||
public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE";
|
public static final String RPC_CALL_FROM_SERVER_TO_DEVICE = "RPC_CALL_FROM_SERVER_TO_DEVICE";
|
||||||
|
|
||||||
public static final String RPC_QUEUED = "RPC_QUEUED";
|
public static final String RPC_QUEUED = "RPC_QUEUED";
|
||||||
|
public static final String RPC_SENT = "RPC_SENT";
|
||||||
public static final String RPC_DELIVERED = "RPC_DELIVERED";
|
public static final String RPC_DELIVERED = "RPC_DELIVERED";
|
||||||
public static final String RPC_SUCCESSFUL = "RPC_SUCCESSFUL";
|
public static final String RPC_SUCCESSFUL = "RPC_SUCCESSFUL";
|
||||||
public static final String RPC_TIMEOUT = "RPC_TIMEOUT";
|
public static final String RPC_TIMEOUT = "RPC_TIMEOUT";
|
||||||
|
public static final String RPC_EXPIRED = "RPC_EXPIRED";
|
||||||
public static final String RPC_FAILED = "RPC_FAILED";
|
public static final String RPC_FAILED = "RPC_FAILED";
|
||||||
public static final String RPC_DELETED = "RPC_DELETED";
|
public static final String RPC_DELETED = "RPC_DELETED";
|
||||||
|
|
||||||
|
|||||||
@ -34,7 +34,6 @@ public class ToDeviceRpcRequest implements Serializable {
|
|||||||
private final DeviceId deviceId;
|
private final DeviceId deviceId;
|
||||||
private final boolean oneway;
|
private final boolean oneway;
|
||||||
private final long expirationTime;
|
private final long expirationTime;
|
||||||
private final long timeout;
|
|
||||||
private final ToDeviceRpcRequestBody body;
|
private final ToDeviceRpcRequestBody body;
|
||||||
private final boolean persisted;
|
private final boolean persisted;
|
||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
|
|||||||
@ -193,29 +193,7 @@ public class DefaultCoapClientContext implements CoapClientContext {
|
|||||||
client.lock();
|
client.lock();
|
||||||
try {
|
try {
|
||||||
long uplinkTime = client.updateLastUplinkTime(uplinkTs);
|
long uplinkTime = client.updateLastUplinkTime(uplinkTs);
|
||||||
long timeout;
|
long timeout = getTimeout(client, powerMode, profileSettings);
|
||||||
if (PowerMode.PSM.equals(powerMode)) {
|
|
||||||
Long psmActivityTimer = client.getPsmActivityTimer();
|
|
||||||
if (psmActivityTimer == null && profileSettings != null) {
|
|
||||||
psmActivityTimer = profileSettings.getPsmActivityTimer();
|
|
||||||
|
|
||||||
}
|
|
||||||
if (psmActivityTimer == null || psmActivityTimer == 0L) {
|
|
||||||
psmActivityTimer = config.getPsmActivityTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
timeout = psmActivityTimer;
|
|
||||||
} else {
|
|
||||||
Long pagingTransmissionWindow = client.getPagingTransmissionWindow();
|
|
||||||
if (pagingTransmissionWindow == null && profileSettings != null) {
|
|
||||||
pagingTransmissionWindow = profileSettings.getPagingTransmissionWindow();
|
|
||||||
|
|
||||||
}
|
|
||||||
if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) {
|
|
||||||
pagingTransmissionWindow = config.getPagingTransmissionWindow();
|
|
||||||
}
|
|
||||||
timeout = pagingTransmissionWindow;
|
|
||||||
}
|
|
||||||
Future<Void> sleepTask = client.getSleepTask();
|
Future<Void> sleepTask = client.getSleepTask();
|
||||||
if (sleepTask != null) {
|
if (sleepTask != null) {
|
||||||
sleepTask.cancel(false);
|
sleepTask.cancel(false);
|
||||||
@ -235,6 +213,33 @@ public class DefaultCoapClientContext implements CoapClientContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private long getTimeout(TbCoapClientState client, PowerMode powerMode, PowerSavingConfiguration profileSettings) {
|
||||||
|
long timeout;
|
||||||
|
if (PowerMode.PSM.equals(powerMode)) {
|
||||||
|
Long psmActivityTimer = client.getPsmActivityTimer();
|
||||||
|
if (psmActivityTimer == null && profileSettings != null) {
|
||||||
|
psmActivityTimer = profileSettings.getPsmActivityTimer();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (psmActivityTimer == null || psmActivityTimer == 0L) {
|
||||||
|
psmActivityTimer = config.getPsmActivityTimer();
|
||||||
|
}
|
||||||
|
|
||||||
|
timeout = psmActivityTimer;
|
||||||
|
} else {
|
||||||
|
Long pagingTransmissionWindow = client.getPagingTransmissionWindow();
|
||||||
|
if (pagingTransmissionWindow == null && profileSettings != null) {
|
||||||
|
pagingTransmissionWindow = profileSettings.getPagingTransmissionWindow();
|
||||||
|
|
||||||
|
}
|
||||||
|
if (pagingTransmissionWindow == null || pagingTransmissionWindow == 0L) {
|
||||||
|
pagingTransmissionWindow = config.getPagingTransmissionWindow();
|
||||||
|
}
|
||||||
|
timeout = pagingTransmissionWindow;
|
||||||
|
}
|
||||||
|
return timeout;
|
||||||
|
}
|
||||||
|
|
||||||
private boolean registerFeatureObservation(TbCoapClientState state, String token, CoapExchange exchange, FeatureType featureType) {
|
private boolean registerFeatureObservation(TbCoapClientState state, String token, CoapExchange exchange, FeatureType featureType) {
|
||||||
state.lock();
|
state.lock();
|
||||||
try {
|
try {
|
||||||
@ -526,13 +531,25 @@ public class DefaultCoapClientContext implements CoapClientContext {
|
|||||||
int requestId = getNextMsgId();
|
int requestId = getNextMsgId();
|
||||||
response.setMID(requestId);
|
response.setMID(requestId);
|
||||||
if (conRequest) {
|
if (conRequest) {
|
||||||
|
PowerMode powerMode = state.getPowerMode();
|
||||||
|
PowerSavingConfiguration profileSettings = null;
|
||||||
|
if (powerMode == null) {
|
||||||
|
var clientProfile = getProfile(state.getProfileId());
|
||||||
|
if (clientProfile.isPresent()) {
|
||||||
|
profileSettings = clientProfile.get().getClientSettings();
|
||||||
|
if (profileSettings != null) {
|
||||||
|
powerMode = profileSettings.getPowerMode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
transportContext.getRpcAwaitingAck().put(requestId, msg);
|
transportContext.getRpcAwaitingAck().put(requestId, msg);
|
||||||
transportContext.getScheduler().schedule(() -> {
|
transportContext.getScheduler().schedule(() -> {
|
||||||
TransportProtos.ToDeviceRpcRequestMsg rpcRequestMsg = transportContext.getRpcAwaitingAck().remove(requestId);
|
TransportProtos.ToDeviceRpcRequestMsg rpcRequestMsg = transportContext.getRpcAwaitingAck().remove(requestId);
|
||||||
if (rpcRequestMsg != null) {
|
if (rpcRequestMsg != null) {
|
||||||
transportService.process(state.getSession(), msg, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY);
|
transportService.process(state.getSession(), msg, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY);
|
||||||
}
|
}
|
||||||
}, Math.max(0, Math.min(msg.getTimeout(), msg.getExpirationTime() - System.currentTimeMillis())), TimeUnit.MILLISECONDS);
|
}, Math.min(getTimeout(state, powerMode, profileSettings), msg.getExpirationTime() - System.currentTimeMillis()), TimeUnit.MILLISECONDS);
|
||||||
|
|
||||||
response.addMessageObserver(new TbCoapMessageObserver(requestId, id -> {
|
response.addMessageObserver(new TbCoapMessageObserver(requestId, id -> {
|
||||||
TransportProtos.ToDeviceRpcRequestMsg rpcRequestMsg = transportContext.getRpcAwaitingAck().remove(id);
|
TransportProtos.ToDeviceRpcRequestMsg rpcRequestMsg = transportContext.getRpcAwaitingAck().remove(id);
|
||||||
|
|||||||
@ -68,4 +68,7 @@ public class MqttTransportContext extends TransportContext {
|
|||||||
@Value("${transport.mqtt.msg_queue_size_per_device_limit:100}")
|
@Value("${transport.mqtt.msg_queue_size_per_device_limit:100}")
|
||||||
private int messageQueueSizePerDeviceLimit;
|
private int messageQueueSizePerDeviceLimit;
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
@Value("${transport.mqtt.timeout:10000}")
|
||||||
|
private long timeout;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -857,7 +857,7 @@ public class MqttTransportHandler extends ChannelInboundHandlerAdapter implement
|
|||||||
if (msg != null) {
|
if (msg != null) {
|
||||||
transportService.process(deviceSessionCtx.getSessionInfo(), rpcRequest, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY);
|
transportService.process(deviceSessionCtx.getSessionInfo(), rpcRequest, RpcStatus.TIMEOUT, TransportServiceCallback.EMPTY);
|
||||||
}
|
}
|
||||||
}, Math.max(0, Math.min(rpcRequest.getTimeout(), rpcRequest.getExpirationTime() - System.currentTimeMillis())), TimeUnit.MILLISECONDS);
|
}, Math.max(0, Math.min(deviceSessionCtx.getContext().getTimeout(), rpcRequest.getExpirationTime() - System.currentTimeMillis())), TimeUnit.MILLISECONDS);
|
||||||
}
|
}
|
||||||
var cf = publish(payload, deviceSessionCtx);
|
var cf = publish(payload, deviceSessionCtx);
|
||||||
cf.addListener(result -> {
|
cf.addListener(result -> {
|
||||||
|
|||||||
@ -39,7 +39,6 @@ public final class RuleEngineDeviceRpcRequest {
|
|||||||
private final String method;
|
private final String method;
|
||||||
private final String body;
|
private final String body;
|
||||||
private final long expirationTime;
|
private final long expirationTime;
|
||||||
private final long timeout;
|
|
||||||
private final boolean restApiCall;
|
private final boolean restApiCall;
|
||||||
private final String additionalInfo;
|
private final String additionalInfo;
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ import org.thingsboard.server.common.msg.session.SessionMsgType;
|
|||||||
type = ComponentType.FILTER,
|
type = ComponentType.FILTER,
|
||||||
name = "message type switch",
|
name = "message type switch",
|
||||||
configClazz = EmptyNodeConfiguration.class,
|
configClazz = EmptyNodeConfiguration.class,
|
||||||
relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "RPC Queued", "RPC Delivered", "RPC Successful", "RPC Timeout", "RPC Failed", "RPC Deleted",
|
relationTypes = {"Post attributes", "Post telemetry", "RPC Request from Device", "RPC Request to Device", "RPC Queued", "RPC Sent", "RPC Delivered", "RPC Successful", "RPC Timeout", "RPC Expired", "RPC Failed", "RPC Deleted",
|
||||||
"Activity Event", "Inactivity Event", "Connect Event", "Disconnect Event", "Entity Created", "Entity Updated", "Entity Deleted", "Entity Assigned",
|
"Activity Event", "Inactivity Event", "Connect Event", "Disconnect Event", "Entity Created", "Entity Updated", "Entity Deleted", "Entity Assigned",
|
||||||
"Entity Unassigned", "Attributes Updated", "Attributes Deleted", "Alarm Acknowledged", "Alarm Cleared", "Other", "Entity Assigned From Tenant", "Entity Assigned To Tenant",
|
"Entity Unassigned", "Attributes Updated", "Attributes Deleted", "Alarm Acknowledged", "Alarm Cleared", "Other", "Entity Assigned From Tenant", "Entity Assigned To Tenant",
|
||||||
"Timeseries Updated", "Timeseries Deleted"},
|
"Timeseries Updated", "Timeseries Deleted"},
|
||||||
@ -97,12 +97,16 @@ public class TbMsgTypeSwitchNode implements TbNode {
|
|||||||
relationType = "Timeseries Deleted";
|
relationType = "Timeseries Deleted";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_QUEUED)) {
|
} else if (msg.getType().equals(DataConstants.RPC_QUEUED)) {
|
||||||
relationType = "RPC Queued";
|
relationType = "RPC Queued";
|
||||||
|
} else if (msg.getType().equals(DataConstants.RPC_SENT)) {
|
||||||
|
relationType = "RPC Sent";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_DELIVERED)) {
|
} else if (msg.getType().equals(DataConstants.RPC_DELIVERED)) {
|
||||||
relationType = "RPC Delivered";
|
relationType = "RPC Delivered";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_SUCCESSFUL)) {
|
} else if (msg.getType().equals(DataConstants.RPC_SUCCESSFUL)) {
|
||||||
relationType = "RPC Successful";
|
relationType = "RPC Successful";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_TIMEOUT)) {
|
} else if (msg.getType().equals(DataConstants.RPC_TIMEOUT)) {
|
||||||
relationType = "RPC Timeout";
|
relationType = "RPC Timeout";
|
||||||
|
} else if (msg.getType().equals(DataConstants.RPC_EXPIRED)) {
|
||||||
|
relationType = "RPC Expired";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_FAILED)) {
|
} else if (msg.getType().equals(DataConstants.RPC_FAILED)) {
|
||||||
relationType = "RPC Failed";
|
relationType = "RPC Failed";
|
||||||
} else if (msg.getType().equals(DataConstants.RPC_DELETED)) {
|
} else if (msg.getType().equals(DataConstants.RPC_DELETED)) {
|
||||||
|
|||||||
@ -92,9 +92,6 @@ public class TbSendRPCRequestNode implements TbNode {
|
|||||||
tmp = msg.getMetaData().getValue(DataConstants.EXPIRATION_TIME);
|
tmp = msg.getMetaData().getValue(DataConstants.EXPIRATION_TIME);
|
||||||
long expirationTime = !StringUtils.isEmpty(tmp) ? Long.parseLong(tmp) : (System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(config.getTimeoutInSeconds()));
|
long expirationTime = !StringUtils.isEmpty(tmp) ? Long.parseLong(tmp) : (System.currentTimeMillis() + TimeUnit.SECONDS.toMillis(config.getTimeoutInSeconds()));
|
||||||
|
|
||||||
tmp = msg.getMetaData().getValue(DataConstants.TIMEOUT);
|
|
||||||
long timeout = !StringUtils.isEmpty(tmp) ? Long.parseLong(tmp) : TimeUnit.SECONDS.toMillis(config.getTimeoutInSeconds());
|
|
||||||
|
|
||||||
String params;
|
String params;
|
||||||
JsonElement paramsEl = json.get("params");
|
JsonElement paramsEl = json.get("params");
|
||||||
if (paramsEl.isJsonPrimitive()) {
|
if (paramsEl.isJsonPrimitive()) {
|
||||||
@ -115,7 +112,6 @@ public class TbSendRPCRequestNode implements TbNode {
|
|||||||
.requestUUID(requestUUID)
|
.requestUUID(requestUUID)
|
||||||
.originServiceId(originServiceId)
|
.originServiceId(originServiceId)
|
||||||
.expirationTime(expirationTime)
|
.expirationTime(expirationTime)
|
||||||
.timeout(timeout)
|
|
||||||
.restApiCall(restApiCall)
|
.restApiCall(restApiCall)
|
||||||
.persisted(persisted)
|
.persisted(persisted)
|
||||||
.additionalInfo(additionalInfo)
|
.additionalInfo(additionalInfo)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user