Class MessagingGatewaySupport
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.MessagingGatewaySupport
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Phased
,SmartLifecycle
,ExpressionCapable
,IntegrationPattern
,NamedComponent
,IntegrationInboundManagement
,IntegrationManagement
,ManageableLifecycle
,ManageableSmartLifecycle
,TrackableComponent
- Direct Known Subclasses:
AbstractWebServiceInboundGateway
,AmqpInboundGateway
,BaseHttpInboundEndpoint
,JmsInboundGateway
,KafkaInboundGateway
,RedisQueueInboundGateway
,RSocketInboundGateway
,TcpInboundGateway
@IntegrationManagedResource
public abstract class MessagingGatewaySupport
extends AbstractEndpoint
implements TrackableComponent, IntegrationInboundManagement, IntegrationPattern
A convenient base class for connecting application code to
MessageChannel
s for sending, receiving, or request-reply operations.
Exposes setters for configuring request and reply MessageChannel
s as
well as the timeout values for sending and receiving Messages.- Author:
- Mark Fisher, Gary Russell, Artem Bilan, Trung Pham
-
Nested Class Summary
Modifier and TypeClassDescriptionprotected static class
TheMessagingTemplate
extension to increaseMessagingGatewaySupport.ConvertingMessagingTemplate.doConvert(Object, Map, MessagePostProcessor)
visibility to get access to the request message from an observation context.Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides
-
Field Summary
Modifier and TypeFieldDescriptionprotected final MessagingGatewaySupport.ConvertingMessagingTemplate
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
ConstructorDescriptionConstruct an instance that will return null if no reply is received.MessagingGatewaySupport
(boolean errorOnTimeout) If errorOnTimeout is true, construct an instance that will send anErrorMessage
with aMessageTimeoutException
payload to the error channel if a reply is expected but none is received. -
Method Summary
Modifier and TypeMethodDescriptionprotected final ErrorMessage
buildErrorMessage
(Message<?> requestMessage, Throwable throwable) Build an error message for the message and throwable using the configuredErrorMessageStrategy
.protected TimerFacade
buildSendTimer
(boolean success, String exception) void
destroy()
protected void
doStart()
Subclasses must implement this method with the start behavior.protected void
doStop()
Subclasses must implement this method with the stop behavior.Subclasses may implement this method to provide component type information.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.Return the overrides.Return this gateway's reply channel if any.Return this gateway's request channel.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.protected Object
receive()
protected Object
receive
(long timeout) protected Message<?>
protected Message<?>
receiveMessage
(long timeout) void
registerMetricsCaptor
(MetricsCaptor metricsCaptorToRegister) Inject aMetricsCaptor
.void
registerObservationRegistry
(io.micrometer.observation.ObservationRegistry observationRegistry) Inject anObservationRegistry
.protected void
protected void
protected Object
sendAndReceive
(Object object) protected Message<?>
sendAndReceiveMessage
(Object object) protected reactor.core.publisher.Mono<Message<?>>
sendAndReceiveMessageReactive
(Object object) protected TimerFacade
void
setErrorChannel
(MessageChannel errorChannel) Set the error channel.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
setErrorOnTimeout
(boolean errorOnTimeout) If errorOnTimeout is true, construct an instance that will send anErrorMessage
with aMessageTimeoutException
payload to the error channel if a reply is expected but none is received.void
setLoggingEnabled
(boolean enabled) Enable logging or not.void
setManagedName
(String managedName) void
setManagedType
(String managedType) void
setObservationConvention
(MessageRequestReplyReceiverObservationConvention observationConvention) void
setReceiverObservationConvention
(MessageReceiverObservationConvention receiverObservationConvention) void
setReplyChannel
(MessageChannel replyChannel) Set the reply channel.void
setReplyChannelName
(String replyChannelName) Set the reply channel name.void
setReplyMapper
(OutboundMessageMapper<?> replyMapper) Provide anOutboundMessageMapper
for mapping to objects from any reply Messages received in receive or sendAndReceive operations.void
setReplyTimeout
(long replyTimeout) Set the timeout value for receiving reply messages.void
setRequestChannel
(MessageChannel requestChannel) Set the request channel.void
setRequestChannelName
(String requestChannelName) Set the request channel name.void
setRequestMapper
(InboundMessageMapper<?> requestMapper) Provide anInboundMessageMapper
for creating request Messages from any object passed in asend
orsendAndReceive
operation.void
setRequestTimeout
(long requestTimeout) Set the timeout value for sending request messages.void
setShouldTrack
(boolean shouldTrack) Specify whether this gateway should be tracked in the Message History of Messages that originate from its send or sendAndReceive operations.Methods inherited from class org.springframework.integration.endpoint.AbstractEndpoint
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, getComponentName, getConversionService, getExpression, getIntegrationProperties, getIntegrationProperty, 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
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
messagingTemplate
-
-
Constructor Details
-
MessagingGatewaySupport
public MessagingGatewaySupport()Construct an instance that will return null if no reply is received. -
MessagingGatewaySupport
public MessagingGatewaySupport(boolean errorOnTimeout) If errorOnTimeout is true, construct an instance that will send anErrorMessage
with aMessageTimeoutException
payload to the error channel if a reply is expected but none is received. If no error channel is configured, theMessageTimeoutException
will be thrown.- Parameters:
errorOnTimeout
- true to create the error message.- Since:
- 4.2
- See Also:
-
-
Method Details
-
setErrorOnTimeout
public void setErrorOnTimeout(boolean errorOnTimeout) If errorOnTimeout is true, construct an instance that will send anErrorMessage
with aMessageTimeoutException
payload to the error channel if a reply is expected but none is received. If no error channel is configured, theMessageTimeoutException
will be thrown.- Parameters:
errorOnTimeout
- true to create the error message on reply timeout.- Since:
- 5.2.2
-
setRequestChannel
Set the request channel.- Parameters:
requestChannel
- the channel to which request messages will be sent
-
setRequestChannelName
Set the request channel name.- Parameters:
requestChannelName
- the channel bean name to which request messages will be sent- Since:
- 4.1
-
setReplyChannel
Set the reply channel. If no reply channel is provided, this gateway will always use an anonymous, temporary channel for handling replies.- Parameters:
replyChannel
- the channel from which reply messages will be received
-
setReplyChannelName
Set the reply channel name. If no reply channel is provided, this gateway will always use an anonymous, temporary channel for handling replies.- Parameters:
replyChannelName
- the channel bean name from which reply messages will be received- Since:
- 4.1
-
setErrorChannel
Set the error channel. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.- Parameters:
errorChannel
- The error channel.
-
setErrorChannelName
Set the error channel name. If no error channel is provided, this gateway will propagate Exceptions to the caller. To completely suppress Exceptions, provide a reference to the "nullChannel" here.- Parameters:
errorChannelName
- The error channel bean name.- Since:
- 4.1
-
setRequestTimeout
public void setRequestTimeout(long requestTimeout) Set the timeout value for sending request messages. If not explicitly configured, the default is one second.- Parameters:
requestTimeout
- the timeout value in milliseconds
-
setReplyTimeout
public void setReplyTimeout(long replyTimeout) Set the timeout value for receiving reply messages. If not explicitly configured, the default is one second.- Parameters:
replyTimeout
- the timeout value in milliseconds
-
setRequestMapper
Provide anInboundMessageMapper
for creating request Messages from any object passed in asend
orsendAndReceive
operation.- Parameters:
requestMapper
- The request mapper.
-
setReplyMapper
Provide anOutboundMessageMapper
for mapping to objects from any reply Messages received in receive or sendAndReceive operations.- Parameters:
replyMapper
- The reply mapper.
-
setShouldTrack
public void setShouldTrack(boolean shouldTrack) Specify whether this gateway should be tracked in the Message History of Messages that originate from its send or sendAndReceive operations.- Specified by:
setShouldTrack
in interfaceTrackableComponent
-
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
-
setLoggingEnabled
public void setLoggingEnabled(boolean enabled) Description copied from interface:IntegrationManagement
Enable logging or not.- Specified by:
setLoggingEnabled
in interfaceIntegrationManagement
- Parameters:
enabled
- false to disable.
-
isLoggingEnabled
public boolean isLoggingEnabled()Description copied from interface:IntegrationManagement
Return whether logging is enabled.- Specified by:
isLoggingEnabled
in interfaceIntegrationManagement
- Returns:
- true if enabled.
-
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
-
getOverrides
Description copied from interface:IntegrationManagement
Return the overrides.- Specified by:
getOverrides
in interfaceIntegrationManagement
- Returns:
- the overrides.
-
setManagedType
- Specified by:
setManagedType
in interfaceIntegrationManagement
-
getManagedType
- Specified by:
getManagedType
in interfaceIntegrationManagement
-
setManagedName
- Specified by:
setManagedName
in interfaceIntegrationManagement
-
getManagedName
- Specified by:
getManagedName
in interfaceIntegrationManagement
-
getIntegrationPatternType
Description copied from interface:IntegrationPattern
Return a pattern type this component implements.- Specified by:
getIntegrationPatternType
in interfaceIntegrationPattern
- Returns:
- the
IntegrationPatternType
this component implements.
-
registerMetricsCaptor
Description copied from interface:IntegrationManagement
Inject aMetricsCaptor
. Ignored ifObservationRegistry
is provided.- Specified by:
registerMetricsCaptor
in interfaceIntegrationManagement
- Parameters:
metricsCaptorToRegister
- the captor.- See Also:
-
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.
-
setObservationConvention
public void setObservationConvention(@Nullable MessageRequestReplyReceiverObservationConvention observationConvention) -
setReceiverObservationConvention
public void setReceiverObservationConvention(MessageReceiverObservationConvention receiverObservationConvention) -
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classAbstractEndpoint
-
getRequestChannel
Return this gateway's request channel.- Returns:
- the channel.
- Since:
- 4.2
-
getReplyChannel
Return this gateway's reply channel if any.- Returns:
- the reply channel instance
- Since:
- 5.1
-
getErrorChannel
Return the error channel (if provided) to which error messages will be routed.- Returns:
- the channel or null.
- Since:
- 4.3
-
send
-
receive
-
receiveMessage
-
receive
-
receiveMessage
-
sendAndReceive
-
sendAndReceiveMessage
-
sendAndReceiveMessageReactive
-
sendTimer
-
buildSendTimer
-
buildErrorMessage
protected final ErrorMessage buildErrorMessage(@Nullable Message<?> requestMessage, Throwable throwable) Build an error message for the message and throwable using the configuredErrorMessageStrategy
.- Parameters:
requestMessage
- the requestMessage.throwable
- the throwable.- 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
-
registerReplyMessageCorrelatorIfNecessary
protected void registerReplyMessageCorrelatorIfNecessary() -
doStart
protected void doStart()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Specified by:
doStart
in classAbstractEndpoint
-
doStop
protected void doStop()Description copied from class:AbstractEndpoint
Subclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock
.- Specified by:
doStop
in classAbstractEndpoint
-
destroy
public void destroy()- Specified by:
destroy
in interfaceDisposableBean
- Specified by:
destroy
in interfaceIntegrationManagement
- Overrides:
destroy
in classAbstractEndpoint
-