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
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 Summary
Nested 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.IntegrationManagement
IntegrationManagement.ManagementOverrides -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final MessagingGatewaySupport.ConvertingMessagingTemplateFields 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_NAMEFields inherited from interface org.springframework.context.SmartLifecycle
DEFAULT_PHASE -
Constructor Summary
ConstructorsConstructorDescriptionConstruct 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 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.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, 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
-
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 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
-
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
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 anInboundMessageMapperfor creating request Messages from any object passed in asendorsendAndReceiveoperation.- 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
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- false 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
-
getErrorMessageStrategy
Get anErrorMessageStrategyto use to build an error message when a exception occurs. Default is theDefaultErrorMessageStrategy.- Returns:
- the errorMessageStrategy.
- Since:
- 6.0
-
getOverrides
Description copied from interface:IntegrationManagementReturn the overrides.- Specified by:
getOverridesin interfaceIntegrationManagement- Returns:
- the overrides.
-
setManagedType
- Specified by:
setManagedTypein interfaceIntegrationManagement
-
getManagedType
- Specified by:
getManagedTypein interfaceIntegrationManagement
-
setManagedName
- Specified by:
setManagedNamein interfaceIntegrationManagement
-
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. Ignored ifObservationRegistryis provided.- Specified by:
registerMetricsCaptorin interfaceIntegrationManagement- Parameters:
metricsCaptorToRegister- the captor.- See Also:
-
registerObservationRegistry
public 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 interfaceIntegrationManagement- Parameters:
observationRegistry- theObservationRegistryto expose observations from the component.- See Also:
-
isObserved
public boolean isObserved()Description copied from interface:IntegrationManagementTrue if this implementation is going to deal with a registry other than theObservationRegistry.NOOPinstance.- Specified by:
isObservedin interfaceIntegrationManagement- Returns:
- true if this implementation is going to deal with a registry other than the
ObservationRegistry.NOOPinstance.
-
setObservationConvention
public void setObservationConvention(@Nullable MessageRequestReplyReceiverObservationConvention observationConvention) -
setReceiverObservationConvention
public void setReceiverObservationConvention(MessageReceiverObservationConvention receiverObservationConvention) -
onInit
protected void onInit()Description copied from class:IntegrationObjectSupportSubclasses may implement this for initialization logic.- Overrides:
onInitin 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 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 interfaceDisposableBean- Specified by:
destroyin interfaceIntegrationManagement- Overrides:
destroyin classAbstractEndpoint
-