Class DynamicRouterProcessor
java.lang.Object
org.apache.camel.support.service.BaseService
org.apache.camel.support.service.ServiceSupport
org.apache.camel.support.AsyncProcessorSupport
org.apache.camel.component.dynamicrouter.DynamicRouterProcessor
- All Implemented Interfaces:
AutoCloseable
,org.apache.camel.AsyncProcessor
,org.apache.camel.Processor
,org.apache.camel.Service
,org.apache.camel.ShutdownableService
,org.apache.camel.spi.HasId
,org.apache.camel.spi.IdAware
,org.apache.camel.StatefulService
,org.apache.camel.SuspendableService
,org.apache.camel.Traceable
@ManagedResource(description="Managed Dynamic Router Processor")
public class DynamicRouterProcessor
extends org.apache.camel.support.AsyncProcessorSupport
implements org.apache.camel.Traceable, org.apache.camel.spi.IdAware
Implements a Dynamic Router pattern where the destinations
are computed at runtime. Recipients register rules and their endpoint with the dynamic router. For each message, each
registered recipient's rules are evaluated, and the message is routed to the first recipient that matches.
-
Nested Class Summary
Nested Classes -
Field Summary
Fields inherited from class org.apache.camel.support.service.BaseService
BUILT, FAILED, INITIALIZED, INITIALIZING, lock, NEW, SHUTDOWN, SHUTTING_DOWN, STARTED, STARTING, status, STOPPED, STOPPING, SUSPENDED, SUSPENDING
-
Constructor Summary
ConstructorsConstructorDescriptionDynamicRouterProcessor
(String id, org.apache.camel.CamelContext camelContext, String recipientMode, boolean warnDroppedMessage, Supplier<PrioritizedFilterProcessor.PrioritizedFilterProcessorFactory> filterProcessorFactorySupplier) Create the processor instance with all properties. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addFilter
(DynamicRouterControlMessage controlMessage) Add a filter based on the supplied control message properties for exchange routing evaluation.void
addFilter
(PrioritizedFilterProcessor filter) Adds the filter to the list of filters, and ensure that the filters are sorted by priority after the insertion.protected void
doInit()
Return the filter with the supplied filter identifier.getId()
Returns the id of the instance of this processor.For tracing.boolean
process
(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) Processes the message exchange, where the caller supports having the exchange asynchronously processed.void
removeFilter
(String filterId) Removes a filter with the ID from the control message.void
Sets the id of the instance of this processor.toString()
The string representation of this dynamic router is its id.Methods inherited from class org.apache.camel.support.AsyncProcessorSupport
process, processAsync
Methods inherited from class org.apache.camel.support.service.BaseService
build, doBuild, doFail, doLifecycleChange, doResume, doShutdown, doStart, doStop, 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, wait, wait, wait
Methods inherited from interface org.apache.camel.spi.IdAware
setGeneratedId
Methods inherited from interface org.apache.camel.Service
build, close, init, start, stop
Methods inherited from interface org.apache.camel.ShutdownableService
shutdown
Methods inherited from interface org.apache.camel.StatefulService
getStatus, isRunAllowed, isStarted, isStarting, isStopped, isStopping, isSuspending
Methods inherited from interface org.apache.camel.SuspendableService
isSuspended, resume, suspend
-
Constructor Details
-
DynamicRouterProcessor
public DynamicRouterProcessor(String id, org.apache.camel.CamelContext camelContext, String recipientMode, boolean warnDroppedMessage, Supplier<PrioritizedFilterProcessor.PrioritizedFilterProcessorFactory> filterProcessorFactorySupplier) Create the processor instance with all properties.- Parameters:
id
- the id of the processorcamelContext
- the camel contextrecipientMode
- the recipient modewarnDroppedMessage
- flag to warn if messages are droppedfilterProcessorFactorySupplier
- creates thePrioritizedFilterProcessor
-
-
Method Details
-
doInit
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
addFilter
Add a filter based on the supplied control message properties for exchange routing evaluation.- Parameters:
controlMessage
- the message for filter creation
-
addFilter
Adds the filter to the list of filters, and ensure that the filters are sorted by priority after the insertion.- Parameters:
filter
- the filter to add
-
getFilter
Return the filter with the supplied filter identifier. If there is no such filter, then return null.- Parameters:
filterId
- the filter identifier- Returns:
- the filter with the supplied ID, or null
-
removeFilter
Removes a filter with the ID from the control message.- Parameters:
filterId
- the ID of the filter to remove
-
process
public boolean process(org.apache.camel.Exchange exchange, org.apache.camel.AsyncCallback callback) Processes the message exchange, where the caller supports having the exchange asynchronously processed. The exchange is matched against allfilterMap
to determine if any of them are suitable to handle the exchange. When the first suitable filter is found, it processes the exchange. If there was any failure in processing, then the causedException
would be set on theExchange
.- Specified by:
process
in interfaceorg.apache.camel.AsyncProcessor
- Parameters:
exchange
- the message exchangecallback
- theAsyncCallback
will be invoked when the processing of the exchange is completed. If the exchange is completed synchronously, then the callback is also invoked synchronously. The callback should therefore be careful of starting recursive loop.- Returns:
- (doneSync) true to continue to execute synchronously, false to continue execution asynchronously
-
toString
The string representation of this dynamic router is its id. -
getTraceLabel
For tracing.- Specified by:
getTraceLabel
in interfaceorg.apache.camel.Traceable
- Returns:
- the label for tracing.
-
getId
Returns the id of the instance of this processor.- Specified by:
getId
in interfaceorg.apache.camel.spi.HasId
- Returns:
- the id
-
setId
Sets the id of the instance of this processor.- Specified by:
setId
in interfaceorg.apache.camel.spi.IdAware
- Parameters:
id
- the id
-