Class MessageProducerSupport
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.endpoint.MessageProducerSupport
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,SmartInitializingSingleton
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ComponentSourceAware
,ExpressionCapable
,MessageProducer
,IntegrationPattern
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
- Direct Known Subclasses:
AbstractHazelcastMessageProducer
,AbstractInternetProtocolReceivingChannelAdapter
,AbstractMqttMessageDrivenChannelAdapter
,AbstractXmppConnectionAwareEndpoint
,AmqpInboundChannelAdapter
,DebeziumMessageProducer
,ExpressionMessageProducerSupport
,FileTailingMessageProducerSupport
,HazelcastClusterMonitorMessageProducer
,ImapIdleChannelAdapter
,JmsMessageDrivenEndpoint
,KafkaMessageDrivenChannelAdapter
,MongoDbChangeStreamMessageProducer
,NotificationListeningMessageProducer
,ReactiveMessageSourceProducer
,ReactiveRedisStreamMessageProducer
,RedisInboundChannelAdapter
,RedisQueueMessageDrivenEndpoint
,StompInboundChannelAdapter
,SyslogReceivingChannelAdapterSupport
,TcpReceivingChannelAdapter
,WebSocketInboundChannelAdapter
,ZeroMqMessageProducer
public abstract class MessageProducerSupport
extends AbstractEndpoint
implements MessageProducer, TrackableComponent, SmartInitializingSingleton, IntegrationPattern, IntegrationInboundManagement
A support class for producer endpoints that provides a setter for the
output channel and a convenience method for sending Messages.
- Author:
- Mark Fisher, Artem Bilan, Gary Russell
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Fields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLock
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.context.SmartLifecycle
DEFAULT_PHASE
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
protected final ErrorMessage
buildErrorMessage
(Message<?> message, Exception exception) Build an error message for the exception and message using the configuredErrorMessageStrategy
.protected void
doStart()
Take no action by default.protected void
doStop()
Take no action by default.Return the error channel (if provided) to which error messages will be routed.protected AttributeAccessor
getErrorMessageAttributes
(Message<?> message) Populate anAttributeAccessor
to be used when building an error message with theerrorMessageStrategy
.protected ErrorMessageStrategy
Get anErrorMessageStrategy
to use to build an error message when a exception occurs.Return a pattern type this component implements.protected MessagingTemplate
Return the output channel.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
registerObservationRegistry
(io.micrometer.observation.ObservationRegistry observationRegistry) Inject anObservationRegistry
.protected final boolean
sendErrorMessageIfNecessary
(Message<?> message, Exception exception) Send an error message based on the exception and message.protected void
sendMessage
(Message<?> message) void
setErrorChannel
(MessageChannel errorChannel) void
setErrorChannelName
(String errorChannelName) Set the error channel name.final void
setErrorMessageStrategy
(ErrorMessageStrategy errorMessageStrategy) Set anErrorMessageStrategy
to use to build an error message when a exception occurs.void
setObservationConvention
(MessageReceiverObservationConvention observationConvention) Set a customMessageReceiverObservationConvention
forIntegrationObservation.HANDLER
.void
setOutputChannel
(MessageChannel outputChannel) Specify theMessageChannel
to which produced Messages should be sent.void
setOutputChannelName
(String outputChannelName) Set the output channel name; overridesoutputChannel
if provided.void
setSendTimeout
(long sendTimeout) Configure the default timeout value to use for send operations.void
setShouldTrack
(boolean shouldTrack) protected void
subscribeToPublisher
(org.reactivestreams.Publisher<? extends Message<?>> publisher) Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
destroy, doStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stop
Methods inherited from class org.springframework.integration.context.IntegrationObjectSupport
afterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getComponentType, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, 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
destroy, getManagedName, getManagedType, getOverrides, getThisAs, isLoggingEnabled, registerMetricsCaptor, setLoggingEnabled, setManagedName, setManagedType
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName, getComponentType
-
Constructor Details
-
MessageProducerSupport
protected MessageProducerSupport()
-
-
Method Details
-
setOutputChannel
Description copied from interface:MessageProducer
Specify theMessageChannel
to which produced Messages should be sent.- Specified by:
setOutputChannel
in interfaceMessageProducer
- Parameters:
outputChannel
- The output channel.
-
setOutputChannelName
Set the output channel name; overridesoutputChannel
if provided.- Specified by:
setOutputChannelName
in interfaceMessageProducer
- Parameters:
outputChannelName
- the channel name.- Since:
- 4.3
-
getOutputChannel
Description copied from interface:MessageProducer
Return the output channel.- Specified by:
getOutputChannel
in interfaceMessageProducer
- Returns:
- the channel.
-
setErrorChannel
-
setErrorChannelName
Set the error channel name. If no error channel is provided, this endpoint will propagate Exceptions to the message-driven source. To completely suppress Exceptions, provide a reference to the "nullChannel" here.- Parameters:
errorChannelName
- The error channel bean name.- Since:
- 4.3
-
getErrorChannel
Return the error channel (if provided) to which error messages will be routed.- Returns:
- the channel or null.
- Since:
- 4.3
-
setSendTimeout
public void setSendTimeout(long sendTimeout) Configure the default timeout value to use for send operations. May be overridden for individual messages.- Parameters:
sendTimeout
- the 'send' operation timeout in milliseconds- See Also:
-
setShouldTrack
public void setShouldTrack(boolean shouldTrack) - Specified by:
setShouldTrack
in interfaceTrackableComponent
-
setErrorMessageStrategy
Set anErrorMessageStrategy
to use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy
.- Parameters:
errorMessageStrategy
- theErrorMessageStrategy
.- Since:
- 4.3.10
-
getErrorMessageStrategy
Get anErrorMessageStrategy
to use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy
.- Returns:
- the errorMessageStrategy
- Since:
- 6.0
-
getMessagingTemplate
-
setObservationConvention
public void setObservationConvention(@Nullable MessageReceiverObservationConvention observationConvention) Set a customMessageReceiverObservationConvention
forIntegrationObservation.HANDLER
. Ignored if anObservationRegistry
is not configured for this component.- Parameters:
observationConvention
- theMessageReceiverObservationConvention
to use.- Since:
- 6.0
-
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.
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Returns:
- the
IntegrationPatternType
this component implements.
-
afterSingletonsInstantiated
public void afterSingletonsInstantiated()- Specified by:
afterSingletonsInstantiated
in interfaceSmartInitializingSingleton
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractEndpoint
-
doStart
protected void doStart()Take no action by default. Subclasses may override this if they need lifecycle-managed behavior. Protected by 'lifecycleLock'.- Specified by:
doStart
in classAbstractEndpoint
-
doStop
protected void doStop()Take no action by default. Subclasses may override this if they need lifecycle-managed behavior.- Specified by:
doStop
in classAbstractEndpoint
-
sendMessage
-
subscribeToPublisher
-
sendErrorMessageIfNecessary
protected final boolean sendErrorMessageIfNecessary(@Nullable Message<?> message, Exception exception) Send an error message based on the exception and message.- Parameters:
message
- the message.exception
- the exception.- Returns:
- true if the error channel is available and message sent.
- Since:
- 4.3.10
-
buildErrorMessage
Build an error message for the exception and message using the configuredErrorMessageStrategy
.- Parameters:
message
- the message.exception
- the exception.- Returns:
- the error message.
- Since:
- 4.3.10
-
getErrorMessageAttributes
Populate anAttributeAccessor
to be used when building an error message with theerrorMessageStrategy
.- Parameters:
message
- the message.- Returns:
- the attributes.
- Since:
- 4.3.10
-