Class MessagingGatewaySupport
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.endpoint.AbstractEndpoint
org.springframework.integration.gateway.MessagingGatewaySupport
- All Implemented Interfaces:
org.springframework.beans.factory.Aware,org.springframework.beans.factory.BeanFactoryAware,org.springframework.beans.factory.BeanNameAware,org.springframework.beans.factory.DisposableBean,org.springframework.beans.factory.InitializingBean,org.springframework.context.ApplicationContextAware,org.springframework.context.Lifecycle,org.springframework.context.Phased,org.springframework.context.SmartLifecycle,ExpressionCapable,IntegrationPattern,NamedComponent,IntegrationInboundManagement,IntegrationManagement,ManageableLifecycle,ManageableSmartLifecycle,TrackableComponent
@IntegrationManagedResource public abstract class MessagingGatewaySupport extends AbstractEndpoint implements TrackableComponent, IntegrationInboundManagement, IntegrationPattern
A convenient base class for connecting application code to
MessageChannels for sending, receiving, or request-reply operations.
Exposes setters for configuring request and reply MessageChannels as
well as the timeout values for sending and receiving Messages.-
Nested Class Summary
Nested classes/interfaces inherited from interface org.springframework.integration.support.management.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
Fields Modifier and Type Field Description protected MessagingTemplatemessagingTemplateFields inherited from class org.springframework.integration.endpoint.AbstractEndpoint
lifecycleCondition, lifecycleLockFields 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_NAME -
Constructor Summary
Constructors Constructor Description MessagingGatewaySupport()Construct an instance that will return null if no reply is received.MessagingGatewaySupport(boolean errorOnTimeout)If errorOnTimeout is true, construct an instance that will send anErrorMessagewith aMessageTimeoutExceptionpayload to the error channel if a reply is expected but none is received. -
Method Summary
Modifier and Type Method Description protected org.springframework.messaging.support.ErrorMessagebuildErrorMessage(org.springframework.messaging.Message<?> requestMessage, java.lang.Throwable throwable)Build an error message for the message and throwable using the configuredErrorMessageStrategy.protected TimerFacadebuildSendTimer(boolean success, java.lang.String exception)voiddestroy()protected voiddoStart()Subclasses must implement this method with the start behavior.protected voiddoStop()Subclasses must implement this method with the stop behavior.java.lang.StringgetComponentType()Subclasses may implement this method to provide component type information.org.springframework.messaging.MessageChannelgetErrorChannel()Return the error channel (if provided) to which error messages will be routed.protected org.springframework.core.AttributeAccessorgetErrorMessageAttributes(org.springframework.messaging.Message<?> message)Populate anAttributeAccessorto be used when building an error message with theerrorMessageStrategy.IntegrationPatternTypegetIntegrationPatternType()Return a pattern type this component implements.java.lang.StringgetManagedName()java.lang.StringgetManagedType()IntegrationManagement.ManagementOverridesgetOverrides()Return the overrides.org.springframework.messaging.MessageChannelgetReplyChannel()Return this gateway's reply channel if any.org.springframework.messaging.MessageChannelgetRequestChannel()Return this gateway's request channel.booleanisLoggingEnabled()Return whether logging is enabled.protected voidonInit()Subclasses may implement this for initialization logic.protected java.lang.Objectreceive()protected java.lang.Objectreceive(long timeout)protected org.springframework.messaging.Message<?>receiveMessage()protected org.springframework.messaging.Message<?>receiveMessage(long timeout)voidregisterMetricsCaptor(MetricsCaptor metricsCaptorToRegister)Inject aMetricsCaptorprotected voidregisterReplyMessageCorrelatorIfNecessary()protected voidsend(java.lang.Object object)protected java.lang.ObjectsendAndReceive(java.lang.Object object)protected org.springframework.messaging.Message<?>sendAndReceiveMessage(java.lang.Object object)protected reactor.core.publisher.Mono<org.springframework.messaging.Message<?>>sendAndReceiveMessageReactive(java.lang.Object object)protected TimerFacadesendTimer()voidsetErrorChannel(org.springframework.messaging.MessageChannel errorChannel)Set the error channel.voidsetErrorChannelName(java.lang.String errorChannelName)Set the error channel name.voidsetErrorMessageStrategy(ErrorMessageStrategy errorMessageStrategy)Set anErrorMessageStrategyto use to build an error message when a exception occurs.voidsetErrorOnTimeout(boolean errorOnTimeout)If errorOnTimeout is true, construct an instance that will send anErrorMessagewith aMessageTimeoutExceptionpayload to the error channel if a reply is expected but none is received.voidsetLoggingEnabled(boolean enabled)Enable logging or not.voidsetManagedName(java.lang.String managedName)voidsetManagedType(java.lang.String managedType)voidsetReplyChannel(org.springframework.messaging.MessageChannel replyChannel)Set the reply channel.voidsetReplyChannelName(java.lang.String replyChannelName)Set the reply channel name.voidsetReplyMapper(OutboundMessageMapper<?> replyMapper)Provide anOutboundMessageMapperfor mapping to objects from any reply Messages received in receive or sendAndReceive operations.voidsetReplyTimeout(long replyTimeout)Set the timeout value for receiving reply messages.voidsetRequestChannel(org.springframework.messaging.MessageChannel requestChannel)Set the request channel.voidsetRequestChannelName(java.lang.String requestChannelName)Set the request channel name.voidsetRequestMapper(InboundMessageMapper<?> requestMapper)Provide anInboundMessageMapperfor creating request Messages from any object passed in a send or sendAndReceive operation.voidsetRequestTimeout(long requestTimeout)Set the timeout value for sending request messages.voidsetShouldTrack(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, stopMethods 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 org.springframework.integration.support.management.IntegrationManagement
getThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Field Details
-
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 anErrorMessagewith aMessageTimeoutExceptionpayload to the error channel if a reply is expected but none is received. If no error channel is configured, theMessageTimeoutExceptionwill be thrown.- Parameters:
errorOnTimeout- true to create the error message.- Since:
- 4.2
- See Also:
setErrorOnTimeout(boolean)
-
-
Method Details
-
setErrorOnTimeout
public void setErrorOnTimeout(boolean errorOnTimeout)If errorOnTimeout is true, construct an instance that will send anErrorMessagewith aMessageTimeoutExceptionpayload to the error channel if a reply is expected but none is received. If no error channel is configured, theMessageTimeoutExceptionwill be thrown.- Parameters:
errorOnTimeout- true to create the error message on reply timeout.- Since:
- 5.2.2
-
setRequestChannel
public void setRequestChannel(org.springframework.messaging.MessageChannel requestChannel)Set the request channel.- Parameters:
requestChannel- the channel to which request messages will be sent
-
setRequestChannelName
public void setRequestChannelName(java.lang.String requestChannelName)Set the request channel name.- Parameters:
requestChannelName- the channel bean name to which request messages will be sent- Since:
- 4.1
-
setReplyChannel
public void setReplyChannel(org.springframework.messaging.MessageChannel replyChannel)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
public void setReplyChannelName(java.lang.String replyChannelName)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
public void setErrorChannel(org.springframework.messaging.MessageChannel errorChannel)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
public void setErrorChannelName(java.lang.String errorChannelName)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 anInboundMessageMapperfor creating request Messages from any object passed in a send or sendAndReceive operation.- Parameters:
requestMapper- The request mapper.
-
setReplyMapper
Provide anOutboundMessageMapperfor 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:
setShouldTrackin interfaceTrackableComponent
-
getComponentType
public java.lang.String getComponentType()Description copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
getComponentTypein interfaceNamedComponent- Overrides:
getComponentTypein classIntegrationObjectSupport
-
setLoggingEnabled
public void setLoggingEnabled(boolean enabled)Description copied from interface:IntegrationManagementEnable logging or not.- Specified by:
setLoggingEnabledin interfaceIntegrationManagement- Parameters:
enabled- dalse to disable.
-
isLoggingEnabled
public boolean isLoggingEnabled()Description copied from interface:IntegrationManagementReturn whether logging is enabled.- Specified by:
isLoggingEnabledin interfaceIntegrationManagement- Returns:
- true if enabled.
-
setErrorMessageStrategy
Set anErrorMessageStrategyto use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy.- Parameters:
errorMessageStrategy- theErrorMessageStrategy.- Since:
- 4.3.10
-
getOverrides
Description copied from interface:IntegrationManagementReturn the overrides.- Specified by:
getOverridesin interfaceIntegrationManagement- Returns:
- the overrides.
-
setManagedType
public void setManagedType(java.lang.String managedType)- Specified by:
setManagedTypein interfaceIntegrationManagement
-
getManagedType
public java.lang.String getManagedType()- Specified by:
getManagedTypein interfaceIntegrationManagement
-
setManagedName
public void setManagedName(java.lang.String managedName)- Specified by:
setManagedNamein interfaceIntegrationManagement
-
getManagedName
public java.lang.String getManagedName()- Specified by:
getManagedNamein interfaceIntegrationManagement
-
getIntegrationPatternType
Description copied from interface:IntegrationPatternReturn a pattern type this component implements.- Specified by:
getIntegrationPatternTypein interfaceIntegrationPattern- Returns:
- the
IntegrationPatternTypethis component implements.
-
registerMetricsCaptor
Description copied from interface:IntegrationManagementInject aMetricsCaptor- Specified by:
registerMetricsCaptorin interfaceIntegrationManagement- Parameters:
metricsCaptorToRegister- the captor.
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin classAbstractEndpoint
-
getRequestChannel
@Nullable public org.springframework.messaging.MessageChannel getRequestChannel()Return this gateway's request channel.- Returns:
- the channel.
- Since:
- 4.2
-
getReplyChannel
@Nullable public org.springframework.messaging.MessageChannel getReplyChannel()Return this gateway's reply channel if any.- Returns:
- the reply channel instance
- Since:
- 5.1
-
getErrorChannel
@Nullable public org.springframework.messaging.MessageChannel getErrorChannel()Return the error channel (if provided) to which error messages will be routed.- Returns:
- the channel or null.
- Since:
- 4.3
-
send
protected void send(java.lang.Object object) -
receive
@Nullable protected java.lang.Object receive() -
receiveMessage
@Nullable protected org.springframework.messaging.Message<?> receiveMessage() -
receive
@Nullable protected java.lang.Object receive(long timeout) -
receiveMessage
@Nullable protected org.springframework.messaging.Message<?> receiveMessage(long timeout) -
sendAndReceive
@Nullable protected java.lang.Object sendAndReceive(java.lang.Object object) -
sendAndReceiveMessage
@Nullable protected org.springframework.messaging.Message<?> sendAndReceiveMessage(java.lang.Object object) -
sendAndReceiveMessageReactive
protected reactor.core.publisher.Mono<org.springframework.messaging.Message<?>> sendAndReceiveMessageReactive(java.lang.Object object) -
sendTimer
-
buildSendTimer
-
buildErrorMessage
protected final org.springframework.messaging.support.ErrorMessage buildErrorMessage(@Nullable org.springframework.messaging.Message<?> requestMessage, java.lang.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
protected org.springframework.core.AttributeAccessor getErrorMessageAttributes(@Nullable org.springframework.messaging.Message<?> message)Populate anAttributeAccessorto 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:AbstractEndpointSubclasses must implement this method with the start behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Specified by:
doStartin classAbstractEndpoint
-
doStop
protected void doStop()Description copied from class:AbstractEndpointSubclasses must implement this method with the stop behavior. This method will be invoked while holding theAbstractEndpoint.lifecycleLock.- Specified by:
doStopin classAbstractEndpoint
-
destroy
public void destroy()- Specified by:
destroyin interfaceorg.springframework.beans.factory.DisposableBean- Specified by:
destroyin interfaceIntegrationManagement- Overrides:
destroyin classAbstractEndpoint
-