Class 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.
    • 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
    • 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 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 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 processor
        camelContext - the camel context
        recipientMode - the recipient mode
        warnDroppedMessage - flag to warn if messages are dropped
        filterProcessorFactorySupplier - creates the PrioritizedFilterProcessor
    • Method Detail

      • doInit

        protected void doInit()
                       throws Exception
        Overrides:
        doInit in class org.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 all filterMap 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 caused Exception would be set on the Exchange.

        Specified by:
        process in interface org.apache.camel.AsyncProcessor
        Parameters:
        exchange - the message exchange
        callback - the AsyncCallback 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.
        Overrides:
        toString in class Object
        Returns:
        the id
      • getTraceLabel

        public String getTraceLabel()
        For tracing.
        Specified by:
        getTraceLabel in interface org.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 interface org.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 interface org.apache.camel.spi.IdAware
        Parameters:
        id - the id