Search in sources :

Example 1 with AmqpClient

use of io.vertx.mutiny.amqp.AmqpClient in project smallrye-reactive-messaging by smallrye.

the class AmqpClientHelper method createClient.

static AmqpClient createClient(AmqpConnector connector, AmqpConnectorCommonConfiguration config, Instance<AmqpClientOptions> instance) {
    AmqpClient client;
    Optional<String> clientOptionsName = config.getClientOptionsName();
    Vertx vertx = connector.getVertx();
    if (clientOptionsName.isPresent()) {
        client = createClientFromClientOptionsBean(vertx, instance, clientOptionsName.get(), config);
    } else {
        client = getClient(vertx, config);
    }
    connector.addClient(client);
    return client;
}
Also used : AmqpClient(io.vertx.mutiny.amqp.AmqpClient) Vertx(io.vertx.mutiny.core.Vertx)

Example 2 with AmqpClient

use of io.vertx.mutiny.amqp.AmqpClient in project smallrye-reactive-messaging by smallrye.

the class AmqpConnector method getPublisherBuilder.

@Override
public PublisherBuilder<? extends Message<?>> getPublisherBuilder(Config config) {
    AmqpConnectorIncomingConfiguration ic = new AmqpConnectorIncomingConfiguration(config);
    String address = ic.getAddress().orElseGet(ic::getChannel);
    opened.put(ic.getChannel(), false);
    boolean broadcast = ic.getBroadcast();
    boolean durable = ic.getDurable();
    boolean autoAck = ic.getAutoAcknowledgement();
    AmqpClient client = AmqpClientHelper.createClient(this, ic, clientOptions);
    String link = ic.getLinkName().orElseGet(ic::getChannel);
    ConnectionHolder holder = new ConnectionHolder(client, ic, getVertx());
    holders.put(ic.getChannel(), holder);
    AmqpFailureHandler onNack = createFailureHandler(ic);
    Multi<? extends Message<?>> multi = holder.getOrEstablishConnection().onItem().transformToUni(connection -> connection.createReceiver(address, new AmqpReceiverOptions().setAutoAcknowledgement(autoAck).setDurable(durable).setLinkName(link).setCapabilities(getClientCapabilities(ic)))).onItem().invoke(r -> opened.put(ic.getChannel(), true)).onItem().transformToMulti(r -> getStreamOfMessages(r, holder, address, ic.getChannel(), onNack, ic.getCloudEvents(), ic.getTracingEnabled()));
    Integer interval = ic.getReconnectInterval();
    Integer attempts = ic.getReconnectAttempts();
    multi = multi.onFailure().invoke(log::retrieveMessagesRetrying).onFailure().retry().withBackOff(ofSeconds(1), ofSeconds(interval)).atMost(attempts).onFailure().invoke(t -> {
        opened.put(ic.getChannel(), false);
        log.retrieveMessagesNoMoreRetrying(t);
    });
    if (broadcast) {
        multi = multi.broadcast().toAllSubscribers();
    }
    return ReactiveStreams.fromPublisher(multi);
}
Also used : AMQPLogging.log(io.smallrye.reactive.messaging.amqp.i18n.AMQPLogging.log) Arrays(java.util.Arrays) AmqpModifiedFailedAndUndeliverableHere(io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailedAndUndeliverableHere) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) HealthReport(io.smallrye.reactive.messaging.health.HealthReport) 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) AmqpFailStop(io.smallrye.reactive.messaging.amqp.fault.AmqpFailStop) Duration(java.time.Duration) Map(java.util.Map) Observes(javax.enterprise.event.Observes) Connector(org.eclipse.microprofile.reactive.messaging.spi.Connector) SpanBuilder(io.opentelemetry.api.trace.SpanBuilder) Any(javax.enterprise.inject.Any) Instance(javax.enterprise.inject.Instance) AmqpFailureHandler(io.smallrye.reactive.messaging.amqp.fault.AmqpFailureHandler) Context(io.opentelemetry.context.Context) ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) ConnectorAttribute(io.smallrye.reactive.messaging.annotations.ConnectorAttribute) Span(io.opentelemetry.api.trace.Span) AmqpAccept(io.smallrye.reactive.messaging.amqp.fault.AmqpAccept) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SubscriberBuilder(org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) SpanKind(io.opentelemetry.api.trace.SpanKind) AmqpClient(io.vertx.mutiny.amqp.AmqpClient) Priority(javax.annotation.Priority) List(java.util.List) AmqpSenderOptions(io.vertx.amqp.AmqpSenderOptions) PostConstruct(javax.annotation.PostConstruct) ProtonSender(io.vertx.proton.ProtonSender) 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) BroadcastProcessor(io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor) AmqpReceiverOptions(io.vertx.amqp.AmqpReceiverOptions) AmqpModifiedFailed(io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailed) Duration.ofSeconds(java.time.Duration.ofSeconds) Tracer(io.opentelemetry.api.trace.Tracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) HealthReporter(io.smallrye.reactive.messaging.health.HealthReporter) Multi(io.smallrye.mutiny.Multi) Uni(io.smallrye.mutiny.Uni) Inject(javax.inject.Inject) AmqpClientOptions(io.vertx.amqp.AmqpClientOptions) BeforeDestroyed(javax.enterprise.context.BeforeDestroyed) OUTGOING(io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.OUTGOING) IncomingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) AMQPExceptions.ex(io.smallrye.reactive.messaging.amqp.i18n.AMQPExceptions.ex) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) AmqpReceiver(io.vertx.mutiny.amqp.AmqpReceiver) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) AmqpRelease(io.smallrye.reactive.messaging.amqp.fault.AmqpRelease) AmqpReject(io.smallrye.reactive.messaging.amqp.fault.AmqpReject) Message(org.eclipse.microprofile.reactive.messaging.Message) AmqpSender(io.vertx.mutiny.amqp.AmqpSender) Vertx(io.vertx.mutiny.core.Vertx) Collections(java.util.Collections) AmqpReceiverOptions(io.vertx.amqp.AmqpReceiverOptions) AmqpClient(io.vertx.mutiny.amqp.AmqpClient) AmqpFailureHandler(io.smallrye.reactive.messaging.amqp.fault.AmqpFailureHandler)

