<dependency> <groupId>org.mule.connectors</groupId> <artifactId>mule-sockets-connector</artifactId> <version>x.x.x</version> <classifier>mule-plugin</classifier> </dependency>
Sockets Connector - Mule 4
RELEASE to the latest version. To specify a version, view
Anypoint Exchange and click Dependency Snippets.
The Socket Listener represents a socket endpoint that clients can connect to. By browsing to this endpoint, external clients establish a TCP Socket connection and trigger the flow each time they send a message.
You can configure a Socket Listener by referencing the configuration element from the listener’s
config-ref. This configuration sets up a Socket Listener to accept local incoming connections on port 8082:
<sockets:listener-config name="SocketsListenerConfig"> <sockets:tcp-listener-connection host="localhost" port="8082" /> </sockets:listener-config>
Sockets Connector supports these TCP protocols:
The socket reads until no more bytes are (immediately) available. On slow networks,
LengthProtocolmight be more reliable.
Reading is terminated by the stream being closed by the client.
This protocol is defined by sending or reading an integer (the packet length) and then the data to be transferred.
Custom Class Loading Length Protocol
This is a length protocol that uses a specific class loader to load objects from streams.
This is a test protocol that should not be used in production environments. This protocol precedes every message with a cookie.
This protocol allows the socket’s Send operation to return a message with the original
XML Message Protocol
XmlMessageProtocolis a protocol used to read streaming XML documents. The only requirement is that each document includes an XML declaration at the beginning of the document of the form "<?xml…". Make sure that the XML documents being streamed begin with an XML declaration when using this protocol.
Data is read until a new document is found or until there is no more currently available data. For slower networks,
XmlMessageEofProtocolmight be more reliable.
Also, because the default character encoding for the platform is used to decode the message bytes when looking for the XML declaration, some caution with message character encodings is warranted
XML Message EOF Protocol
XmlMessageProtocolto continue reading until either a new message or EOF is found.
You can define your own protocol by writing a class that extends
TcpProtocol, and that will be used as custom protocol.
These application level protocols are implemented on top of TCP. For these protocols to work properly, implement these in both client and server ends.
By default, a socket implements Safe Protocol, but you can specify a different protocol in the
config element. The following example, demonstrates how to configure the socket to use Direct Protocol:
<sockets:listener-config name="Sockets_Listener_config" doc:name="Sockets Listener config" > <sockets:tcp-listener-connection host="localhost" port="8082" > <sockets:protocol> <sockets:direct-protocol /> </sockets:protocol> </sockets:tcp-listener-connection> </sockets:listener-config>