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:
java.lang.Runnable,org.reactivestreams.Subscriber<org.springframework.messaging.Message<?>>,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.core.Ordered,org.springframework.integration.context.ExpressionCapable,org.springframework.integration.context.Orderable,org.springframework.integration.IntegrationPattern,CommonSocketOptions,org.springframework.integration.support.context.NamedComponent,org.springframework.integration.support.management.IntegrationManagement,org.springframework.integration.support.management.ManageableLifecycle,org.springframework.integration.support.management.TrackableComponent,org.springframework.messaging.MessageHandler,reactor.core.CoreSubscriber<org.springframework.messaging.Message<?>>
- Direct Known Subclasses:
MulticastSendingMessageHandler
public class UnicastSendingMessageHandler extends AbstractInternetProtocolSendingMessageHandler implements java.lang.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
-
Nested Class Summary
-
Field Summary
Fields inherited from class org.springframework.integration.context.IntegrationObjectSupport
EXPRESSION_PARSER, logger -
Constructor Summary
Constructors Constructor Description UnicastSendingMessageHandler(java.lang.String destinationExpression)Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage.UnicastSendingMessageHandler(java.lang.String host, int port)Basic constructor; no reliability; no acknowledgment.UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck)Can used to add a length to each packet which can be checked at the destination.UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)Add a length and/or acknowledgment request to packets.UnicastSendingMessageHandler(java.lang.String host, int port, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)Add an acknowledgment request to packets.UnicastSendingMessageHandler(org.springframework.expression.Expression destinationExpression)Construct UnicastSendingMessageHandler based on the destination SpEL expression to determine the target destination at runtime against requestMessage. -
Method Summary
Modifier and Type Method Description protected voidconvertAndSend(org.springframework.messaging.Message<?> message)voiddoStart()protected voiddoStop()intgetAckPort()java.lang.StringgetComponentType()protected java.net.DatagramSocketgetSocket()intgetSoReceiveBufferSize()protected java.net.DatagramSocketgetTheSocket()voidhandleMessageInternal(org.springframework.messaging.Message<?> message)booleanisAcknowledge()protected voidonInit()voidrestartAckThread()If exposed as an MBean, can be used to restart the ack thread if a fatal (bind) error occurred, without bouncing the JVM.voidrun()Process acknowledgments, if requested.voidsetAckCounter(int ackCounter)voidsetLengthCheck(boolean lengthCheck)voidsetLocalAddress(java.lang.String localAddress)On a multi-homed system, specifies the ip address of the network interface used to communicate.protected voidsetReliabilityAttributes(boolean lengthCheck, boolean acknowledge, java.lang.String ackHost, int ackPort, int ackTimeout)protected voidsetSocket(java.net.DatagramSocket socket)protected voidsetSocketAttributes(java.net.DatagramSocket socket)voidsetSocketCustomizer(SocketCustomizer socketCustomizer)Set a customizer to further configure the socket after creation.voidsetSocketExpression(org.springframework.expression.Expression socketExpression)voidsetSocketExpressionString(java.lang.String socketExpression)voidsetSoReceiveBufferSize(int size)voidsetTaskExecutor(java.util.concurrent.Executor taskExecutor)voidstartAckThread()protected voidupdateAckAddress()Methods inherited from class org.springframework.integration.ip.AbstractInternetProtocolSendingMessageHandler
getDestinationAddress, getHost, getPort, getSoSendBufferSize, getSoTimeout, isRunning, setSoSendBufferSize, setSoTimeout, start, stopMethods inherited from class org.springframework.integration.handler.AbstractMessageHandler
handleMessage, onComplete, onError, onNext, onSubscribeMethods inherited from class org.springframework.integration.handler.MessageHandlerSupport
buildSendTimer, destroy, getIntegrationPatternType, getManagedName, getManagedType, getMetricsCaptor, getOrder, getOverrides, isLoggingEnabled, registerMetricsCaptor, sendTimer, setLoggingEnabled, setManagedName, setManagedType, setOrder, setShouldTrack, shouldTrackMethods 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, wait
-
Constructor Details
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(java.lang.String host, int port)Basic constructor; no reliability; no acknowledgment.- Parameters:
host- Destination host.port- Destination port.
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(java.lang.String destinationExpression)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,URIorSocketAddress.- Since:
- 4.3
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(org.springframework.expression.Expression destinationExpression)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,URIorSocketAddress.- Since:
- 4.3
-
UnicastSendingMessageHandler
public UnicastSendingMessageHandler(java.lang.String host, int port, boolean lengthCheck)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(java.lang.String host, int port, boolean acknowledge, java.lang.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(java.lang.String host, int port, boolean lengthCheck, boolean acknowledge, java.lang.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, java.lang.String ackHost, int ackPort, int ackTimeout) -
doStart
public void doStart()- Specified by:
doStartin classAbstractInternetProtocolSendingMessageHandler
-
doStop
protected void doStop()- Specified by:
doStopin classAbstractInternetProtocolSendingMessageHandler
-
handleMessageInternal
public void handleMessageInternal(org.springframework.messaging.Message<?> message)- Specified by:
handleMessageInternalin classorg.springframework.integration.handler.AbstractMessageHandler
-
startAckThread
public void startAckThread() -
convertAndSend
protected void convertAndSend(org.springframework.messaging.Message<?> message) throws java.io.IOException, java.net.URISyntaxException- Throws:
java.io.IOExceptionjava.net.URISyntaxException
-
setSocket
protected void setSocket(java.net.DatagramSocket socket) -
getTheSocket
@Nullable protected java.net.DatagramSocket getTheSocket() -
getSocket
protected java.net.DatagramSocket getSocket() throws java.io.IOException- Throws:
java.io.IOException
-
updateAckAddress
protected void updateAckAddress() -
setSoReceiveBufferSize
public void setSoReceiveBufferSize(int size)- Specified by:
setSoReceiveBufferSizein interfaceCommonSocketOptions- Overrides:
setSoReceiveBufferSizein classAbstractInternetProtocolSendingMessageHandler- Parameters:
size- The receive buffer size.- See Also:
Socket.setReceiveBufferSize(int),DatagramSocket.setReceiveBufferSize(int)
-
setLocalAddress
public void setLocalAddress(java.lang.String localAddress)Description copied from interface:CommonSocketOptionsOn 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:
setLocalAddressin interfaceCommonSocketOptions- Parameters:
localAddress- The local address.
-
setTaskExecutor
public void setTaskExecutor(java.util.concurrent.Executor taskExecutor) -
setAckCounter
public void setAckCounter(int ackCounter)- Parameters:
ackCounter- the ackCounter to set
-
setSocketExpression
public void setSocketExpression(org.springframework.expression.Expression socketExpression)- Parameters:
socketExpression- the socket expression to determine the target socket at runtime.- Since:
- 4.3
-
setSocketExpressionString
public void setSocketExpressionString(java.lang.String socketExpression)- Parameters:
socketExpression- the socket SpEL expression to determine the target socket at runtime.- Since:
- 4.3
-
getComponentType
public java.lang.String getComponentType()- Specified by:
getComponentTypein interfaceorg.springframework.integration.support.context.NamedComponent- Overrides:
getComponentTypein classorg.springframework.integration.handler.MessageHandlerSupport
-
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()- Overrides:
onInitin classorg.springframework.integration.context.IntegrationObjectSupport
-
setSocketAttributes
protected void setSocketAttributes(java.net.DatagramSocket socket) throws java.net.SocketException- Throws:
java.net.SocketException
-
run
public void run()Process acknowledgments, if requested.- Specified by:
runin interfacejava.lang.Runnable
-
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.
-