@Override public boolean local() { return member.local(); }
@Override public boolean local() { return member.local(); }
@Override public boolean local() { return member.local(); }
@Override public <C> void send(Member destination, CommandMessage<? extends C> commandMessage) { if (destination.local()) { localCommandBus.dispatch(commandMessage); } else { executor.execute(() -> { sendRemotely(destination, commandMessage, DO_NOT_EXPECT_REPLY); }); } }
@Override public <C, R> void send(Member destination, CommandMessage<C> commandMessage, CommandCallback<? super C, R> callback) { if (destination.local()) { localCommandBus.dispatch(commandMessage, callback); } else { executor.execute(() -> { SpringHttpReplyMessage<R> replyMessage = this.<C, R>sendRemotely(destination, commandMessage, EXPECT_REPLY).getBody(); if (replyMessage != null) { callback.onResult(commandMessage, replyMessage.getCommandResultMessage(serializer)); } }); } }
private Optional<MessageRoutingInformation> requestMessageRoutingInformation(ServiceInstance serviceInstance) { Member member = buildMember(serviceInstance); if (member.local()) { return Optional.of(getLocalMessageRoutingInformation()); } URI endpoint = member.getConnectionEndpoint(URI.class) .orElseThrow(() -> new IllegalArgumentException(String.format( "No Connection Endpoint found in Member [%s] for protocol [%s] to send a " + "%s request to", member, URI.class, MessageRoutingInformation.class.getSimpleName() ))); URI destinationUri = buildURIForPath(endpoint, messageRoutingInformationEndpoint); try { ResponseEntity<MessageRoutingInformation> responseEntity = restTemplate.exchange(destinationUri, HttpMethod.GET, HttpEntity.EMPTY, MessageRoutingInformation.class); return Optional.ofNullable(responseEntity.getBody()); } catch (HttpClientErrorException e) { logger.info("Blacklisting Service [" + serviceInstance.getServiceId() + "], " + "as requesting message routing information from it resulted in an exception.", logger.isDebugEnabled() ? e : null); return Optional.empty(); } catch (Exception e) { logger.info("Failed to receive message routing information from Service [" + serviceInstance.getServiceId() + "] due to an exception. " + "Will temporarily set this instance to deny all incoming messages", logger.isDebugEnabled()?e:null); return Optional.of(unreachableService); } }