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 Modifier and Type Class Description static class
DynamicRouterProcessor.DynamicRouterProcessorFactory
Create aDynamicRouterProcessor
instance.
-
Constructor Summary
Constructors Constructor Description DynamicRouterProcessor(String id, org.apache.camel.CamelContext camelContext, String recipientMode, boolean warnDroppedMessage, Supplier<PrioritizedFilterProcessor.PrioritizedFilterProcessorFactory> filterProcessorFactorySupplier)
Create the processor instance with all properties.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
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()
PrioritizedFilterProcessor
getFilter(String filterId)
Return the filter with the supplied filter identifier.String
getId()
Returns the id of the instance of this processor.String
getTraceLabel()
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
setId(String id)
Sets the id of the instance of this processor.String
toString()
The string representation of this dynamic router is its id.-
Methods inherited from class org.apache.camel.support.AsyncProcessorSupport
doStart, doStop, process, processAsync
-
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, wait, wait, wait
-
-
-
-
Constructor Detail
-
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 Detail
-
doInit
protected void doInit() throws Exception
- Overrides:
doInit
in classorg.apache.camel.support.service.BaseService
- Throws:
Exception
-
addFilter
public void addFilter(DynamicRouterControlMessage controlMessage)
Add a filter based on the supplied control message properties for exchange routing evaluation.- Parameters:
controlMessage
- the message for filter creation
-
addFilter
public void addFilter(PrioritizedFilterProcessor filter)
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
public PrioritizedFilterProcessor getFilter(String filterId)
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
public void removeFilter(String filterId)
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
public String toString()
The string representation of this dynamic router is its id.
-
getTraceLabel
public String getTraceLabel()
For tracing.- Specified by:
getTraceLabel
in interfaceorg.apache.camel.Traceable
- Returns:
- the label for tracing.
-
getId
public String getId()
Returns the id of the instance of this processor.- Specified by:
getId
in interfaceorg.apache.camel.spi.HasId
- Returns:
- the id
-
setId
public void setId(String id)
Sets the id of the instance of this processor.- Specified by:
setId
in interfaceorg.apache.camel.spi.IdAware
- Parameters:
id
- the id
-
-