@Test public void testReceiveCommandHandlesCommandWithCallbackFails() throws Exception { doThrow(RuntimeException.class).when(localCommandBus).dispatch(any(), any()); SpringHttpReplyMessage<String> result = (SpringHttpReplyMessage<String>) testSubject.receiveCommand(buildDispatchMessage(true)).get(); CommandResultMessage<String> commandResultMessage = result.getCommandResultMessage(serializer); assertEquals(COMMAND_MESSAGE.getIdentifier(), result.getCommandIdentifier()); assertTrue(commandResultMessage.isExceptional()); verify(localCommandBus).dispatch(any(), any()); }
@PostMapping("/command") public <C, R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage) { CommandMessage<C> commandMessage = dispatchMessage.getCommandMessage(serializer); if (dispatchMessage.isExpectReply()) { try { SpringHttpReplyFutureCallback<C, R> replyFutureCallback = new SpringHttpReplyFutureCallback<>(); localCommandBus.dispatch(commandMessage, replyFutureCallback); return replyFutureCallback; } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } else { try { localCommandBus.dispatch(commandMessage); return CompletableFuture.completedFuture(""); } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } }
SpringHttpCommandBusConnector implements CommandBusConnector { @PostMapping("/command") public <C, R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage) { CommandMessage<C> commandMessage = dispatchMessage.getCommandMessage(serializer); if (dispatchMessage.isExpectReply()) { try { SpringHttpReplyFutureCallback<C, R> replyFutureCallback = new SpringHttpReplyFutureCallback<>(); localCommandBus.dispatch(commandMessage, replyFutureCallback); return replyFutureCallback; } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } else { try { localCommandBus.dispatch(commandMessage); return CompletableFuture.completedFuture(""); } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } } }
SpringHttpCommandBusConnector implements CommandBusConnector { @PostMapping("/command") public <C, R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage) { CommandMessage<C> commandMessage = dispatchMessage.getCommandMessage(serializer); if (dispatchMessage.isExpectReply()) { try { SpringHttpReplyFutureCallback<C, R> replyFutureCallback = new SpringHttpReplyFutureCallback<>(); localCommandBus.dispatch(commandMessage, replyFutureCallback); return replyFutureCallback; } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } else { try { localCommandBus.dispatch(commandMessage); return CompletableFuture.completedFuture(""); } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } } protected  SpringHttpCommandBusConnector(Builder builder); }
SpringHttpCommandBusConnector implements CommandBusConnector { @PostMapping("/command") public <C, R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage) { CommandMessage<C> commandMessage = dispatchMessage.getCommandMessage(serializer); if (dispatchMessage.isExpectReply()) { try { SpringHttpReplyFutureCallback<C, R> replyFutureCallback = new SpringHttpReplyFutureCallback<>(); localCommandBus.dispatch(commandMessage, replyFutureCallback); return replyFutureCallback; } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } else { try { localCommandBus.dispatch(commandMessage); return CompletableFuture.completedFuture(""); } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } } protected  SpringHttpCommandBusConnector(Builder builder); @StartHandler(phase = Phase.EXTERNAL_CONNECTIONS) void start(); static Builder builder(); @Override void send(Member destination, CommandMessage<? extends C> commandMessage); @Override void send(Member destination,
                            CommandMessage<C> commandMessage,
                            CommandCallback<? super C, R> callback); @Override CompletableFuture<Void> initiateShutdown(); @Override Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler); @Override Optional<CommandBus> localSegment(); @PostMapping("/command") CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage); @Override Registration registerHandlerInterceptor(
            MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor); }
SpringHttpCommandBusConnector implements CommandBusConnector { @PostMapping("/command") public <C, R> CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage) { CommandMessage<C> commandMessage = dispatchMessage.getCommandMessage(serializer); if (dispatchMessage.isExpectReply()) { try { SpringHttpReplyFutureCallback<C, R> replyFutureCallback = new SpringHttpReplyFutureCallback<>(); localCommandBus.dispatch(commandMessage, replyFutureCallback); return replyFutureCallback; } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } else { try { localCommandBus.dispatch(commandMessage); return CompletableFuture.completedFuture(""); } catch (Exception e) { logger.error("Could not dispatch command", e); return CompletableFuture.completedFuture(createReply(commandMessage, asCommandResultMessage(e))); } } } protected  SpringHttpCommandBusConnector(Builder builder); @StartHandler(phase = Phase.EXTERNAL_CONNECTIONS) void start(); static Builder builder(); @Override void send(Member destination, CommandMessage<? extends C> commandMessage); @Override void send(Member destination,
                            CommandMessage<C> commandMessage,
                            CommandCallback<? super C, R> callback); @Override CompletableFuture<Void> initiateShutdown(); @Override Registration subscribe(String commandName, MessageHandler<? super CommandMessage<?>> handler); @Override Optional<CommandBus> localSegment(); @PostMapping("/command") CompletableFuture<?> receiveCommand(@RequestBody SpringHttpDispatchMessage<C> dispatchMessage); @Override Registration registerHandlerInterceptor(
            MessageHandlerInterceptor<? super CommandMessage<?>> handlerInterceptor);  }