Class MessageFilter
java.lang.Object
- All Implemented Interfaces:
org.reactivestreams.Subscriber<Message<?>>,Aware,BeanClassLoaderAware,BeanFactoryAware,BeanNameAware,DisposableBean,InitializingBean,ApplicationContextAware,Lifecycle,Ordered,ExpressionCapable,Orderable,MessageProducer,DiscardingMessageHandler,HeaderPropagationAware,PostProcessingMessageHandler,IntegrationPattern,NamedComponent,IntegrationManagement,ManageableLifecycle,TrackableComponent,MessageHandler,reactor.core.CoreSubscriber<Message<?>>
public class MessageFilter
extends AbstractReplyProducingPostProcessingMessageHandler
implements DiscardingMessageHandler, ManageableLifecycle
Message Handler that delegates to a
MessageSelector. If and only if
the selector accepts the Message, it
will be passed to this filter's output channel. Otherwise the message will
either be silently dropped (the default) or will trigger the throwing of a
MessageRejectedException depending on the value of its
throwExceptionOnRejection property. If a discard channel is
provided, the rejected Messages will be sent to that channel.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, David Liu
-
Nested Class Summary
Nested classes/interfaces inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
AbstractReplyProducingMessageHandler.RequestHandlerNested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
messagingTemplateFields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE -
Constructor Summary
ConstructorsConstructorDescriptionMessageFilter(MessageSelector selector) Create a MessageFilter that will delegate to the givenMessageSelector. -
Method Summary
Modifier and TypeMethodDescriptionprotected ObjectdoHandleRequestMessage(Message<?> message) protected voiddoInit()Subclasses may implement this method to provide component type information.Return the discard channel.Return a pattern type this component implements.booleanpostProcess(Message<?> message, Object result) Take some further action on the result and/or message.voidsetDiscardChannel(MessageChannel discardChannel) Specify a channel where rejected Messages should be sent.voidsetDiscardChannelName(String discardChannelName) voidsetDiscardWithinAdvice(boolean discardWithinAdvice) Set to 'true' if you wish the discard processing to occur within any request handler advice applied to this filter.voidsetThrowExceptionOnRejection(boolean throwExceptionOnRejection) Specify whether this filter should throw aMessageRejectedExceptionwhen its selector does not accept a Message.protected booleanSubclasses may override this.voidstart()voidstop()Methods inherited from class org.springframework.integration.handler.AbstractReplyProducingPostProcessingMessageHandler
doInvokeAdvisedRequestHandler, handleRequestMessage, setPostProcessWithinAdviceMethods inherited from class org.springframework.integration.handler.AbstractReplyProducingMessageHandler
getBeanClassLoader, getRequiresReply, handleMessageInternal, hasAdviceChain, onInit, setAdviceChain, setBeanClassLoader, setRequiresReplyMethods inherited from class org.springframework.integration.handler.AbstractMessageProducingHandler
addNotPropagatedHeaders, createOutputMessage, getNotPropagatedHeaders, getOutputChannel, isAsync, messageBuilderForReply, produceOutput, resolveErrorChannel, sendErrorMessage, sendOutput, sendOutputs, setAsync, setNotPropagatedHeaders, setOutputChannel, setOutputChannelName, setSendTimeout, setupMessageProcessor, shouldSplitOutput, updateNotPropagatedHeadersMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConventionMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface reactor.core.CoreSubscriber
currentContextMethods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.messaging.MessageHandler
handleMessageMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
MessageFilter
Create a MessageFilter that will delegate to the givenMessageSelector.- Parameters:
selector- The message selector.
-
-
Method Details
-
setThrowExceptionOnRejection
public void setThrowExceptionOnRejection(boolean throwExceptionOnRejection) Specify whether this filter should throw aMessageRejectedExceptionwhen its selector does not accept a Message. The default value isfalsemeaning that rejected Messages will be quietly dropped or sent to the discard channel if available. Typically this value would not betruewhen a discard channel is provided, but if so, it will still apply (in such a case, the Message will be sent to the discard channel, and then the exception will be thrown).- Parameters:
throwExceptionOnRejection- true if an exception should be thrown.- See Also:
-
setDiscardChannel
Specify a channel where rejected Messages should be sent. If the discard channel is null (the default), rejected Messages will be dropped. However, the 'throwExceptionOnRejection' flag determines whether rejected Messages trigger an exception. That value is evaluated regardless of the presence of a discard channel.- Parameters:
discardChannel- The discard channel.- See Also:
-
setDiscardChannelName
-
setDiscardWithinAdvice
public void setDiscardWithinAdvice(boolean discardWithinAdvice) Set to 'true' if you wish the discard processing to occur within any request handler advice applied to this filter. Also applies to throwing an exception on rejection. Default: true.- Parameters:
discardWithinAdvice- true to discard within the advice.
-
getDiscardChannel
Description copied from interface:DiscardingMessageHandlerReturn the discard channel.- Specified by:
getDiscardChannelin interfaceDiscardingMessageHandler- Returns:
- the channel.
-
getComponentType
Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classMessageHandlerSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPatternReturn a pattern type this component implements.- Specified by:
getIntegrationPatternTypein interfaceIntegrationPattern- Overrides:
getIntegrationPatternTypein classAbstractReplyProducingMessageHandler- Returns:
- the
IntegrationPatternTypethis component implements.
-
doInit
protected void doInit()- Overrides:
doInitin classAbstractReplyProducingMessageHandler
-
start
public void start()- Specified by:
startin interfaceLifecycle- Specified by:
startin interfaceManageableLifecycle
-
stop
public void stop()- Specified by:
stopin interfaceLifecycle- Specified by:
stopin interfaceManageableLifecycle
-
isRunning
public boolean isRunning()- Specified by:
isRunningin interfaceLifecycle- Specified by:
isRunningin interfaceManageableLifecycle
-
doHandleRequestMessage
- Specified by:
doHandleRequestMessagein classAbstractReplyProducingPostProcessingMessageHandler
-
postProcess
Description copied from interface:PostProcessingMessageHandlerTake some further action on the result and/or message.- Specified by:
postProcessin interfacePostProcessingMessageHandler- Parameters:
message- The message.result- The result fromAbstractMessageHandler.handleMessageInternal(Message).- Returns:
- The post-processed result.
-
shouldCopyRequestHeaders
protected boolean shouldCopyRequestHeaders()Description copied from class:AbstractMessageProducingHandlerSubclasses may override this. True by default.- Overrides:
shouldCopyRequestHeadersin classAbstractMessageProducingHandler- Returns:
- true if the request headers should be copied.
-