Search in sources :

Example 1 with IncomingConnectorFactory

use of org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory in project helidon by oracle.

the class ChannelRouter method addOutgoingConnector.

private void addOutgoingConnector(Bean<?> bean) {
    IncomingConnectorFactory incomingConnectorFactory = lookup(bean, beanManager);
    String connectorName = bean.getBeanClass().getAnnotation(Connector.class).value();
    OutgoingConnector outgoingConnector = new OutgoingConnector(connectorName, incomingConnectorFactory, this);
    outgoingConnectorMap.put(connectorName, outgoingConnector);
}
Also used : Connector(org.eclipse.microprofile.reactive.messaging.spi.Connector) IncomingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory)

Example 2 with IncomingConnectorFactory

use of org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory in project smallrye-reactive-messaging by smallrye.

the class RabbitMQConnector method getPublisherBuilder.

/**
 * Creates a <em>channel</em> for the given configuration. The channel's configuration is associated with a
 * specific {@code connector}, using the {@link Connector} qualifier's parameter indicating a key to
 * which {@link IncomingConnectorFactory} to use.
 *
 * <p>
 * Note that the connection to the <em>transport</em> or <em>broker</em> is generally postponed until the
 * subscription occurs.
 *
 * @param config the configuration, must not be {@code null}, must contain the {@link #CHANNEL_NAME_ATTRIBUTE}
 *        attribute.
 * @return the created {@link PublisherBuilder}, will not be {@code null}.
 * @throws IllegalArgumentException if the configuration is invalid.
 * @throws NoSuchElementException if the configuration does not contain an expected attribute.
 */
