Using WebSockets connector in Mule 4 & stream HTTP Request data

In our previous articles, we have seen What are WebSockets? and how to stream the data from an existing WebSocket using WebSockets connector in Mule 4. This article covers the steps to flow when you want to stream the data from an HTTP Request which is pattern 2 from the below



Here are the patterns which are highly used
  1. To stream all the data from WebSockets

  2. To stream all the data to the clients from an HTTP request

  3. To stream only data which is requested by the client

This is the overall flow after creating the API


Steps to stream the data from HTTP Request using WebSockets connector in Mule 4

Step 1: Configuring On New Inbound Message (WS Listener)

Step 2: Scheduler configuration as below



Step 3: Request configuration as below
  • Request host: api.coincap.io

  • Request port: 80

  • Request Path: /v2/assets/bitcoin

Step 4: Configuring Broadcast component in Mule 4 WebSocket connector

Testing WebSockets API using Postwoman

  1. Open www.postwoman.io/realtime

  2. Provide the URL (ws://localhost:8082/ws/wsdata). Click on connect

  3. You can see that data is streaming to your browser as below

Find the latest MuleSoft(Mule 4) Articles on DataWeave, Anypoint Studio, Anypoint Platform, and Runtime Manager. Our articles also include frequently asked Mule4 Interview questions and answers. Please comment below for any queries or free article submissions.

Post a Comment

0 Comments