@Override public Set<String> getAddresses() { return delegate.getAddresses(); }
@Override public Set<String> getAddresses() { return delegate.getAddresses(); }
@Override protected CompletionStage<Map<String, AddressMetric>> getSourceConnectionStatus(final Source source) { return collectAsList(source.getAddresses().stream() .flatMap(address -> IntStream.range(0, source.getConsumerCount()) .mapToObj(idx -> { final String addressWithIndex = address + "-" + idx; final String actorLabel = CONSUMER_ACTOR_PREFIX + addressWithIndex; final ActorRef consumer = consumerByAddressWithIndex.get(addressWithIndex); return retrieveAddressMetric(addressWithIndex, actorLabel, consumer); }) )) .thenApply(entries -> entries.stream().collect(Collectors.toMap(Pair::first, Pair::second))); }
@Override protected CompletionStage<Map<String, AddressMetric>> getSourceConnectionStatus(final Source source) { return collectAsList(source.getAddresses().stream() .flatMap(address -> IntStream.range(0, source.getConsumerCount()) .mapToObj(idx -> { final String addressWithIndex = address + "-" + idx; final String actorLabel = CONSUMER_ACTOR_PREFIX + addressWithIndex; final ActorRef consumer = consumerByAddressWithIndex.get(addressWithIndex); return retrieveAddressMetric(addressWithIndex, actorLabel, consumer); }) )) .thenApply(entries -> entries.stream().collect(Collectors.toMap(Pair::first, Pair::second))); }
private static void validateAddresses(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources() .stream() .flatMap(source -> source.getAddresses().stream()) .forEach(a -> validateAddress(a, true, dittoHeaders)); // no wildcards allowed for publish targets connection.getTargets() .stream() .map(Target::getAddress) .forEach(a -> validateAddress(a, false, dittoHeaders)); }
@Override protected CompletionStage<Map<String, AddressMetric>> getSourceConnectionStatus(final Source source) { return collectAsList(IntStream.range(0, source.getConsumerCount()) .mapToObj(idx -> { final String topics = String.join(",", source.getAddresses()); final String actorLabel = MqttConsumerActor.ACTOR_NAME_PREFIX + getUniqueSourceSuffix(source.getIndex(), idx); final ActorRef consumer = consumerByActorNameWithIndex.get(actorLabel); return retrieveAddressMetric(topics, actorLabel, consumer); })) .thenApply(entries -> entries.stream().collect(Collectors.toMap(Pair::first, Pair::second))); }
private static void validateAddresses(final Connection connection, final DittoHeaders dittoHeaders) { connection.getSources() .stream() .flatMap(source -> source.getAddresses().stream()) .forEach(a -> validateAddress(a, true, dittoHeaders)); // no wildcards allowed for publish targets connection.getTargets() .stream() .map(Target::getAddress) .forEach(a -> validateAddress(a, false, dittoHeaders)); }
/** * Uses the given session to create the specified count of message consumers for every sources addresses. * * @param session the session * @return the consumers * @throws org.eclipse.ditto.signals.commands.connectivity.exceptions.ConnectionFailedException if creation of one * or more consumers failed */ private List<ConsumerData> createConsumers(final Session session) { final Map<String, Exception> failedSources = new HashMap<>(); final List<ConsumerData> consumers = connection.getSources().stream().flatMap(source -> source.getAddresses().stream().flatMap(sourceAddress -> IntStream.range(0, source.getConsumerCount()) .mapToObj(i -> sourceAddress + "-" + i) .map(addressWithIndex -> createJmsConsumer(session, failedSources, source, sourceAddress, addressWithIndex)) .filter(Objects::nonNull) .collect(Collectors.toList()).stream() ).collect(Collectors.toList()).stream() ).collect(Collectors.toList()); if (!failedSources.isEmpty()) { throw buildConnectionFailedException(failedSources); } return consumers; }
@Override protected CompletionStage<Map<String, AddressMetric>> getSourceConnectionStatus(final Source source) { return collectAsList(IntStream.range(0, source.getConsumerCount()) .mapToObj(idx -> { final String topics = String.join(",", source.getAddresses()); final String actorLabel = MqttConsumerActor.ACTOR_NAME_PREFIX + getUniqueSourceSuffix(source.getIndex(), idx); final ActorRef consumer = consumerByActorNameWithIndex.get(actorLabel); return retrieveAddressMetric(topics, actorLabel, consumer); })) .thenApply(entries -> entries.stream().collect(Collectors.toMap(Pair::first, Pair::second))); }
/** * Uses the given session to create the specified count of message consumers for every sources addresses. * * @param session the session * @return the consumers * @throws org.eclipse.ditto.signals.commands.connectivity.exceptions.ConnectionFailedException if creation of one * or more consumers failed */ private List<ConsumerData> createConsumers(final Session session) { final Map<String, Exception> failedSources = new HashMap<>(); final List<ConsumerData> consumers = connection.getSources().stream().flatMap(source -> source.getAddresses().stream().flatMap(sourceAddress -> IntStream.range(0, source.getConsumerCount()) .mapToObj(i -> sourceAddress + "-" + i) .map(addressWithIndex -> createJmsConsumer(session, failedSources, source, sourceAddress, addressWithIndex)) .filter(Objects::nonNull) .collect(Collectors.toList()).stream() ).collect(Collectors.toList()).stream() ).collect(Collectors.toList()); if (!failedSources.isEmpty()) { throw buildConnectionFailedException(failedSources); } return consumers; }
/** * If no context is set on connection level each target and source must have its own context. */ private void checkAuthorizationContextsAreValid() { // if the auth context on connection level is empty, // an auth context is required to be set on each source/target final Set<String> sourcesWithoutAuthContext = sources.stream() .filter(source -> source.getAuthorizationContext().isEmpty()) .flatMap(source -> source.getAddresses().stream()) .collect(Collectors.toSet()); final Set<String> targetsWithoutAuthContext = targets.stream() .filter(target -> target.getAuthorizationContext().isEmpty()) .map(Target::getAddress) .collect(Collectors.toSet()); if (!sourcesWithoutAuthContext.isEmpty() || !targetsWithoutAuthContext.isEmpty()) { final StringBuilder message = new StringBuilder("The "); if (!sourcesWithoutAuthContext.isEmpty()) { message.append("Sources ").append(sourcesWithoutAuthContext); } if (!sourcesWithoutAuthContext.isEmpty() && !targetsWithoutAuthContext.isEmpty()) { message.append(" and "); } if (!targetsWithoutAuthContext.isEmpty()) { message.append("Targets ").append(targetsWithoutAuthContext); } message.append(" are missing an authorization context."); throw ConnectionConfigurationInvalidException.newBuilder(message.toString()).build(); } }
/** * If no context is set on connection level each target and source must have its own context. */ private void checkAuthorizationContextsAreValid() { // if the auth context on connection level is empty, // an auth context is required to be set on each source/target final Set<String> sourcesWithoutAuthContext = sources.stream() .filter(source -> source.getAuthorizationContext().isEmpty()) .flatMap(source -> source.getAddresses().stream()) .collect(Collectors.toSet()); final Set<String> targetsWithoutAuthContext = targets.stream() .filter(target -> target.getAuthorizationContext().isEmpty()) .map(Target::getAddress) .collect(Collectors.toSet()); if (!sourcesWithoutAuthContext.isEmpty() || !targetsWithoutAuthContext.isEmpty()) { final StringBuilder message = new StringBuilder("The "); if (!sourcesWithoutAuthContext.isEmpty()) { message.append("Sources ").append(sourcesWithoutAuthContext); } if (!sourcesWithoutAuthContext.isEmpty() && !targetsWithoutAuthContext.isEmpty()) { message.append(" and "); } if (!targetsWithoutAuthContext.isEmpty()) { message.append("Targets ").append(targetsWithoutAuthContext); } message.append(" are missing an authorization context."); throw ConnectionConfigurationInvalidException.newBuilder(message.toString()).build(); } }
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); })); }); }
private void ensureQueuesExist(final Channel channel) { final Collection<String> missingQueues = new ArrayList<>(); getSourcesOrEmptySet().forEach(consumer -> consumer.getAddresses().forEach(address -> { try { channel.queueDeclarePassive(address); } catch (final IOException e) { missingQueues.add(address); log.warning("The queue <{}> does not exist.", address); } }) ); if (!missingQueues.isEmpty()) { log.warning("Stopping RMQ client actor for connection <{}> as queues to connect to are missing: <{}>", connectionId(), missingQueues); throw ConnectionFailedException.newBuilder(connectionId()) .description("The queues " + missingQueues + " to connect to are missing.") .build(); } }
private void ensureQueuesExist(final Channel channel) { final Collection<String> missingQueues = new ArrayList<>(); getSourcesOrEmptySet().forEach(consumer -> consumer.getAddresses().forEach(address -> { try { channel.queueDeclarePassive(address); } catch (final IOException e) { missingQueues.add(address); log.warning("The queue <{}> does not exist.", address); } }) ); if (!missingQueues.isEmpty()) { log.warning("Stopping RMQ client actor for connection <{}> as queues to connect to are missing: <{}>", connectionId(), missingQueues); throw ConnectionFailedException.newBuilder(connectionId()) .description("The queues " + missingQueues + " to connect to are missing.") .build(); } }
private void startConsumers(final Channel channel) { final Optional<ActorRef> messageMappingProcessor = getMessageMappingProcessorActor(); if (messageMappingProcessor.isPresent()) { getSourcesOrEmptySet().forEach(source -> source.getAddresses().forEach(sourceAddress -> { for (int i = 0; i < source.getConsumerCount(); i++) { final String addressWithIndex = sourceAddress + "-" + i; final AuthorizationContext authorizationContext = source.getAuthorizationContext(); final Enforcement enforcement = source.getEnforcement().orElse(null); final HeaderMapping headerMapping = source.getHeaderMapping().orElse(null); final ActorRef consumer = startChildActorConflictFree( CONSUMER_ACTOR_PREFIX + addressWithIndex, RabbitMQConsumerActor.props(sourceAddress, messageMappingProcessor.get(), authorizationContext, enforcement, headerMapping)); consumerByAddressWithIndex.put(addressWithIndex, consumer); try { final String consumerTag = channel.basicConsume(sourceAddress, false, new RabbitMQMessageConsumer(consumer, channel)); log.debug("Consuming queue <{}>, consumer tag is <{}>.", addressWithIndex, consumerTag); consumedTagsToAddresses.put(consumerTag, addressWithIndex); } catch (final IOException e) { log.warning("Failed to consume queue <{}>: <{}>", addressWithIndex, e.getMessage()); } } }) ); } else { log.warning("The MessageMappingProcessor was not available and therefore no consumers were started!"); } }
private void startConsumers(final Channel channel) { final Optional<ActorRef> messageMappingProcessor = getMessageMappingProcessorActor(); if (messageMappingProcessor.isPresent()) { getSourcesOrEmptySet().forEach(source -> source.getAddresses().forEach(sourceAddress -> { for (int i = 0; i < source.getConsumerCount(); i++) { final String addressWithIndex = sourceAddress + "-" + i; final AuthorizationContext authorizationContext = source.getAuthorizationContext(); final Enforcement enforcement = source.getEnforcement().orElse(null); final HeaderMapping headerMapping = source.getHeaderMapping().orElse(null); final ActorRef consumer = startChildActorConflictFree( CONSUMER_ACTOR_PREFIX + addressWithIndex, RabbitMQConsumerActor.props(sourceAddress, messageMappingProcessor.get(), authorizationContext, enforcement, headerMapping)); consumerByAddressWithIndex.put(addressWithIndex, consumer); try { final String consumerTag = channel.basicConsume(sourceAddress, false, new RabbitMQMessageConsumer(consumer, channel)); log.debug("Consuming queue <{}>, consumer tag is <{}>.", addressWithIndex, consumerTag); consumedTagsToAddresses.put(consumerTag, addressWithIndex); } catch (final IOException e) { log.warning("Failed to consume queue <{}>: <{}>", addressWithIndex, e.getMessage()); } } }) ); } else { log.warning("The MessageMappingProcessor was not available and therefore no consumers were started!"); } }
pendingStatusReportsFromStreams.add(firstConsumer); subscriptionInitialized.handle((done, error) -> { final Collection<String> sourceAddresses = source.getAddresses(); if (error == null) { log.info("Subscriptions {} initialized successfully", sourceAddresses);
pendingStatusReportsFromStreams.add(firstConsumer); subscriptionInitialized.handle((done, error) -> { final Collection<String> sourceAddresses = source.getAddresses(); if (error == null) { log.info("Subscriptions {} initialized successfully", sourceAddresses);