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