@Override public String getAddress() { return delegate.getAddress(); }
@Override public String getAddress() { return delegate.getAddress(); }
/** * Obtain a supplier of a description of a target of a connection. * * @param target the target. * @param connection the connection. * @return supplier of the description. */ private static Supplier<String> targetDescription(final Target target, final Connection connection) { return () -> MessageFormat.format("Target of address ''{0}'' of connection ''{1}''", target.getAddress(), connection.getId()); }
/** * Obtain a supplier of a description of a target of a connection. * * @param target the target. * @param connection the connection. * @return supplier of the description. */ private static Supplier<String> targetDescription(final Target target, final Connection connection) { return () -> MessageFormat.format("Target of address ''{0}'' of connection ''{1}''", target.getAddress(), connection.getId()); }
/** * Apply {@link ThingPlaceholder}s to the passed {@code targets} with the passed {@code thingId}. * * @param targets {@link Target}s to apply placeholder substitution in. * @param thingId the thing ID. * @param unresolvedPlaceholderListener callback to call with unresolved placeholders. * @return Targets as result of placeholder substitution. */ public static Set<Target> filterTargets(final Set<Target> targets, final String thingId, final Consumer<String> unresolvedPlaceholderListener) { // check if we have to replace anything at all if (targets.stream().map(Target::getAddress).noneMatch(Placeholders::containsAnyPlaceholder)) { return targets; } return targets.stream() .map(target -> { final String filtered = applyThingPlaceholder(target.getAddress(), thingId, unresolvedPlaceholderListener); return filtered != null ? target.withAddress(filtered) : null; }) .filter(Objects::nonNull) .collect(Collectors.toSet()); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), RabbitMQPublisherActor.ACTOR_NAME, rmqPublisherActor); return targetEntryFuture.thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), MqttPublisherActor.ACTOR_NAME, getPublisherActor().orElse(null)); return targetEntryFuture.thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), MqttPublisherActor.ACTOR_NAME, getPublisherActor().orElse(null)); return targetEntryFuture.thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), RabbitMQPublisherActor.ACTOR_NAME, rmqPublisherActor); return targetEntryFuture.thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), AmqpPublisherActor.ACTOR_NAME, amqpPublisherActor); return targetEntryFuture .thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())) .handle((result, error) -> { if (error == null) { return result; } else { log.error(error, "Error while aggregating target ConnectionStatus: {}", error.getMessage()); return Collections.emptyMap(); } }); }
@Override protected CompletionStage<Map<String, AddressMetric>> getTargetConnectionStatus(final Target target) { final CompletionStage<Pair<String, AddressMetric>> targetEntryFuture = retrieveAddressMetric(target.getAddress(), AmqpPublisherActor.ACTOR_NAME, amqpPublisherActor); return targetEntryFuture .thenApply(targetEntry -> Collections.singletonMap(targetEntry.first(), targetEntry.second())) .handle((result, error) -> { if (error == null) { return result; } else { log.error(error, "Error while aggregating target ConnectionStatus: {}", error.getMessage()); return Collections.emptyMap(); } }); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
private void validateSourceAndTargetAddressesAreNonempty(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources().forEach(source -> { if (source.getAddresses().isEmpty() || source.getAddresses().contains("")) { final String location = String.format("Source %d of connection <%s>", source.getIndex(), connection.getId()); throw emptyAddressesError(location, dittoHeaders); } }); connection.getTargets().forEach(target -> { if (target.getAddress().isEmpty()) { final String location = String.format("Targets of connection <%s>", connection.getId()); throw emptyAddressesError(location, dittoHeaders); } target.getTopics().forEach(topic -> topic.getFilter().ifPresent(filter -> { // will throw an InvalidRqlExpressionException if the RQL expression was not valid: queryFilterCriteriaFactory.filterCriteria(filter, dittoHeaders); })); }); }
@Override protected void preEnhancement(final ReceiveBuilder receiveBuilder) { receiveBuilder .match(ChannelCreated.class, channelCreated -> { this.channelActor = channelCreated.channel(); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); final Set<String> exchanges = targets.stream() .map(t -> toPublishTarget(t.getAddress())) .map(RabbitMQTarget::getExchange) .collect(Collectors.toSet()); final ChannelMessage channelMessage = ChannelMessage.apply(channel -> { exchanges.forEach(exchange -> { log.debug("Checking for existence of exchange <{}>", exchange); try { channel.exchangeDeclarePassive(exchange); } catch (final IOException e) { log.warning("Failed to declare exchange <{}> passively", exchange); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.FAILED, "Exchange '" + exchange + "' was missing at " + Instant.now(), 0, null); } }); return null; }, false); channelCreated.channel().tell(channelMessage, getSelf()); }); }
@Override protected void preEnhancement(final ReceiveBuilder receiveBuilder) { receiveBuilder .match(ChannelCreated.class, channelCreated -> { this.channelActor = channelCreated.channel(); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.OPEN, "Started at " + Instant.now(), 0, null); final Set<String> exchanges = targets.stream() .map(t -> toPublishTarget(t.getAddress())) .map(RabbitMQTarget::getExchange) .collect(Collectors.toSet()); final ChannelMessage channelMessage = ChannelMessage.apply(channel -> { exchanges.forEach(exchange -> { log.debug("Checking for existence of exchange <{}>", exchange); try { channel.exchangeDeclarePassive(exchange); } catch (final IOException e) { log.warning("Failed to declare exchange <{}> passively", exchange); addressMetric = ConnectivityModelFactory.newAddressMetric(ConnectionStatus.FAILED, "Exchange '" + exchange + "' was missing at " + Instant.now(), 0, null); } }); return null; }, false); channelCreated.channel().tell(channelMessage, getSelf()); }); }
outbound.getTargets().forEach(target -> { log().info("Publishing mapped message of type <{}> to target address <{}>", outboundSource.getType(), target.getAddress()); try { final T publishTarget = toPublishTarget(target.getAddress()); final ExternalMessage messageWithMappedHeaders = applyHeaderMapping(outbound, target, log()); publishMessage(target, publishTarget, messageWithMappedHeaders);
outbound.getTargets().forEach(target -> { log().info("Publishing mapped message of type <{}> to target address <{}>", outboundSource.getType(), target.getAddress()); try { final T publishTarget = toPublishTarget(target.getAddress()); final ExternalMessage messageWithMappedHeaders = applyHeaderMapping(outbound, target, log()); publishMessage(target, publishTarget, messageWithMappedHeaders);