Example 3 with AmqpClient

use of io.vertx.mutiny.amqp.AmqpClient in project smallrye-reactive-messaging by smallrye.

the class AmqpConnector method getSubscriberBuilder.

@Override
public SubscriberBuilder<? extends Message<?>, Void> getSubscriberBuilder(Config config) {
    AmqpConnectorOutgoingConfiguration oc = new AmqpConnectorOutgoingConfiguration(config);
    String configuredAddress = oc.getAddress().orElseGet(oc::getChannel);
    opened.put(oc.getChannel(), false);
    AtomicReference<AmqpSender> sender = new AtomicReference<>();
    AmqpClient client = AmqpClientHelper.createClient(this, oc, clientOptions);
    String link = oc.getLinkName().orElseGet(oc::getChannel);
    ConnectionHolder holder = new ConnectionHolder(client, oc, getVertx());
    Uni<AmqpSender> getSender = Uni.createFrom().deferred(() -> {
        // If we already have a sender, use it.
        AmqpSender current = sender.get();
        if (current != null && !current.connection().isDisconnected()) {
            if (isLinkOpen(current)) {
                return Uni.createFrom().item(current);
            } else {
                // link closed, close the sender, and recreate one.
                current.closeAndForget();
            }
        }
        return holder.getOrEstablishConnection().onItem().transformToUni(connection -> {
            boolean anonymous = oc.getUseAnonymousSender().orElseGet(() -> ConnectionHolder.supportAnonymousRelay(connection));
            if (anonymous) {
                return connection.createAnonymousSender();
            } else {
                return connection.createSender(configuredAddress, new AmqpSenderOptions().setLinkName(link).setCapabilities(getClientCapabilities(oc)));
            }
        }).onItem().invoke(s -> {
            AmqpSender orig = sender.getAndSet(s);
            if (orig != null) {
                // Close the previous one if any.
                orig.closeAndForget();
            }
            opened.put(oc.getChannel(), true);
        });
    }).onFailure().invoke(t -> {
        sender.set(null);
        opened.put(oc.getChannel(), false);
    }).onCancellation().invoke(() -> {
        sender.set(null);
        opened.put(oc.getChannel(), false);
    });
    AmqpCreditBasedSender processor = new AmqpCreditBasedSender(this, holder, oc, getSender);
    processors.put(oc.getChannel(), processor);
    return ReactiveStreams.<Message<?>>builder().via(processor).onError(t -> {
        log.failureReported(oc.getChannel(), t);
        opened.put(oc.getChannel(), false);
    }).ignore();
}
Also used : AMQPLogging.log(io.smallrye.reactive.messaging.amqp.i18n.AMQPLogging.log) Arrays(java.util.Arrays) AmqpModifiedFailedAndUndeliverableHere(io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailedAndUndeliverableHere) SemanticAttributes(io.opentelemetry.semconv.trace.attributes.SemanticAttributes) HealthReport(io.smallrye.reactive.messaging.health.HealthReport) 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) AmqpFailStop(io.smallrye.reactive.messaging.amqp.fault.AmqpFailStop) Duration(java.time.Duration) Map(java.util.Map) Observes(javax.enterprise.event.Observes) Connector(org.eclipse.microprofile.reactive.messaging.spi.Connector) SpanBuilder(io.opentelemetry.api.trace.SpanBuilder) Any(javax.enterprise.inject.Any) Instance(javax.enterprise.inject.Instance) AmqpFailureHandler(io.smallrye.reactive.messaging.amqp.fault.AmqpFailureHandler) Context(io.opentelemetry.context.Context) ExecutionHolder(io.smallrye.reactive.messaging.providers.connectors.ExecutionHolder) ConnectorAttribute(io.smallrye.reactive.messaging.annotations.ConnectorAttribute) Span(io.opentelemetry.api.trace.Span) AmqpAccept(io.smallrye.reactive.messaging.amqp.fault.AmqpAccept) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SubscriberBuilder(org.eclipse.microprofile.reactive.streams.operators.SubscriberBuilder) Config(org.eclipse.microprofile.config.Config) Collectors(java.util.stream.Collectors) SpanKind(io.opentelemetry.api.trace.SpanKind) AmqpClient(io.vertx.mutiny.amqp.AmqpClient) Priority(javax.annotation.Priority) List(java.util.List) AmqpSenderOptions(io.vertx.amqp.AmqpSenderOptions) PostConstruct(javax.annotation.PostConstruct) ProtonSender(io.vertx.proton.ProtonSender) 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) BroadcastProcessor(io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor) AmqpReceiverOptions(io.vertx.amqp.AmqpReceiverOptions) AmqpModifiedFailed(io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailed) Duration.ofSeconds(java.time.Duration.ofSeconds) Tracer(io.opentelemetry.api.trace.Tracer) AtomicReference(java.util.concurrent.atomic.AtomicReference) HealthReporter(io.smallrye.reactive.messaging.health.HealthReporter) Multi(io.smallrye.mutiny.Multi) Uni(io.smallrye.mutiny.Uni) Inject(javax.inject.Inject) AmqpClientOptions(io.vertx.amqp.AmqpClientOptions) BeforeDestroyed(javax.enterprise.context.BeforeDestroyed) OUTGOING(io.smallrye.reactive.messaging.annotations.ConnectorAttribute.Direction.OUTGOING) IncomingConnectorFactory(org.eclipse.microprofile.reactive.messaging.spi.IncomingConnectorFactory) ReactiveStreams(org.eclipse.microprofile.reactive.streams.operators.ReactiveStreams) AMQPExceptions.ex(io.smallrye.reactive.messaging.amqp.i18n.AMQPExceptions.ex) TracingMetadata(io.smallrye.reactive.messaging.TracingMetadata) AmqpReceiver(io.vertx.mutiny.amqp.AmqpReceiver) GlobalOpenTelemetry(io.opentelemetry.api.GlobalOpenTelemetry) AmqpRelease(io.smallrye.reactive.messaging.amqp.fault.AmqpRelease) AmqpReject(io.smallrye.reactive.messaging.amqp.fault.AmqpReject) Message(org.eclipse.microprofile.reactive.messaging.Message) AmqpSender(io.vertx.mutiny.amqp.AmqpSender) Vertx(io.vertx.mutiny.core.Vertx) Collections(java.util.Collections) AmqpClient(io.vertx.mutiny.amqp.AmqpClient) AtomicReference(java.util.concurrent.atomic.AtomicReference) AmqpSender(io.vertx.mutiny.amqp.AmqpSender) AmqpSenderOptions(io.vertx.amqp.AmqpSenderOptions)

Aggregations

AmqpClient (io.vertx.mutiny.amqp.AmqpClient)3 Vertx (io.vertx.mutiny.core.Vertx)3 GlobalOpenTelemetry (io.opentelemetry.api.GlobalOpenTelemetry)2 Span (io.opentelemetry.api.trace.Span)2 SpanBuilder (io.opentelemetry.api.trace.SpanBuilder)2 SpanKind (io.opentelemetry.api.trace.SpanKind)2 Tracer (io.opentelemetry.api.trace.Tracer)2 Context (io.opentelemetry.context.Context)2 SemanticAttributes (io.opentelemetry.semconv.trace.attributes.SemanticAttributes)2 Multi (io.smallrye.mutiny.Multi)2 Uni (io.smallrye.mutiny.Uni)2 BroadcastProcessor (io.smallrye.mutiny.operators.multi.processors.BroadcastProcessor)2 TracingMetadata (io.smallrye.reactive.messaging.TracingMetadata)2 AmqpAccept (io.smallrye.reactive.messaging.amqp.fault.AmqpAccept)2 AmqpFailStop (io.smallrye.reactive.messaging.amqp.fault.AmqpFailStop)2 AmqpFailureHandler (io.smallrye.reactive.messaging.amqp.fault.AmqpFailureHandler)2 AmqpModifiedFailed (io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailed)2 AmqpModifiedFailedAndUndeliverableHere (io.smallrye.reactive.messaging.amqp.fault.AmqpModifiedFailedAndUndeliverableHere)2 AmqpReject (io.smallrye.reactive.messaging.amqp.fault.AmqpReject)2 AmqpRelease (io.smallrye.reactive.messaging.amqp.fault.AmqpRelease)2