@Override public boolean process(Exchange exchange, AsyncCallback callback) { final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class)); final CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { try { final RpcResponse response; if (ex != null) { // An exception occurred, store the exception in a new response LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { // No exception occurred, use the given response response = res; } try { exchange.getOut().setBody(module.marshalResponse(response), String.class); postProcess(exchange); } catch (Throwable t) { LOG.error("Marshalling a response in RPC module {} failed.", module, t); exchange.setException(t); exchange.getOut().setFault(true); } } finally { callback.done(false); } }); return false; }
public static String getRouteId(RpcModule<?,?> module) { return "RPC.Server." + module.getId(); }
if (request.getLocation() == null || request.getLocation().equals(location)) { return module.execute(request); KafkaRpcConstants.RPC_REQUEST_TOPIC_NAME, module.getId(), request.getLocation()); String requestTopic = topicNameFactory.getName(); String marshalRequest = module.marshalRequest(request); delayQueue.offer(responseHandler); rpcResponseMap.put(rpcId, responseHandler); kafkaConsumerRunner.startConsumingForModule(module.getId()); byte[] messageInBytes = marshalRequest.getBytes(); int totalChunks = IntMath.divide(messageInBytes.length, MAX_BUFFER_SIZE, RoundingMode.UP);
@Override public void process(Exchange exchange) throws Exception { @SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest,RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class); final JmsQueueNameFactory queueNameFactory = new JmsQueueNameFactory(CamelRpcConstants.JMS_QUEUE_PREFIX, wrapper.getModule().getId(), wrapper.getRequest().getLocation()); exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, queueNameFactory.getName()); exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT); if (wrapper.getRequest().getSystemId() != null) { exchange.getIn().setHeader(CamelRpcConstants.JMS_SYSTEM_ID_HEADER, wrapper.getRequest().getSystemId()); } final String request = wrapper.getModule().marshalRequest((RpcRequest)wrapper.getRequest()); exchange.getIn().setBody(request); } }
@Override public CompletableFuture<S> execute(R request) { return module.execute(request); } };
@Override public void sendResponse(String message) { // restore Logging context on callback. try (MDCCloseable mdc = Logging.withContextMapCloseable(loggingContext)) { // When message is not null, it's called from kafka consumer otherwise it is from timeout tracker. if (message != null) { T response = rpcModule.unmarshalResponse(message); if (response.getErrorMessage() != null) { responseFuture.completeExceptionally(new RemoteExecutionException(response.getErrorMessage())); } else { responseFuture.complete(response); } isProcessed = true; } else { responseFuture.completeExceptionally(new RequestTimedOutException(new TimeoutException())); } rpcResponseMap.remove(rpcId); messageCache.remove(rpcId); } catch (Exception e) { LOG.warn("error while handling response for RPC request id {}", rpcId, e); } }
public static String getRouteId(RpcModule<?,?> module) { return "RPC.Server." + module.getId(); }
if (request.getLocation() == null || request.getLocation().equals(location)) { return module.execute(request); KafkaRpcConstants.RPC_REQUEST_TOPIC_NAME, module.getId(), request.getLocation()); String requestTopic = topicNameFactory.getName(); String marshalRequest = module.marshalRequest(request); delayQueue.offer(responseHandler); rpcResponseMap.put(rpcId, responseHandler); kafkaConsumerRunner.startConsumingForModule(module.getId()); byte[] messageInBytes = marshalRequest.getBytes(); int totalChunks = IntMath.divide(messageInBytes.length, MAX_BUFFER_SIZE, RoundingMode.UP);
@Override public void process(Exchange exchange) throws Exception { @SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest,RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class); final JmsQueueNameFactory queueNameFactory = new JmsQueueNameFactory(CamelRpcConstants.JMS_QUEUE_PREFIX, wrapper.getModule().getId(), wrapper.getRequest().getLocation()); exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, queueNameFactory.getName()); exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT); if (wrapper.getRequest().getSystemId() != null) { exchange.getIn().setHeader(CamelRpcConstants.JMS_SYSTEM_ID_HEADER, wrapper.getRequest().getSystemId()); } final String request = wrapper.getModule().marshalRequest((RpcRequest)wrapper.getRequest()); exchange.getIn().setBody(request); } }
@Override public CompletableFuture<S> execute(R request) { return module.execute(request); } };
@Override public void sendResponse(String message) { // restore Logging context on callback. try (MDCCloseable mdc = Logging.withContextMapCloseable(loggingContext)) { // When message is not null, it's called from kafka consumer otherwise it is from timeout tracker. if (message != null) { T response = rpcModule.unmarshalResponse(message); if (response.getErrorMessage() != null) { responseFuture.completeExceptionally(new RemoteExecutionException(response.getErrorMessage())); } else { responseFuture.complete(response); } isProcessed = true; } else { responseFuture.completeExceptionally(new RequestTimedOutException(new TimeoutException())); } rpcResponseMap.remove(rpcId); messageCache.remove(rpcId); } catch (Exception e) { LOG.warn("error while handling response for RPC request id {}", rpcId, e); } }
@Override public boolean process(Exchange exchange, AsyncCallback callback) { final RpcRequest request = module.unmarshalRequest(exchange.getIn().getBody(String.class)); final CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { try { final RpcResponse response; if (ex != null) { // An exception occurred, store the exception in a new response LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { // No exception occurred, use the given response response = res; } try { exchange.getOut().setBody(module.marshalResponse(response), String.class); postProcess(exchange); } catch (Throwable t) { LOG.error("Marshalling a response in RPC module {} failed.", module, t); exchange.setException(t); exchange.getOut().setFault(true); } } finally { callback.done(false); } }); return false; }
@SuppressWarnings({ "rawtypes", "unchecked" }) public void bind(RpcModule module) throws Exception { if (module != null) { final RpcModule<RpcRequest, RpcResponse> rpcModule = (RpcModule<RpcRequest, RpcResponse>) module; if (registerdModules.containsKey(rpcModule.getId())) { LOG.warn(" {} module is already registered", rpcModule.getId()); } else { registerdModules.put(rpcModule.getId(), rpcModule); startConsumerForModule(rpcModule); } } }
@Override public void process(Exchange exchange) throws AmazonSQSQueueException { @SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest,RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class); final String requestQueueName = sqsManager.getRpcRequestQueueNameAndCreateIfNecessary( wrapper.getModule().getId(), wrapper.getRequest().getLocation()); final String replyQueueName = sqsManager.getRpcReplyQueueNameAndCreateIfNecessary( wrapper.getModule().getId(), wrapper.getRequest().getLocation()); exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, requestQueueName); exchange.getIn().setHeader(CamelRpcConstants.JMS_REPLY_TO_QUEUE_NAME_HEADER, replyQueueName); exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT); if (wrapper.getRequest().getSystemId() != null) { exchange.getIn().setHeader(CamelRpcConstants.JMS_SYSTEM_ID_HEADER, wrapper.getRequest().getSystemId()); } final String request = wrapper.getModule().marshalRequest((RpcRequest)wrapper.getRequest()); exchange.getIn().setBody(request); } }
if (request.getLocation() == null || request.getLocation().equals(location)) { return module.execute(request);
messageCache.remove(rpcId); RpcRequest request = module.unmarshalRequest(rpcContent.toStringUtf8()); CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { final RpcResponse response; if (ex != null) { LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { module.getId()); final String responseAsString = module.marshalResponse(response); final byte[] messageInBytes = responseAsString.getBytes(); int totalChunks = IntMath.divide(messageInBytes.length, maxBufferSize, RoundingMode.UP);
@SuppressWarnings({ "rawtypes", "unchecked" }) public void bind(RpcModule module) throws Exception { if (module != null) { final RpcModule<RpcRequest, RpcResponse> rpcModule = (RpcModule<RpcRequest, RpcResponse>) module; if (registerdModules.containsKey(rpcModule.getId())) { LOG.warn(" {} module is already registered", rpcModule.getId()); } else { registerdModules.put(rpcModule.getId(), rpcModule); startConsumerForModule(rpcModule); } } }
@Override public void process(Exchange exchange) throws AmazonSQSQueueException { @SuppressWarnings("unchecked") final CamelRpcRequest<RpcRequest,RpcResponse> wrapper = exchange.getIn().getBody(CamelRpcRequest.class); final String requestQueueName = sqsManager.getRpcRequestQueueNameAndCreateIfNecessary( wrapper.getModule().getId(), wrapper.getRequest().getLocation()); final String replyQueueName = sqsManager.getRpcReplyQueueNameAndCreateIfNecessary( wrapper.getModule().getId(), wrapper.getRequest().getLocation()); exchange.getIn().setHeader(CamelRpcConstants.JMS_QUEUE_NAME_HEADER, requestQueueName); exchange.getIn().setHeader(CamelRpcConstants.JMS_REPLY_TO_QUEUE_NAME_HEADER, replyQueueName); exchange.getIn().setHeader(CamelRpcConstants.CAMEL_JMS_REQUEST_TIMEOUT_HEADER, wrapper.getRequest().getTimeToLiveMs() != null ? wrapper.getRequest().getTimeToLiveMs() : CAMEL_JMS_REQUEST_TIMEOUT); if (wrapper.getRequest().getSystemId() != null) { exchange.getIn().setHeader(CamelRpcConstants.JMS_SYSTEM_ID_HEADER, wrapper.getRequest().getSystemId()); } final String request = wrapper.getModule().marshalRequest((RpcRequest)wrapper.getRequest()); exchange.getIn().setBody(request); } }
if (request.getLocation() == null || request.getLocation().equals(location)) { return module.execute(request);
messageCache.remove(rpcId); RpcRequest request = module.unmarshalRequest(rpcContent.toStringUtf8()); CompletableFuture<RpcResponse> future = module.execute(request); future.whenComplete((res, ex) -> { final RpcResponse response; if (ex != null) { LOG.warn("An error occured while executing a call in {}.", module.getId(), ex); response = module.createResponseWithException(ex); } else { module.getId()); final String responseAsString = module.marshalResponse(response); final byte[] messageInBytes = responseAsString.getBytes(); int totalChunks = IntMath.divide(messageInBytes.length, maxBufferSize, RoundingMode.UP);