Min RPC timeout
This commit is contained in:
parent
28f1993a7c
commit
e823dfb85d
@ -20,6 +20,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||||||
import com.google.common.util.concurrent.FutureCallback;
|
import com.google.common.util.concurrent.FutureCallback;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -65,7 +66,6 @@ import java.util.UUID;
|
|||||||
@Slf4j
|
@Slf4j
|
||||||
public class RpcController extends BaseController {
|
public class RpcController extends BaseController {
|
||||||
|
|
||||||
public static final int DEFAULT_TIMEOUT = 10000;
|
|
||||||
protected final ObjectMapper jsonMapper = new ObjectMapper();
|
protected final ObjectMapper jsonMapper = new ObjectMapper();
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
@ -74,6 +74,12 @@ public class RpcController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private AccessValidator accessValidator;
|
private AccessValidator accessValidator;
|
||||||
|
|
||||||
|
@Value("${server.rest.server_side_rpc.min_timeout:5000}")
|
||||||
|
private long minTimeout;
|
||||||
|
|
||||||
|
@Value("${server.rest.server_side_rpc.default_timeout:10000}")
|
||||||
|
private long defaultTimeout;
|
||||||
|
|
||||||
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
|
||||||
@RequestMapping(value = "/oneway/{deviceId}", method = RequestMethod.POST)
|
@RequestMapping(value = "/oneway/{deviceId}", method = RequestMethod.POST)
|
||||||
@ResponseBody
|
@ResponseBody
|
||||||
@ -100,7 +106,8 @@ public class RpcController extends BaseController {
|
|||||||
SecurityUser currentUser = getCurrentUser();
|
SecurityUser currentUser = getCurrentUser();
|
||||||
TenantId tenantId = currentUser.getTenantId();
|
TenantId tenantId = currentUser.getTenantId();
|
||||||
final DeferredResult<ResponseEntity> response = new DeferredResult<>();
|
final DeferredResult<ResponseEntity> response = new DeferredResult<>();
|
||||||
long timeout = System.currentTimeMillis() + (cmd.getTimeout() != null ? cmd.getTimeout() : DEFAULT_TIMEOUT);
|
long timeout = cmd.getTimeout() != null ? cmd.getTimeout() : defaultTimeout;
|
||||||
|
long expTime = System.currentTimeMillis() + Math.max(minTimeout, timeout);
|
||||||
ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
|
ToDeviceRpcRequestBody body = new ToDeviceRpcRequestBody(cmd.getMethodName(), cmd.getRequestData());
|
||||||
accessValidator.validate(currentUser, Operation.RPC_CALL, deviceId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {
|
accessValidator.validate(currentUser, Operation.RPC_CALL, deviceId, new HttpValidationCallback(response, new FutureCallback<DeferredResult<ResponseEntity>>() {
|
||||||
@Override
|
@Override
|
||||||
@ -109,7 +116,7 @@ public class RpcController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
deviceId,
|
deviceId,
|
||||||
oneWay,
|
oneWay,
|
||||||
timeout,
|
expTime,
|
||||||
body
|
body
|
||||||
);
|
);
|
||||||
deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse));
|
deviceRpcService.processRestApiRpcRequest(rpcRequest, fromDeviceRpcResponse -> reply(new LocalRequestMetaData(rpcRequest, currentUser, result), fromDeviceRpcResponse));
|
||||||
|
|||||||
@ -54,6 +54,13 @@ server:
|
|||||||
customer:
|
customer:
|
||||||
enabled: "${TB_SERVER_REST_LIMITS_CUSTOMER_ENABLED:false}"
|
enabled: "${TB_SERVER_REST_LIMITS_CUSTOMER_ENABLED:false}"
|
||||||
configuration: "${TB_SERVER_REST_LIMITS_CUSTOMER_CONFIGURATION:50:1,1000:60}"
|
configuration: "${TB_SERVER_REST_LIMITS_CUSTOMER_CONFIGURATION:50:1,1000:60}"
|
||||||
|
server_side_rpc:
|
||||||
|
# Minimum value of the server side RPC timeout. May override value provided in the REST API call.
|
||||||
|
# Since 2.5 migration to queues, the RPC delay depends on the size of the pending messages in the queue,
|
||||||
|
# so default UI parameter of 500ms may not be sufficient for loaded environments.
|
||||||
|
min_timeout: "${MIN_SERVER_SIDE_RPC_TIMEOUT:5000}"
|
||||||
|
# Default value of the server side RPC timeout.
|
||||||
|
default_timeout: "${DEFAULT_SERVER_SIDE_RPC_TIMEOUT:10000}"
|
||||||
|
|
||||||
# Zookeeper connection parameters. Used for service discovery.
|
# Zookeeper connection parameters. Used for service discovery.
|
||||||
zk:
|
zk:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user