Class DefaultCamelReactiveStreamsService
- java.lang.Object
-
- org.apache.camel.support.service.BaseService
-
- org.apache.camel.support.service.ServiceSupport
-
- org.apache.camel.component.reactive.streams.engine.DefaultCamelReactiveStreamsService
-
- All Implemented Interfaces:
AutoCloseable
,CamelReactiveStreamsService
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasCamelContext
,org.apache.camel.spi.HasId
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
@ManagedResource(description="Managed CamelReactiveStreamsService") public class DefaultCamelReactiveStreamsService extends org.apache.camel.support.service.ServiceSupport implements CamelReactiveStreamsService
The default implementation of the reactive streams service.
-
-
Constructor Summary
Constructors Constructor Description DefaultCamelReactiveStreamsService(org.apache.camel.CamelContext context, ReactiveStreamsEngineConfiguration configuration)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ReactiveStreamsCamelSubscriber
attachCamelConsumer(String name, ReactiveStreamsConsumer consumer)
Used by Camel to associate the subscriber of the stream with the given name to a specific Camel consumer.void
attachCamelProducer(String name, ReactiveStreamsProducer producer)
Used by Camel to associate the publisher of the stream with the given name to a specific Camel producer.TabularData
camelPublishers()
TabularData
camelSubscribers()
void
detachCamelConsumer(String name)
Used by Camel to detach the existing consumer from the given stream.void
detachCamelProducer(String name)
Used by Camel to detach the existing producer from the given stream.protected void
doInit()
protected org.reactivestreams.Publisher<org.apache.camel.Exchange>
doRequest(String name, org.apache.camel.Exchange data)
protected void
doStart()
protected void
doStop()
org.reactivestreams.Publisher<org.apache.camel.Exchange>
from(String uri)
Creates a new stream from the endpoint URI (used as Camel Consumer) and returns the associatedPublisher
.<T> org.reactivestreams.Publisher<T>
from(String uri, Class<T> type)
Creates a new stream of the given type from the endpoint URI (used as Camel Consumer) and returns the associatedPublisher
.org.reactivestreams.Publisher<org.apache.camel.Exchange>
fromStream(String name)
Returns the publisher associated to the given stream name.<T> org.reactivestreams.Publisher<T>
fromStream(String name, Class<T> cls)
Returns the publisher associated to the given stream name.org.apache.camel.CamelContext
getCamelContext()
String
getId()
<T> void
process(String uri, Class<T> type, Function<? super org.reactivestreams.Publisher<T>,?> processor)
Adds a processing step at the specified endpoint uri (usually a "direct:name") that delegates to the given reactive processor.void
process(String uri, Function<? super org.reactivestreams.Publisher<org.apache.camel.Exchange>,?> processor)
Adds a processing step at the specified endpoint uri (usually a "direct:name") that delegates to the given reactive processor.void
sendCamelExchange(String name, org.apache.camel.Exchange exchange)
Used by Camel to send the exchange to all active subscriptions on the given stream.ReactiveStreamsCamelSubscriber
streamSubscriber(String name)
Returns the subscriber associated to the given stream name.<T> org.reactivestreams.Subscriber<T>
streamSubscriber(String name, Class<T> type)
Returns the subscriber associated to the given stream name.org.reactivestreams.Subscriber<org.apache.camel.Exchange>
subscriber(String uri)
Creates a new route that pushes data to the endpoint URI and returns the associatedSubscriber
.<T> org.reactivestreams.Subscriber<T>
subscriber(String uri, Class<T> type)
Creates a new route that pushes data to the endpoint URI and returns the associatedSubscriber
.Function<Object,org.reactivestreams.Publisher<org.apache.camel.Exchange>>
to(String uri)
Creates a new route that uses the endpoint URI as producer, and returns a function that pushes the data into the route and returns thePublisher
that holds the resulting exchange or the error.<T> Function<Object,org.reactivestreams.Publisher<T>>
to(String uri, Class<T> type)
Creates a new route that uses the endpoint URI as producer, and returns a function that pushes the data into the route and returns thePublisher
that holds the exchange output or an error.org.reactivestreams.Publisher<org.apache.camel.Exchange>
to(String uri, Object data)
Creates a new route that uses the endpoint URI as producer, pushes the given data to the route and returns aPublisher
that will eventually return the resulting exchange or an error.<T> org.reactivestreams.Publisher<T>
to(String uri, Object data, Class<T> type)
Creates a new route that uses the endpoint URI as producer, pushes the given data to the route and returns aPublisher
that will eventually return the exchange output or an error.Function<?,? extends org.reactivestreams.Publisher<org.apache.camel.Exchange>>
toStream(String name)
Returns a function that pushes data into the specified Camel stream and returns a Publisher (mono) holding the resulting exchange or an error.<T> Function<Object,org.reactivestreams.Publisher<T>>
toStream(String name, Class<T> type)
Returns a function that pushes data into the specified Camel stream and returns a Publisher (mono) holding the exchange output or an error.org.reactivestreams.Publisher<org.apache.camel.Exchange>
toStream(String name, Object data)
Pushes the given data into the specified Camel stream and returns a Publisher (mono) holding the resulting exchange or an error.<T> org.reactivestreams.Publisher<T>
toStream(String name, Object data, Class<T> type)
Pushes the given data into the specified Camel stream and returns a Publisher (mono) holding the exchange output or an error.-
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doSuspend, fail, getStatus, init, isBuild, isInit, isNew, isRunAllowed, isShutdown, isStarted, isStarting, isStartingOrStarted, isStopped, isStopping, isStoppingOrStopped, isSuspended, isSuspending, isSuspendingOrSuspended, resume, shutdown, start, stop, suspend
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
-
-
Constructor Detail
-
DefaultCamelReactiveStreamsService
public DefaultCamelReactiveStreamsService(org.apache.camel.CamelContext context, ReactiveStreamsEngineConfiguration configuration)
-
-
Method Detail
-
getId
public String getId()
- Specified by:
getId
in interfaceorg.apache.camel.spi.HasId
-
getCamelContext
public org.apache.camel.CamelContext getCamelContext()
- Specified by:
getCamelContext
in interfaceorg.apache.camel.spi.HasCamelContext
-
doInit
protected void doInit()
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
-
doStart
protected void doStart() throws Exception
- Overrides:
doStart
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
doStop
protected void doStop() throws Exception
- Overrides:
doStop
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
fromStream
public org.reactivestreams.Publisher<org.apache.camel.Exchange> fromStream(String name)
Description copied from interface:CamelReactiveStreamsService
Returns the publisher associated to the given stream name. A publisher can be used to push Camel exchanges to reactive-streams subscribers.- Specified by:
fromStream
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream name- Returns:
- the stream publisher
-
fromStream
public <T> org.reactivestreams.Publisher<T> fromStream(String name, Class<T> cls)
Description copied from interface:CamelReactiveStreamsService
Returns the publisher associated to the given stream name. A publisher can be used to push Camel exchange to external reactive-streams subscribers. The publisher converts automatically exchanges to the given type.- Specified by:
fromStream
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the type of items emitted by the publisher- Parameters:
name
- the stream namecls
- the type of the emitted items- Returns:
- the publisher associated to the stream
-
streamSubscriber
public ReactiveStreamsCamelSubscriber streamSubscriber(String name)
Description copied from interface:CamelReactiveStreamsService
Returns the subscriber associated to the given stream name. A subscriber can be used to push items coming from external reactive-streams publishers to Camel routes.- Specified by:
streamSubscriber
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream name- Returns:
- the subscriber associated with the stream
-
streamSubscriber
public <T> org.reactivestreams.Subscriber<T> streamSubscriber(String name, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Returns the subscriber associated to the given stream name. A subscriber can be used to push items coming from external reactive-streams publishers to Camel routes. The subscriber converts automatically items of the given type to exchanges before pushing them.- Specified by:
streamSubscriber
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the type of items accepted by the subscriber- Parameters:
name
- the stream nametype
- the publisher converts automatically exchanges to the given type.- Returns:
- the subscriber associated with the stream
-
sendCamelExchange
public void sendCamelExchange(String name, org.apache.camel.Exchange exchange)
Description copied from interface:CamelReactiveStreamsService
Used by Camel to send the exchange to all active subscriptions on the given stream. The callback is used to signal that the exchange has been delivered to the subscribers.- Specified by:
sendCamelExchange
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream nameexchange
- the exchange to be forwarded to the external subscribers
-
toStream
public org.reactivestreams.Publisher<org.apache.camel.Exchange> toStream(String name, Object data)
Description copied from interface:CamelReactiveStreamsService
Pushes the given data into the specified Camel stream and returns a Publisher (mono) holding the resulting exchange or an error.- Specified by:
toStream
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream namedata
- the data to push- Returns:
- a publisher with the resulting exchange
-
toStream
public Function<?,? extends org.reactivestreams.Publisher<org.apache.camel.Exchange>> toStream(String name)
Description copied from interface:CamelReactiveStreamsService
Returns a function that pushes data into the specified Camel stream and returns a Publisher (mono) holding the resulting exchange or an error. This is a curryied version ofCamelReactiveStreamsService.toStream(String, Object)
.- Specified by:
toStream
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream name- Returns:
- a function that returns a publisher with the resulting exchange
-
toStream
public <T> org.reactivestreams.Publisher<T> toStream(String name, Object data, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Pushes the given data into the specified Camel stream and returns a Publisher (mono) holding the exchange output or an error.- Specified by:
toStream
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the generic type of the resulting Publisher- Parameters:
name
- the stream namedata
- the data to pushtype
- the type to which the output should be converted- Returns:
- a publisher with the resulting data
-
doRequest
protected org.reactivestreams.Publisher<org.apache.camel.Exchange> doRequest(String name, org.apache.camel.Exchange data)
-
toStream
public <T> Function<Object,org.reactivestreams.Publisher<T>> toStream(String name, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Returns a function that pushes data into the specified Camel stream and returns a Publisher (mono) holding the exchange output or an error. This is a curryied version ofCamelReactiveStreamsService.toStream(String, Object, Class)
.- Specified by:
toStream
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the generic type of the resulting Publisher- Parameters:
name
- the stream nametype
- the type to which the output should be converted- Returns:
- a function that returns a publisher with the resulting data
-
from
public org.reactivestreams.Publisher<org.apache.camel.Exchange> from(String uri)
Description copied from interface:CamelReactiveStreamsService
Creates a new stream from the endpoint URI (used as Camel Consumer) and returns the associatedPublisher
. If a stream has already been created, the existingPublisher
is returned.- Specified by:
from
in interfaceCamelReactiveStreamsService
- Parameters:
uri
- the consumer uri- Returns:
- the publisher associated to the uri
-
from
public <T> org.reactivestreams.Publisher<T> from(String uri, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Creates a new stream of the given type from the endpoint URI (used as Camel Consumer) and returns the associatedPublisher
. If a stream has already been created, the existingPublisher
is returned.- Specified by:
from
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the type to which Camel should convert exchanges to- Parameters:
uri
- the consumer uritype
- the type of items emitted by the publisher- Returns:
- the publisher associated to the uri
-
subscriber
public org.reactivestreams.Subscriber<org.apache.camel.Exchange> subscriber(String uri)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that pushes data to the endpoint URI and returns the associatedSubscriber
. This method always create a new stream.- Specified by:
subscriber
in interfaceCamelReactiveStreamsService
- Parameters:
uri
- the target uri- Returns:
- the subscriber associated to the uri
-
subscriber
public <T> org.reactivestreams.Subscriber<T> subscriber(String uri, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that pushes data to the endpoint URI and returns the associatedSubscriber
. This method always create a new stream.- Specified by:
subscriber
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the type from which Camel should convert data to exchanges- Parameters:
uri
- the target uritype
- the type of items that the subscriber can receive- Returns:
- the subscriber associated to the uri
-
to
public org.reactivestreams.Publisher<org.apache.camel.Exchange> to(String uri, Object data)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that uses the endpoint URI as producer, pushes the given data to the route and returns aPublisher
that will eventually return the resulting exchange or an error.- Specified by:
to
in interfaceCamelReactiveStreamsService
- Parameters:
uri
- the producer uridata
- the data to push- Returns:
- a publisher with the resulting exchange
-
to
public Function<Object,org.reactivestreams.Publisher<org.apache.camel.Exchange>> to(String uri)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that uses the endpoint URI as producer, and returns a function that pushes the data into the route and returns thePublisher
that holds the resulting exchange or the error. This is a curryied version ofCamelReactiveStreamsService.to(String, Object)
.- Specified by:
to
in interfaceCamelReactiveStreamsService
- Parameters:
uri
- the producer uri- Returns:
- a function that returns a publisher with the resulting exchange
-
to
public <T> org.reactivestreams.Publisher<T> to(String uri, Object data, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that uses the endpoint URI as producer, pushes the given data to the route and returns aPublisher
that will eventually return the exchange output or an error.- Specified by:
to
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the generic type of the resulting Publisher- Parameters:
uri
- the producer uridata
- the data to pushtype
- the type to which the output should be converted- Returns:
- a publisher with the resulting data
-
to
public <T> Function<Object,org.reactivestreams.Publisher<T>> to(String uri, Class<T> type)
Description copied from interface:CamelReactiveStreamsService
Creates a new route that uses the endpoint URI as producer, and returns a function that pushes the data into the route and returns thePublisher
that holds the exchange output or an error. This is a curryied version ofCamelReactiveStreamsService.to(String, Object, Class)
.- Specified by:
to
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the generic type of the resulting Publisher- Parameters:
uri
- the producer uritype
- the type to which the output should be converted- Returns:
- a function that returns a publisher with the resulting data
-
process
public void process(String uri, Function<? super org.reactivestreams.Publisher<org.apache.camel.Exchange>,?> processor)
Description copied from interface:CamelReactiveStreamsService
Adds a processing step at the specified endpoint uri (usually a "direct:name") that delegates to the given reactive processor. The processor receives aPublisher
of exchanges and returns an object. If the output of the processor is aPublisher
, it will be unwrapped before delivering the result to the source route.- Specified by:
process
in interfaceCamelReactiveStreamsService
- Parameters:
uri
- the uri where the processor should be attachedprocessor
- the reactive processor
-
process
public <T> void process(String uri, Class<T> type, Function<? super org.reactivestreams.Publisher<T>,?> processor)
Description copied from interface:CamelReactiveStreamsService
Adds a processing step at the specified endpoint uri (usually a "direct:name") that delegates to the given reactive processor. The processor receives aPublisher
of items of the given type and returns an object. If the output of the processor is aPublisher
, it will be unwrapped before delivering the result to the source route.- Specified by:
process
in interfaceCamelReactiveStreamsService
- Type Parameters:
T
- the generic type of the Publisher that should be processed- Parameters:
uri
- the uri where the processor should be attachedtype
- the type to which the body of the exchange should be convertedprocessor
- the reactive processor
-
attachCamelConsumer
public ReactiveStreamsCamelSubscriber attachCamelConsumer(String name, ReactiveStreamsConsumer consumer)
Description copied from interface:CamelReactiveStreamsService
Used by Camel to associate the subscriber of the stream with the given name to a specific Camel consumer. This method is used to bind a Camel route to a reactive stream.- Specified by:
attachCamelConsumer
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream nameconsumer
- the consumer of the route- Returns:
- the associated subscriber
-
detachCamelConsumer
public void detachCamelConsumer(String name)
Description copied from interface:CamelReactiveStreamsService
Used by Camel to detach the existing consumer from the given stream.- Specified by:
detachCamelConsumer
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream name
-
attachCamelProducer
public void attachCamelProducer(String name, ReactiveStreamsProducer producer)
Description copied from interface:CamelReactiveStreamsService
Used by Camel to associate the publisher of the stream with the given name to a specific Camel producer. This method is used to bind a Camel route to a reactive stream.- Specified by:
attachCamelProducer
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream nameproducer
- the producer of the route
-
detachCamelProducer
public void detachCamelProducer(String name)
Description copied from interface:CamelReactiveStreamsService
Used by Camel to detach the existing producer from the given stream.- Specified by:
detachCamelProducer
in interfaceCamelReactiveStreamsService
- Parameters:
name
- the stream name
-
camelSubscribers
@ManagedOperation(description="Information about Camel Reactive subscribers") public TabularData camelSubscribers()
-
camelPublishers
@ManagedOperation(description="Information about Camel Reactive publishers") public TabularData camelPublishers()
-
-