Class AbstractMessageChannel
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.channel.AbstractMessageChannel
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,ExpressionCapable
,IntegrationPattern
,NamedComponent
,IntegrationManagement
,TrackableComponent
,MessageChannel
,InterceptableChannel
- Direct Known Subclasses:
AbstractAmqpChannel
,AbstractJmsChannel
,AbstractKafkaChannel
,AbstractPollableChannel
,AbstractSubscribableChannel
,FluxMessageChannel
,SubscribableRedisChannel
,ZeroMqChannel
@IntegrationManagedResource
public abstract class AbstractMessageChannel
extends IntegrationObjectSupport
implements MessageChannel, TrackableComponent, InterceptableChannel, IntegrationManagement, IntegrationPattern
Base class for
MessageChannel
implementations providing common
properties such as the channel name. Also provides the common functionality
for sending and receiving Messages
including the invocation
of any ChannelInterceptors
.- Author:
- Mark Fisher, Oleg Zhurakousky, Gary Russell, Artem Bilan, Christian Tzolov
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
A convenience wrapper class for the list of ChannelInterceptors.Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Modifier and TypeFieldDescriptionprotected final AbstractMessageChannel.ChannelInterceptorList
protected final Set<MeterFacade>
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger
Fields inherited from interface org.springframework.integration.support.management.IntegrationManagement
METER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAME
Fields inherited from interface org.springframework.messaging.MessageChannel
INDEFINITE_TIMEOUT
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addInterceptor
(int index, ChannelInterceptor interceptor) Add a channel interceptor to the specified index of the list.void
addInterceptor
(ChannelInterceptor interceptor) Add a channel interceptor to the end of the list.void
destroy()
protected abstract boolean
Subclasses must implement this method.Subclasses may implement this method to provide component type information.Returns the fully qualified channel name including the application context id, if available.Exposes the interceptor list instance for subclasses.Return a pattern type this component implements.Return a read-only list of the configured interceptors.protected MetricsCaptor
Return the overrides.boolean
Return whether logging is enabled.boolean
True if this implementation is going to deal with a registry other than theObservationRegistry.NOOP
instance.protected void
onInit()
Subclasses may implement this for initialization logic.void
registerMetricsCaptor
(MetricsCaptor metricsCaptorToRegister) Inject aMetricsCaptor
.void
registerObservationRegistry
(io.micrometer.observation.ObservationRegistry observationRegistry) Inject anObservationRegistry
.removeInterceptor
(int index) boolean
removeInterceptor
(ChannelInterceptor interceptor) boolean
Send a message on this channel.boolean
Send a message on this channel.void
setDatatypes
(Class<?>... datatypes) Specify the Message payload datatype(s) supported by this channel.void
setInterceptors
(List<ChannelInterceptor> interceptors) Set the list of channel interceptors.void
setLoggingEnabled
(boolean loggingEnabled) Enable logging or not.void
setMessageConverter
(MessageConverter messageConverter) Specify theMessageConverter
to use when trying to convert to one of this channel's supported datatypes (in order) for a Message whose payload does not already match.void
setObservationConvention
(MessageSenderObservationConvention observationConvention) void
setShouldTrack
(boolean shouldTrack) Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentName, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentName, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getManagedName, getManagedType, getThisAs, setManagedName, setManagedType
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
interceptors
-
meters
-
-
Constructor Details
-
AbstractMessageChannel
public AbstractMessageChannel()
-
-
Method Details
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classIntegrationObjectSupport
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Returns:
- the
IntegrationPatternType
this component implements.
-
setShouldTrack
public void setShouldTrack(boolean shouldTrack) - Specified by:
setShouldTrack
in interfaceTrackableComponent
-
registerMetricsCaptor
Description copied from interface:IntegrationManagement
Inject aMetricsCaptor
. Ignored ifObservationRegistry
is provided.- Specified by:
registerMetricsCaptor
in interfaceIntegrationManagement
- Parameters:
metricsCaptorToRegister
- the captor.- See Also:
-
getMetricsCaptor
-
isLoggingEnabled
public boolean isLoggingEnabled()Description copied from interface:IntegrationManagement
Return whether logging is enabled.- Specified by:
isLoggingEnabled
in interfaceIntegrationManagement
- Returns:
- true if enabled.
-
setLoggingEnabled
public void setLoggingEnabled(boolean loggingEnabled) Description copied from interface:IntegrationManagement
Enable logging or not.- Specified by:
setLoggingEnabled
in interfaceIntegrationManagement
- Parameters:
loggingEnabled
- false to disable.
-
setDatatypes
Specify the Message payload datatype(s) supported by this channel. If a payload type does not match directly, but the 'conversionService' is available, then type conversion will be attempted in the order of the elements provided in this array.If this property is not set explicitly, any Message payload type will be accepted.
- Parameters:
datatypes
- The supported data types.- See Also:
-
setInterceptors
Set the list of channel interceptors. This will clear any existing interceptors.- Specified by:
setInterceptors
in interfaceInterceptableChannel
- Parameters:
interceptors
- The list of interceptors.
-
addInterceptor
Add a channel interceptor to the end of the list.- Specified by:
addInterceptor
in interfaceInterceptableChannel
- Parameters:
interceptor
- The interceptor.
-
addInterceptor
Add a channel interceptor to the specified index of the list.- Specified by:
addInterceptor
in interfaceInterceptableChannel
- Parameters:
index
- The index to add interceptor.interceptor
- The interceptor.
-
setMessageConverter
Specify theMessageConverter
to use when trying to convert to one of this channel's supported datatypes (in order) for a Message whose payload does not already match.Note: only the
MessageConverter.fromMessage(Message, Class)
method is used. If the returned object is not aMessage
, the inbound headers will be copied; if the returned object is aMessage
, it is expected that the converter will have fully populated the headers; no further action is performed by the channel. Ifnull
is returned, conversion to the next datatype (if any) will be attempted. Defaults to aDefaultDatatypeChannelMessageConverter
.- Parameters:
messageConverter
- The message converter.
-
setObservationConvention
public void setObservationConvention(@Nullable MessageSenderObservationConvention observationConvention) -
getInterceptors
Return a read-only list of the configured interceptors.- Specified by:
getInterceptors
in interfaceInterceptableChannel
-
removeInterceptor
- Specified by:
removeInterceptor
in interfaceInterceptableChannel
-
removeInterceptor
- Specified by:
removeInterceptor
in interfaceInterceptableChannel
-
getIChannelInterceptorList
Exposes the interceptor list instance for subclasses.- Returns:
- The channel interceptor list.
-
getOverrides
Description copied from interface:IntegrationManagement
Return the overrides.- Specified by:
getOverrides
in interfaceIntegrationManagement
- Returns:
- the overrides.
-
registerObservationRegistry
public void registerObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Description copied from interface:IntegrationManagement
Inject anObservationRegistry
. If provided, theMetricsCaptor
is ignored. The meters capturing has to be configured as anObservationHandler
on the providedObservationRegistry
.- Specified by:
registerObservationRegistry
in interfaceIntegrationManagement
- Parameters:
observationRegistry
- theObservationRegistry
to expose observations from the component.- See Also:
-
isObserved
public boolean isObserved()Description copied from interface:IntegrationManagement
True if this implementation is going to deal with a registry other than theObservationRegistry.NOOP
instance.- Specified by:
isObserved
in interfaceIntegrationManagement
- Returns:
- true if this implementation is going to deal with a registry other than the
ObservationRegistry.NOOP
instance.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
getFullChannelName
Returns the fully qualified channel name including the application context id, if available.- Returns:
- The name.
-
send
Send a message on this channel. If the channel is at capacity, this method will block until either space becomes available or the sending thread is interrupted.- Specified by:
send
in interfaceMessageChannel
- Parameters:
message
- the Message to send- Returns:
true
if the message is sent successfully orfalse
if the sending thread is interrupted.
-
send
Send a message on this channel. If the channel is at capacity, this method will block until either the timeout occurs or the sending thread is interrupted. If the specified timeout is 0, the method will return immediately. If less than zero, it will block indefinitely (seesend(Message)
).- Specified by:
send
in interfaceMessageChannel
- Parameters:
messageArg
- the Message to sendtimeout
- the timeout in milliseconds- Returns:
true
if the message is sent successfully,false
if the message cannot be sent within the allotted time or the sending thread is interrupted.
-
doSend
Subclasses must implement this method. A non-negative timeout indicates how long to wait if the channel is at capacity (if the value is 0, it must return immediately with or without success). A negative timeout value indicates that the method should block until either the message is accepted or the blocking thread is interrupted.- Parameters:
message
- The message.timeout
- The timeout.- Returns:
- true if the
send
was successful.
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Specified by:
destroy
in interfaceIntegrationManagement
-