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,- ComponentSourceAware,- 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
 
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.- Author:
- Mark Fisher, Gary Russell, Artem Bilan, Trung Pham, Christian Tzolov
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionprotected static classTheMessagingTemplateextension 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.IntegrationManagementIntegrationManagement.ManagementOverrides
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final MessagingGatewaySupport.ConvertingMessagingTemplateFields inherited from class org.springframework.integration.endpoint.AbstractEndpointlifecycleCondition, lifecycleLockFields inherited from class org.springframework.integration.context.IntegrationObjectSupportEXPRESSION_PARSER, loggerFields inherited from interface org.springframework.integration.support.management.IntegrationManagementMETER_PREFIX, RECEIVE_COUNTER_NAME, SEND_TIMER_NAMEFields inherited from interface org.springframework.context.SmartLifecycleDEFAULT_PHASE
- 
Constructor SummaryConstructorsConstructorDescriptionConstruct 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 SummaryModifier and TypeMethodDescriptionprotected final ErrorMessagebuildErrorMessage(Message<?> requestMessage, Throwable throwable) Build an error message for the message and throwable using the configuredErrorMessageStrategy.protected TimerFacadebuildSendTimer(boolean success, 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.Subclasses may implement this method to provide component type information.Return the error channel (if provided) to which error messages will be routed.protected AttributeAccessorgetErrorMessageAttributes(Message<?> message) Populate anAttributeAccessorto be used when building an error message with theerrorMessageStrategy.protected ErrorMessageStrategyGet anErrorMessageStrategyto 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.booleanReturn whether logging is enabled.booleanTrue if this implementation is going to deal with a registry other than theObservationRegistry.NOOPinstance.protected voidonInit()Subclasses may implement this for initialization logic.protected Objectreceive()protected Objectreceive(long timeout) protected Message<?>protected Message<?>receiveMessage(long timeout) voidregisterMetricsCaptor(MetricsCaptor metricsCaptorToRegister) Inject aMetricsCaptor.voidregisterObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Inject anObservationRegistry.protected voidprotected voidprotected ObjectsendAndReceive(Object object) protected Message<?>sendAndReceiveMessage(Object object) protected reactor.core.publisher.Mono<Message<?>>sendAndReceiveMessageReactive(Object object) protected TimerFacadevoidsetErrorChannel(MessageChannel errorChannel) Set the error channel.voidsetErrorChannelName(String errorChannelName) Set the error channel name.final 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(String managedName) voidsetManagedType(String managedType) voidsetObservationConvention(MessageRequestReplyReceiverObservationConvention observationConvention) voidsetReceiverObservationConvention(MessageReceiverObservationConvention receiverObservationConvention) voidsetReplyChannel(MessageChannel replyChannel) Set the reply channel.voidsetReplyChannelName(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(MessageChannel requestChannel) Set the request channel.voidsetRequestChannelName(String requestChannelName) Set the request channel name.voidsetRequestMapper(InboundMessageMapper<?> requestMapper) Provide anInboundMessageMapperfor creating request Messages from any object passed in asendorsendAndReceiveoperation.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.AbstractEndpointdoStop, getPhase, getRole, isActive, isAutoStartup, isRunning, setAutoStartup, setPhase, setRole, start, stop, stopMethods inherited from class org.springframework.integration.context.IntegrationObjectSupportafterPropertiesSet, extractTypeIfPossible, generateId, getApplicationContext, getApplicationContextId, getBeanDescription, getBeanFactory, getBeanName, getChannelResolver, getComponentDescription, getComponentName, getComponentSource, getConversionService, getExpression, getIntegrationProperties, getMessageBuilderFactory, getTaskScheduler, isInitialized, setApplicationContext, setBeanFactory, setBeanName, setChannelResolver, setComponentDescription, setComponentName, setComponentSource, setConversionService, setMessageBuilderFactory, setPrimaryExpression, setTaskScheduler, toStringMethods inherited from class java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.springframework.integration.support.management.IntegrationManagementgetThisAsMethods inherited from interface org.springframework.integration.support.context.NamedComponentgetBeanName, getComponentName
- 
Field Details- 
messagingTemplate
 
- 
- 
Constructor Details- 
MessagingGatewaySupportpublic MessagingGatewaySupport()Construct an instance that will return null if no reply is received.
- 
MessagingGatewaySupportpublic 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:
 
 
- 
- 
Method Details- 
setErrorOnTimeoutpublic 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
 
- 
setRequestChannelSet the request channel.- Parameters:
- requestChannel- the channel to which request messages will be sent
 
- 
setRequestChannelNameSet the request channel name.- Parameters:
- requestChannelName- the channel bean name to which request messages will be sent
- Since:
- 4.1
 
- 
setReplyChannelSet 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
 
- 
setReplyChannelNameSet 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
 
- 
setErrorChannelSet 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.
 
- 
setErrorChannelNameSet 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
 
- 
setRequestTimeoutpublic 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
 
- 
setReplyTimeoutpublic 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
 
- 
setRequestMapperProvide anInboundMessageMapperfor creating request Messages from any object passed in asendorsendAndReceiveoperation.- Parameters:
- requestMapper- The request mapper.
 
- 
setReplyMapperProvide anOutboundMessageMapperfor mapping to objects from any reply Messages received in receive or sendAndReceive operations.- Parameters:
- replyMapper- The reply mapper.
 
- 
setShouldTrackpublic 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 interface- TrackableComponent
 
- 
getComponentTypeDescription copied from class:IntegrationObjectSupportSubclasses may implement this method to provide component type information.- Specified by:
- getComponentTypein interface- NamedComponent
- Overrides:
- getComponentTypein class- IntegrationObjectSupport
 
- 
setLoggingEnabledpublic void setLoggingEnabled(boolean enabled) Description copied from interface:IntegrationManagementEnable logging or not.- Specified by:
- setLoggingEnabledin interface- IntegrationManagement
- Parameters:
- enabled- false to disable.
 
- 
isLoggingEnabledpublic boolean isLoggingEnabled()Description copied from interface:IntegrationManagementReturn whether logging is enabled.- Specified by:
- isLoggingEnabledin interface- IntegrationManagement
- Returns:
- true if enabled.
 
- 
setErrorMessageStrategySet anErrorMessageStrategyto use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy.- Parameters:
- errorMessageStrategy- the- ErrorMessageStrategy.
- Since:
- 4.3.10
 
- 
getErrorMessageStrategyGet anErrorMessageStrategyto use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy.- Returns:
- the errorMessageStrategy.
- Since:
- 6.0
 
- 
getOverridesDescription copied from interface:IntegrationManagementReturn the overrides.- Specified by:
- getOverridesin interface- IntegrationManagement
- Returns:
- the overrides.
 
- 
setManagedType- Specified by:
- setManagedTypein interface- IntegrationManagement
 
- 
getManagedType- Specified by:
- getManagedTypein interface- IntegrationManagement
 
- 
setManagedName- Specified by:
- setManagedNamein interface- IntegrationManagement
 
- 
getManagedName- Specified by:
- getManagedNamein interface- IntegrationManagement
 
- 
getIntegrationPatternTypeDescription copied from interface:IntegrationPatternReturn a pattern type this component implements.- Specified by:
- getIntegrationPatternTypein interface- IntegrationPattern
- Returns:
- the IntegrationPatternTypethis component implements.
 
- 
registerMetricsCaptorDescription copied from interface:IntegrationManagementInject aMetricsCaptor. Ignored ifObservationRegistryis provided.- Specified by:
- registerMetricsCaptorin interface- IntegrationManagement
- Parameters:
- metricsCaptorToRegister- the captor.
- See Also:
 
- 
registerObservationRegistrypublic void registerObservationRegistry(io.micrometer.observation.ObservationRegistry observationRegistry) Description copied from interface:IntegrationManagementInject anObservationRegistry. If provided, theMetricsCaptoris ignored. The meters capturing has to be configured as anObservationHandleron the providedObservationRegistry.- Specified by:
- registerObservationRegistryin interface- IntegrationManagement
- Parameters:
- observationRegistry- the- ObservationRegistryto expose observations from the component.
- See Also:
 
- 
isObservedpublic boolean isObserved()Description copied from interface:IntegrationManagementTrue if this implementation is going to deal with a registry other than theObservationRegistry.NOOPinstance.- Specified by:
- isObservedin interface- IntegrationManagement
- Returns:
- true if this implementation is going to deal with a registry other than the ObservationRegistry.NOOPinstance.
 
- 
setObservationConventionpublic void setObservationConvention(@Nullable MessageRequestReplyReceiverObservationConvention observationConvention) 
- 
setReceiverObservationConventionpublic void setReceiverObservationConvention(MessageReceiverObservationConvention receiverObservationConvention) 
- 
onInitprotected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
- onInitin class- AbstractEndpoint
 
- 
getRequestChannelReturn this gateway's request channel.- Returns:
- the channel.
- Since:
- 4.2
 
- 
getReplyChannelReturn this gateway's reply channel if any.- Returns:
- the reply channel instance
- Since:
- 5.1
 
- 
getErrorChannelReturn 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
- 
buildErrorMessageprotected 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
 
- 
getErrorMessageAttributesPopulate anAttributeAccessorto be used when building an error message with theerrorMessageStrategy.- Parameters:
- message- the message.
- Returns:
- the attributes.
- Since:
- 4.3.10
 
- 
registerReplyMessageCorrelatorIfNecessaryprotected void registerReplyMessageCorrelatorIfNecessary()
- 
doStartprotected 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 class- AbstractEndpoint
 
- 
doStopprotected 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 class- AbstractEndpoint
 
- 
destroypublic void destroy()- Specified by:
- destroyin interface- DisposableBean
- Specified by:
- destroyin interface- IntegrationManagement
- Overrides:
- destroyin class- AbstractEndpoint
 
 
-