Search in sources :

Example 1 with ReactiveStreamsConsumer

use of org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer in project camel by apache.

the class CamelSubscriber method onComplete.

@Override
public void onComplete() {
    LOG.info("Reactive stream '{}' completed", name);
    ReactiveStreamsConsumer consumer;
    synchronized (this) {
        consumer = this.consumer;
        this.subscription = null;
    }
    if (consumer != null) {
        consumer.onComplete();
    }
}
Also used : ReactiveStreamsConsumer(org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer)

Example 2 with ReactiveStreamsConsumer

use of org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer in project camel by apache.

the class CamelSubscriber method onError.

@Override
public void onError(Throwable throwable) {
    if (throwable == null) {
        throw new NullPointerException("throwable is null");
    }
    LOG.error("Error in reactive stream '" + name + "'", throwable);
    ReactiveStreamsConsumer consumer;
    synchronized (this) {
        consumer = this.consumer;
        this.subscription = null;
    }
    if (consumer != null) {
        consumer.onError(throwable);
    }
}
Also used : ReactiveStreamsConsumer(org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer)

Example 3 with ReactiveStreamsConsumer

use of org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer in project camel by apache.

the class CamelReactiveStreamsServiceImpl method doRequest.

protected Publisher<Exchange> doRequest(String name, Exchange data) {
    ReactiveStreamsConsumer consumer = streamSubscriber(name).getConsumer();
    if (consumer == null) {
        throw new IllegalStateException("No consumers attached to the stream " + name);
    }
    DelayedMonoPublisher<Exchange> publisher = new DelayedMonoPublisher<>(this.workerPool);
    data.addOnCompletion(new Synchronization() {

        @Override
        public void onComplete(Exchange exchange) {
            publisher.setData(exchange);
        }

        @Override
        public void onFailure(Exchange exchange) {
            Throwable throwable = exchange.getException();
            if (throwable == null) {
                throwable = new IllegalStateException("Unknown Exception");
            }
            publisher.setException(throwable);
        }
    });
    consumer.process(data, doneSync -> {
    });
    return publisher;
}
Also used : DefaultExchange(org.apache.camel.impl.DefaultExchange) Exchange(org.apache.camel.Exchange) ReactiveStreamsConsumer(org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer) Synchronization(org.apache.camel.spi.Synchronization)

Example 4 with ReactiveStreamsConsumer

use of org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer in project camel by apache.

the class CamelSubscriber method onNext.

@Override
public void onNext(Exchange exchange) {
    if (exchange == null) {
        throw new NullPointerException("exchange is null");
    }
    ReactiveStreamsConsumer target;
    synchronized (this) {
        requested--;
        target = this.consumer;
        if (target != null) {
            inflightCount++;
        }
    }
    if (target != null) {
        target.process(exchange, doneSync -> {
            synchronized (this) {
                inflightCount--;
            }
            refill();
        });
    } else {
        // This may happen when the consumer is stopped
        LOG.warn("Message received in stream '{}', but no consumers were attached. Discarding {}.", name, exchange);
    }
}
Also used : ReactiveStreamsConsumer(org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer)

Aggregations

ReactiveStreamsConsumer (org.apache.camel.component.reactive.streams.ReactiveStreamsConsumer)4 Exchange (org.apache.camel.Exchange)1 DefaultExchange (org.apache.camel.impl.DefaultExchange)1 Synchronization (org.apache.camel.spi.Synchronization)1