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;
}
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);
}
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();
}
Aggregations