Intercepting Messages on TCP/IP in Mule

July 25 2017

0 comments 0
mule intercepting message

In this article, we will see how Mule can intercept messages on the / socket for real-time communication. You will first receive messages on the TCP/ socket and then transform the messages from byte to object, then from object to , and then, finally, from to JSON––all using out-of-the-box transformers.

The TCP transport allows users to send or receive messages over TCP connections. TCP is a layer above the IP. It is used to implement a number of other reliable protocols, such as HTTP and FTP. If you want to use the TCP transport directly, then you need a specific protocol to read the message payload that is not supported by one of these higher level protocols. This is often the case when communicating with legacy or native system applications that don’t support web services. TCP transport is also used in business scenarios where transactions are in real-time.


In this blog post, we will first send the message from the Packet Sender application, and then Mule will receive the message on the TCP/IP socket. We will then transform the message from byte to object, then from object to XML, and then from XML to JSON––all using Anypoint Studio transformers.

Image title

1. First, configure TCP Transport as follows:

a. The exchange pattern will be one-way, because we are not sending any acknowledgment back. Then, we need to input the host and port information and define the connector configuration:

Image title






b. Set the MIME type to text/plain and set the response timeout to default. 
Image title





c. Check the “Do not use a Reconnection strategy” radiobox.
Image title






d. Now, choose the appropriate protocol according to your requirement and check the “Keep Alive” box as shown below.

Image title









2. Set the MIME type to “text/plain” in the Byte Array to Object transformer. 
Image title






3. The MIME type will be “text/xml” in the Object to XML transformer.
Image title





4. Set the MIME type to “text/JSON” in the XML to JSON transformer.
Image title






5. Configure all Logger components Message value to be  #[payload]  in order to log received payloads in the console.

6. Send the packet from the Packet Sender application on the TCP socket according to the configuration below. Set the packet payload to “MULE ESB TEST PACKET.”

Image title





7. Run the application in debug mode so that you can stop the application and easily see the in-flight conversion of data, while the data moves from one component to another. 

8. After passing the Byte Array to the Object component, you will receive the payload as a text/plain payload. 

Image title






9. After passing the Object to XML component, the payload will convert to XML format. Image title







10. After passing the XML to JSON component, the payload will convert from XML to JSON format. 

Image title




11. Finally, you can see all the data format changes in the console. Image title



Please refer to this page for more details and information.

This article was originally published on Dzone


We'd love to hear your opinion on this post