@Override public int getConsumerCount() { return delegate.getConsumerCount(); }
@Override public int getConsumerCount() { return delegate.getConsumerCount(); }
@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))); }
@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))); }
@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; }
/** * 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; }
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!"); } }
final boolean dryRun) { if (source.getConsumerCount() <= 0) { log.info("source #{} has {} consumer - not starting stream", source.getIndex(), source.getConsumerCount()); return; (org.eclipse.ditto.model.connectivity.MqttSource) source; for (int i = 0; i < source.getConsumerCount(); i++) {
final boolean dryRun) { if (source.getConsumerCount() <= 0) { log.info("source #{} has {} consumer - not starting stream", source.getIndex(), source.getConsumerCount()); return; (org.eclipse.ditto.model.connectivity.MqttSource) source; for (int i = 0; i < source.getConsumerCount(); i++) {