Class UnicastSendingMessageHandler
java.lang.Object
org.springframework.integration.context.IntegrationObjectSupport
org.springframework.integration.handler.MessageHandlerSupport
org.springframework.integration.handler.AbstractMessageHandler
org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
org.springframework.integration.ip.udp.UnicastSendingMessageHandler
- All Implemented Interfaces:
Runnable
,org.reactivestreams.Subscriber<Message<?>>
,Aware
,BeanFactoryAware
,BeanNameAware
,DisposableBean
,InitializingBean
,ApplicationContextAware
,Lifecycle
,Ordered
,ExpressionCapable
,Orderable
,IntegrationPattern
,CommonSocketOptions
,NamedComponent
,IntegrationManagement
,ManageableLifecycle
,TrackableComponent
,MessageHandler
,reactor.core.CoreSubscriber<Message<?>>
- Direct Known Subclasses:
MulticastSendingMessageHandler
public class UnicastSendingMessageHandler
extends AbstractInternetProtocolSendingMessageHandler
implements Runnable
A
MessageHandler
implementation that maps a Message into
a UDP datagram packet and sends that to the specified host and port.
Messages can be basic, with no support for reliability, can be prefixed by a length so the receiving end can detect truncation, and can require a UDP acknowledgment to confirm delivery.
- Since:
- 2.0
- Author:
- Gary Russell, Marcin Pilaczynski, Artem Bilan
-
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.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.core.Ordered
HIGHEST_PRECEDENCE, LOWEST_PRECEDENCE
-
Constructor Summary
ConstructorDescriptionUnicastSendingMessageHandler
(String destinationExpression) Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.UnicastSendingMessageHandler
(String host, int port) Basic constructor; no reliability; no acknowledgment.UnicastSendingMessageHandler
(String host, int port, boolean lengthCheck) Can used to add a length to each packet which can be checked at the destination.UnicastSendingMessageHandler
(String host, int port, boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) Add a length and/or acknowledgment request to packets.UnicastSendingMessageHandler
(String host, int port, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) Add an acknowledgment request to packets.UnicastSendingMessageHandler
(Expression destinationExpression) Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
convertAndSend
(Message<?> message) void
doStart()
protected void
doStop()
int
Subclasses may implement this method to provide component type information.protected DatagramSocket
int
protected DatagramSocket
void
handleMessageInternal
(Message<?> message) boolean
protected void
onInit()
Subclasses may implement this for initialization logic.void
If exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.void
run()
Process acknowledgments, if requested.void
setAckCounter
(int ackCounter) void
setLengthCheck
(boolean lengthCheck) void
setLocalAddress
(String localAddress) On a multi-homed system, specifies the ip address of the network interface used to communicate.protected final void
setReliabilityAttributes
(boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) protected void
setSocket
(DatagramSocket socket) protected void
setSocketAttributes
(DatagramSocket socket) void
setSocketCustomizer
(SocketCustomizer socketCustomizer) Set a customizer to further configure the socket after creation.void
setSocketExpression
(Expression socketExpression) void
setSocketExpressionString
(String socketExpression) void
setSoReceiveBufferSize
(int size) void
setTaskExecutor
(Executor taskExecutor) void
protected void
Methods inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
getDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, isRunning, setSoSendBufferSize, setSoTimeout, start, stop
Methods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribe, setObservationConvention
Methods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getObservationRegistry, getOrder, getOverrides, isLoggingEnabled, isObserved, registerMetricsCaptor, registerObservationRegistry, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrack
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 reactor.core.CoreSubscriber
currentContext
Methods inherited from interface org.springframework.integration.support.management.IntegrationManagement
getThisAs
Methods inherited from interface org.springframework.integration.support.context.NamedComponent
getBeanName, getComponentName
-
Constructor Details
-
UnicastSendingMessageHandler
Basic constructor; no reliability; no acknowledgment.- Parameters:
host
- Destination host.port
- Destination port.
-
UnicastSendingMessageHandler
Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.- Parameters:
destinationExpression
- the SpEL expression to evaluate the target destination at runtime. Must evaluate toString
,URI
orSocketAddress
.- Since:
- 4.3
-
UnicastSendingMessageHandler
Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.- Parameters:
destinationExpression
- the SpEL expression to evaluate the target destination at runtime. Must evaluate toString
,URI
orSocketAddress
.- Since:
- 4.3
-
UnicastSendingMessageHandler
Can used to add a length to each packet which can be checked at the destination.- Parameters:
host
- Destination Host.port
- Destination Port.lengthCheck
- If true, packets will contain a length.
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(String host, int port, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) Add an acknowledgment request to packets.- Parameters:
host
- Destination Host.port
- Destination Port.acknowledge
- If true, packets will request acknowledgment.ackHost
- The host to which acks should be sent. Required if ack true.ackPort
- The port to which acks should be sent.ackTimeout
- How long we will wait (milliseconds) for the ack.
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(String host, int port, boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) Add a length and/or acknowledgment request to packets.- Parameters:
host
- Destination Host.port
- Destination Port.lengthCheck
- If true, packets will contain a length.acknowledge
- If true, packets will request acknowledgment.ackHost
- The host to which acks should be sent. Required if ack true.ackPort
- The port to which acks should be sent.ackTimeout
- How long we will wait (milliseconds) for the ack.
-
-
Method Details
-
setLengthCheck
public void setLengthCheck(boolean lengthCheck) - Parameters:
lengthCheck
- if true, a four byte binary length header is added to the packet, allowing the receiver to check for data truncation.- Since:
- 5.0
-
setSocketCustomizer
Set a customizer to further configure the socket after creation.- Parameters:
socketCustomizer
- the customizer.- Since:
- 5.3.3
-
setReliabilityAttributes
protected final void setReliabilityAttributes(boolean lengthCheck, boolean acknowledge, String ackHost, int ackPort, int ackTimeout) -
doStart
public void doStart()- Specified by:
doStart
in classAbstractInternetProtocolSendingMessageHandler
-
doStop
protected void doStop()- Specified by:
doStop
in classAbstractInternetProtocolSendingMessageHandler
-
handleMessageInternal
- Specified by:
handleMessageInternal
in classAbstractMessageHandler
-
startAckThread
public void startAckThread() -
convertAndSend
- Throws:
IOException
URISyntaxException
-
setSocket
-
getTheSocket
-
getSocket
- Throws:
IOException
-
updateAckAddress
protected void updateAckAddress() -
setSoReceiveBufferSize
public void setSoReceiveBufferSize(int size) - Specified by:
setSoReceiveBufferSize
in interfaceCommonSocketOptions
- Overrides:
setSoReceiveBufferSize
in classAbstractInternetProtocolSendingMessageHandler
- Parameters:
size
- The receive buffer size.- See Also:
-
setLocalAddress
Description copied from interface:CommonSocketOptions
On a multi-homed system, specifies the ip address of the network interface used to communicate. For inbound adapters and gateways, specifies the interface used to listed for incoming connections. If omitted, the endpoint will listen on all available adapters. For the UDP multicast outbound adapter specifies the interface to which multicast packets will be sent. For UDP unicast and multicast adapters, specifies which interface to which the acknowledgment socket will be bound. Does not apply to TCP outbound adapters and gateways.- Specified by:
setLocalAddress
in interfaceCommonSocketOptions
- Parameters:
localAddress
- The local address.
-
setTaskExecutor
-
setAckCounter
public void setAckCounter(int ackCounter) - Parameters:
ackCounter
- the ackCounter to set
-
setSocketExpression
- Parameters:
socketExpression
- the socket expression to determine the target socket at runtime.- Since:
- 4.3
-
setSocketExpressionString
- Parameters:
socketExpression
- the socket SpEL expression to determine the target socket at runtime.- Since:
- 4.3
-
getComponentType
Description copied from class:IntegrationObjectSupport
Subclasses may implement this method to provide component type information.- Specified by:
getComponentType
in interfaceNamedComponent
- Overrides:
getComponentType
in classMessageHandlerSupport
-
isAcknowledge
public boolean isAcknowledge()- Returns:
- the acknowledge
-
getAckPort
public int getAckPort()- Returns:
- the ackPort
-
getSoReceiveBufferSize
public int getSoReceiveBufferSize()- Returns:
- the soReceiveBufferSize
-
onInit
protected void onInit()Description copied from class:IntegrationObjectSupport
Subclasses may implement this for initialization logic.- Overrides:
onInit
in classIntegrationObjectSupport
-
setSocketAttributes
- Throws:
SocketException
-
run
public void run()Process acknowledgments, if requested. -
restartAckThread
public void restartAckThread()If exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.
-