Class DatagramPacketMessageMapper
java.lang.Object
org.springframework.integration.ip.udp.DatagramPacketMessageMapper
- All Implemented Interfaces:
Aware
,BeanFactoryAware
,InboundMessageMapper<DatagramPacket>
,OutboundMessageMapper<DatagramPacket>
public class DatagramPacketMessageMapper
extends Object
implements InboundMessageMapper<DatagramPacket>, OutboundMessageMapper<DatagramPacket>, BeanFactoryAware
Message Mapper for converting to and from UDP DatagramPackets. When
converting to a Message, the payload will be a byte array containing the
data from the received packet. When converting from a Message, the payload
may be either a byte array or a String. The default charset for converting
a String to a byte array is UTF-8, but that may be changed by invoking the
setCharset(String)
method.
By default, the UDP messages will be unreliable (truncation may occur on the receiving end; packets may be lost).
Reliability can be enhanced by one or both of the following techniques:
- including a binary message length at the beginning of the packet
- requesting a receipt acknowledgment
- Since:
- 2.0
- Author:
- Mark Fisher, Gary Russell, Dave Syer, Artem Bilan
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionfromMessage
(Message<?> message) Raw byte[] from message, possibly with a length field up front.protected MessageBuilderFactory
void
setAckAddress
(String ackAddress) void
setAcknowledge
(boolean acknowledge) void
setBeanFactory
(BeanFactory beanFactory) void
setCharset
(String charset) void
setLengthCheck
(boolean lengthCheck) void
setLookupHost
(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address.Message<byte[]>
toMessage
(DatagramPacket object) Convert a provided object to theMessage
.Message<byte[]>
toMessage
(DatagramPacket packet, Map<String, Object> headers) Convert a provided object to theMessage
and supply with headers if necessary and provided.
-
Constructor Details
-
DatagramPacketMessageMapper
public DatagramPacketMessageMapper()
-
-
Method Details
-
setCharset
-
setAcknowledge
public void setAcknowledge(boolean acknowledge) -
setAckAddress
-
setLengthCheck
public void setLengthCheck(boolean lengthCheck) -
setLookupHost
public void setLookupHost(boolean lookupHost) If true, DNS reverse lookup is done on the remote ip address. Default false: not all environments (e.g. Docker containers) perform reliable DNS resolution.- Parameters:
lookupHost
- the lookupHost to set
-
setBeanFactory
- Specified by:
setBeanFactory
in interfaceBeanFactoryAware
- Throws:
BeansException
-
getMessageBuilderFactory
-
fromMessage
Raw byte[] from message, possibly with a length field up front.- Specified by:
fromMessage
in interfaceOutboundMessageMapper<DatagramPacket>
-
toMessage
Description copied from interface:InboundMessageMapper
Convert a provided object to theMessage
.- Specified by:
toMessage
in interfaceInboundMessageMapper<DatagramPacket>
- Parameters:
object
- the object for message payload or some other conversion logic- Returns:
- the message as a result of mapping
-
toMessage
@Nullable public Message<byte[]> toMessage(DatagramPacket packet, @Nullable Map<String, Object> headers) Description copied from interface:InboundMessageMapper
Convert a provided object to theMessage
and supply with headers if necessary and provided.- Specified by:
toMessage
in interfaceInboundMessageMapper<DatagramPacket>
- Parameters:
packet
- the object for message payload or some other conversion logicheaders
- additional headers for building message. Can be null- Returns:
- the message as a result of mapping
-