@Override
public PublisherBuilder<? extends Message<?>> getPublisherBuilder(final Config config) {
    final RabbitMQConnectorIncomingConfiguration ic = new RabbitMQConnectorIncomingConfiguration(config);
    incomingChannelStatus.put(ic.getChannel(), ChannelStatus.INITIALISING);
    // Create a client
    final RabbitMQClient client = RabbitMQClientHelper.createClient(this, ic, clientOptions, credentialsProviders);
    final ConnectionHolder holder = new ConnectionHolder(client, ic, getVertx());
    final RabbitMQFailureHandler onNack = createFailureHandler(ic);
    final RabbitMQAckHandler onAck = createAckHandler(ic);
    // Ensure we set the queue up
    Uni<RabbitMQClient> uniQueue = holder.getOrEstablishConnection().onItem().call(connection -> establishQueue(connection, ic)).onItem().call(connection -> establishDLQ(connection, ic)).onItem().invoke(connection -> incomingChannelStatus.put(ic.getChannel(), ChannelStatus.CONNECTED));
    // Once the queue is set up, set yp a consumer
    final Integer interval = ic.getReconnectInterval();
    final Integer attempts = ic.getReconnectAttempts();
    Multi<? extends Message<?>> multi = uniQueue.onItem().transformToUni(connection -> client.basicConsumer(ic.getQueueName(), new QueueOptions().setAutoAck(ic.getAutoAcknowledgement()).setMaxInternalQueueSize(ic.getMaxIncomingInternalQueueSize()).setKeepMostRecent(ic.getKeepMostRecent()))).onItem().transformToMulti(consumer -> getStreamOfMessages(consumer, holder, ic, onNack, onAck)).plug(m -> {
        if (attempts > 0) {
            return m.onFailure().invoke(log::retrieveMessagesRetrying).onFailure().retry().withBackOff(ofSeconds(1), ofSeconds(interval)).atMost(attempts).onFailure().invoke(t -> {
                incomingChannelStatus.put(ic.getChannel(), ChannelStatus.NOT_CONNECTED);
                log.retrieveMessagesNoMoreRetrying(t);
            });
        }
        return m;
    });
    if (Boolean.TRUE.equals(ic.getBroadcast())) {
        multi = multi.broadcast().toAllSubscribers();
    }
    return ReactiveStreams.fromPublisher(multi);
}
Also used : Arrays(java.util.Arrays) HealthReport(io.smallrye.reactive.messaging.health.HealthReport) RabbitMQConsumer(io.vertx.mutiny.rabbitmq.RabbitMQConsumer) INCOMING(io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.INCOMING) INCOMING_AND_OUTGOING(io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.INCOMING_AND_OUTGOING) Reception(javax.enterprise.event.Reception) Map(java.util.Map) Observes(javax.enterprise.event.Observes) Connector(org.eclipse.microprofile.reactive.messaging.spi.Connector) JsonObject(io.vertx.core.json.JsonObject) Any(javax.enterprise.inject.Any) Instance(javax.enterprise.inject.Instance) ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) RabbitMQAutoAck(io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAutoAck) ConnectorAttribute(io.smallrye.reactive.messaging.annotations.ConnectorAttribute) RabbitMQExceptions.ex(io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQExceptions.ex) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) RabbitMQPublisher(io.vertx.mutiny.rabbitmq.RabbitMQPublisher) SubscriberBuilder(org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) Priority(javax.annotation.Priority) List(java.util.List) CredentialsProvider(com.rabbitmq.client.impl.CredentialsProvider) PostConstruct(javax.annotation.PostConstruct) ApplicationScoped(javax.enterprise.context.ApplicationScoped) PublisherBuilder(org.eclipse.microprofile.reactive.streams.operators.PublisherBuilder) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) OutgoingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.OutgoingConnectorFactory) RabbitMQReject(io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQReject) BroadcastProcessor(io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor) RabbitMQLogging.log(io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQLogging.log) RabbitMQClient(io.vertx.mutiny.rabbitmq.RabbitMQClient) Duration.ofSeconds(java.time.Duration.ofSeconds) HealthReporter(io.smallrye.reactive.messaging.health.HealthReporter) Multi(io.smallrye.mutiny.Multi) Uni(io.smallrye.mutiny.Uni) Inject(javax.inject.Inject) RabbitMQAck(io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAck) BeforeDestroyed(javax.enterprise.context.BeforeDestroyed) TracingUtils(io.smallrye.reactive.messaging.rabbitmq.tracing.TracingUtils) OUTGOING(io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.OUTGOING) RabbitMQAccept(io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQAccept) QueueOptions(io.vertx.rabbitmq.QueueOptions) RabbitMQPublisherOptions(io.vertx.rabbitmq.RabbitMQPublisherOptions) NoSuchElementException(java.util.NoSuchElementException) IncomingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) RabbitMQOptions(io.vertx.rabbitmq.RabbitMQOptions) RabbitMQAckHandler(io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAckHandler) Message(org.eclipse.microprofile.reactive.messaging.Message) RabbitMQFailStop(io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQFailStop) Subscription(org.reactivestreams.Subscription) Vertx(io.vertx.mutiny.core.Vertx) RabbitMQFailureHandler(io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQFailureHandler) RabbitMQAckHandler(io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAckHandler) RabbitMQClient(io.vertx.mutiny.rabbitmq.RabbitMQClient) RabbitMQFailureHandler(io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQFailureHandler) RabbitMQLogging.log(io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQLogging.log) QueueOptions(io.vertx.rabbitmq.QueueOptions)

Aggregations

CredentialsProvider (com.rabbitmq.client.impl.CredentialsProvider)1 Multi (io.smallrye.mutiny.Multi)1 Uni (io.smallrye.mutiny.Uni)1 BroadcastProcessor (io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor)1 ConnectorAttribute (io.smallrye.reactive.messaging.annotations.ConnectorAttribute)1 INCOMING (io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.INCOMING)1 INCOMING_AND_OUTGOING (io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.INCOMING_AND_OUTGOING)1 OUTGOING (io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.OUTGOING)1 HealthReport (io.smallrye.reactive.messaging.health.HealthReport)1 HealthReporter (io.smallrye.reactive.messaging.health.HealthReporter)1 ExecutionHolder (io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder)1 RabbitMQAck (io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAck)1 RabbitMQAckHandler (io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAckHandler)1 RabbitMQAutoAck (io.smallrye.reactive.messaging.rabbitmq.ack.RabbitMQAutoAck)1 RabbitMQAccept (io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQAccept)1 RabbitMQFailStop (io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQFailStop)1 RabbitMQFailureHandler (io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQFailureHandler)1 RabbitMQReject (io.smallrye.reactive.messaging.rabbitmq.fault.RabbitMQReject)1 RabbitMQExceptions.ex (io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQExceptions.ex)1 RabbitMQLogging.log (io.smallrye.reactive.messaging.rabbitmq.i18n.RabbitMQLogging.log)1