@Override public String getRoutingKey(CommandMessage<?> command) { String routingKey = doResolveRoutingKey(command); if (routingKey == null) { switch (unresolvedRoutingKeyPolicy) { case ERROR: throw new CommandDispatchException(format("The command [%s] does not contain a routing key.", command.getCommandName())); case RANDOM_KEY: return Long.toHexString(counter.getAndIncrement()); case STATIC_KEY: return STATIC_ROUTING_KEY; default: throw new IllegalStateException("The configured UnresolvedRoutingPolicy of " + unresolvedRoutingKeyPolicy.name() + " is not supported."); } } return routingKey; }
@Override public <C> void dispatch(CommandMessage<C> command) { LoggingCallback loggingCallback = LoggingCallback.INSTANCE; if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get(); try { connector.send(destination, interceptedCommand); } catch (Exception e) { destination.suspect(); loggingCallback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) )); } } else { loggingCallback.onResult(interceptedCommand, asCommandResultMessage(new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()) ))); } } else { dispatch(command, loggingCallback); } }
destination.suspect(); callback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) ));
@Override public String getRoutingKey(CommandMessage<?> command) { String routingKey = doResolveRoutingKey(command); if (routingKey == null) { switch (unresolvedRoutingKeyPolicy) { case ERROR: throw new CommandDispatchException(format("The command [%s] does not contain a routing key.", command.getCommandName())); case RANDOM_KEY: return Long.toHexString(counter.getAndIncrement()); case STATIC_KEY: return STATIC_ROUTING_KEY; } } return routingKey; }
@Override public String getRoutingKey(CommandMessage<?> command) { String routingKey = doResolveRoutingKey(command); if (routingKey == null) { switch (unresolvedRoutingKeyPolicy) { case ERROR: throw new CommandDispatchException(format("The command [%s] does not contain a routing key.", command.getCommandName())); case RANDOM_KEY: return Long.toHexString(counter.getAndIncrement()); case STATIC_KEY: return STATIC_ROUTING_KEY; default: throw new IllegalStateException("The configured UnresolvedRoutingPolicy of " + unresolvedRoutingKeyPolicy.name() + " is not supported."); } } return routingKey; }
@Override public String getRoutingKey(CommandMessage<?> command) { String routingKey = doResolveRoutingKey(command); if (routingKey == null) { switch (unresolvedRoutingKeyPolicy) { case ERROR: throw new CommandDispatchException(format("The command [%s] does not contain a routing key.", command.getCommandName())); case RANDOM_KEY: return Long.toHexString(counter.getAndIncrement()); case STATIC_KEY: return STATIC_ROUTING_KEY; default: throw new IllegalStateException("The configured UnresolvedRoutingPolicy of " + unresolvedRoutingKeyPolicy.name() + " is not supported."); } } return routingKey; }
/** * {@inheritDoc} * * @throws CommandDispatchException when an error occurs while dispatching the command to a segment */ @Override public <R> void dispatch(CommandMessage<?> command, CommandCallback<R> callback) { command = intercept(command); String routingKey = routingStrategy.getRoutingKey(command); try { connector.send(routingKey, command, callback); } catch (Exception e) { callback.onFailure(new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e)); } }
private Address resolveDestination(String routingKey, CommandMessage<?> commandMessage) throws InterruptedException { Assert.isTrue(awaitJoined(5, TimeUnit.SECONDS), "This Connector did not properly join the Cluster yet."); String destination = consistentHash.get().getMember(routingKey, commandMessage.getCommandName()); if (destination == null) { throw new CommandDispatchException("No node known to accept " + commandMessage.getCommandName()); } return getAddress(destination); }
@Override public <C> void dispatch(CommandMessage<C> command) { if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Member destination = commandRouter.findDestination(interceptedCommand) .orElseThrow(() -> new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()))); try { connector.send(destination, interceptedCommand); } catch(Exception e) { destination.suspect(); throw new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e); } } else { dispatch(command, null); } }
/** * {@inheritDoc} * * @throws CommandDispatchException when an error occurs while dispatching the command to a segment */ @Override public <C, R> void dispatch(CommandMessage<C> command, CommandCallback<? super C, R> callback) { CommandMessage<? extends C> interceptedCommand = intercept(command); MessageMonitor.MonitorCallback messageMonitorCallback = messageMonitor.onMessageIngested(interceptedCommand); Member destination = commandRouter.findDestination(interceptedCommand) .orElseThrow(() -> { NoHandlerForCommandException exception = new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName())); messageMonitorCallback.reportFailure(exception); return exception; }); try { connector.send(destination, interceptedCommand, new MonitorAwareCallback<>(callback, messageMonitorCallback)); } catch(Exception e) { messageMonitorCallback.reportFailure(e); destination.suspect(); throw new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e); } }
@Override public <C> void dispatch(CommandMessage<C> command) { LoggingCallback loggingCallback = LoggingCallback.INSTANCE; if (NoOpMessageMonitor.INSTANCE.equals(messageMonitor)) { CommandMessage<? extends C> interceptedCommand = intercept(command); Optional<Member> optionalDestination = commandRouter.findDestination(interceptedCommand); if (optionalDestination.isPresent()) { Member destination = optionalDestination.get(); try { connector.send(destination, interceptedCommand); } catch (Exception e) { destination.suspect(); loggingCallback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) )); } } else { loggingCallback.onResult(interceptedCommand, asCommandResultMessage(new NoHandlerForCommandException( format("No node known to accept [%s]", interceptedCommand.getCommandName()) ))); } } else { dispatch(command, loggingCallback); } }
destination.suspect(); callback.onResult(interceptedCommand, asCommandResultMessage( new CommandDispatchException(DISPATCH_ERROR_MESSAGE + ": " + e.getMessage(), e) ));