0% found this document useful (0 votes)
42 views

POC Socket Io

This document describes a proof of concept for an alternative to web sockets using NodeJs, socket.io, and axios libraries. It includes three APIs - a producer that makes frontend requests, a consumer that processes requests asynchronously and notifies the socket server, and a server that uses socket.io for communication between APIs. The producer sends frontend requests to the consumer, which simulates processing and returns a response via the server to the producer and frontend. This provides asynchronous processing and response via sockets as an alternative to web sockets.

Uploaded by

Samuel Prates
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

POC Socket Io

This document describes a proof of concept for an alternative to web sockets using NodeJs, socket.io, and axios libraries. It includes three APIs - a producer that makes frontend requests, a consumer that processes requests asynchronously and notifies the socket server, and a server that uses socket.io for communication between APIs. The producer sends frontend requests to the consumer, which simulates processing and returns a response via the server to the producer and frontend. This provides asynchronous processing and response via sockets as an alternative to web sockets.

Uploaded by

Samuel Prates
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

First POC for an alternative method to web socket with front-end

Work item: Chargeback Team Storys Backlog - Boards (azure.com)

Problem:

“As we still do not have the confirmation that we will use the web socket to communicate with the
frontend, we need to think about an alternative that meets the need to return the updated data to
the frontend.

Raising possible alternatives.

One idea would be to hold the request that the frontend makes and only return as soon as all the
queues have been processed by the backend and updated in the database.”

Technology used for this POC:

 NodeJs;
 Lib socket.io - https://www.npmjs.com/package/socket.io;
 Lib axios - https://www.npmjs.com/package/axios;

Method:

Three APIs were created. The first (Producer) is the service that will make the request for processing
a front-end call. The second (Consumer) is the service that will respond to the first API instantly and
later process the request asynchronously notifying the socket server. Finally, the server (Server) uses
the socket.io library to create stable communication between the APIs.
Example code
Server:

The server receives a communication in a context (‘message’) and then emit this message to all
connections throw an id context (variable ‘id’ in this case) with the exact same message received.

Consumer:
The consumer receives a request from the producer and then simulate a processing delay changing
the payload from anything to ‘processed’.

Producer:
The Producer receive a request from front-end and then send it to consumer to processes and so
wait receive a response from server and output to front-end.

Link to files: https://santandernet.sharepoint.com/sites/SMPS-BR-Team/Shared%20Documents/


Chargeback/New%20Architecture/POCs/poc-socket-io.rar

Conclusion:

 You can expect a request to be processed asynchronously and wait for a response via
socket.io.
 The id created to wait a request should be unique, because every API connected to server
will listen that message if connected to same id context.
 You should remove the listener after receive the message to keep a pattern and avoid stay
listeners opens. (ex. “socket.off(context)”).

You might also like