All Downloads are FREE. Search and download functionalities are using the official Maven repository.

dev.snowdrop.vertx.amqp.SnowdropAmqpClient Maven / Gradle / Ivy

There is a newer version: 1.4.1
Show newest version
package dev.snowdrop.vertx.amqp;

import java.time.Duration;

import io.smallrye.mutiny.converters.uni.UniReactorConverters;
import org.springframework.beans.factory.DisposableBean;
import reactor.core.publisher.Mono;

class SnowdropAmqpClient implements AmqpClient, DisposableBean {

    private final io.vertx.mutiny.amqp.AmqpClient delegate;

    private final MessageConverter messageConverter;

    SnowdropAmqpClient(io.vertx.mutiny.amqp.AmqpClient delegate, MessageConverter messageConverter) {
        this.delegate = delegate;
        this.messageConverter = messageConverter;
    }

    @Override
    public Mono connect() {
        return delegate.connect()
            .convert()
            .with(UniReactorConverters.toMono())
            .map(delegateConnection -> new SnowdropAmqpConnection(delegateConnection, messageConverter));
    }

    @Override
    public Mono createSender(String address) {
        return delegate.createSender(address)
            .convert()
            .with(UniReactorConverters.toMono())
            .map(delegateSender -> new SnowdropAmqpSender(delegateSender, messageConverter));
    }

    @Override
    public Mono createSender(String address, AmqpSenderOptions options) {
        return delegate.createSender(address, options.toVertxAmqpSenderOptions())
            .convert()
            .with(UniReactorConverters.toMono())
            .map(delegateSender -> new SnowdropAmqpSender(delegateSender, messageConverter));
    }

    @Override
    public Mono createReceiver(String address) {
        return delegate.createReceiver(address)
            .convert()
            .with(UniReactorConverters.toMono())
            .map(delegateReceiver -> new SnowdropAmqpReceiver(delegateReceiver, messageConverter));
    }

    @Override
    public Mono createReceiver(String address, AmqpReceiverOptions options) {
        return delegate.createReceiver(address, options.toVertxAmqpReceiverOptions())
            .convert()
            .with(UniReactorConverters.toMono())
            .map(delegateReceiver -> new SnowdropAmqpReceiver(delegateReceiver, messageConverter));
    }

    @Override
    public Mono close() {
        return delegate.close()
            .convert()
            .with(UniReactorConverters.toMono());
    }

    @Override
    public void destroy() {
        close().block(Duration.ofSeconds(10)); // TODO should this be configurable?
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy