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