WebSockets & API Gateway

WebSockets & API Gateway

El día de hoy te traemos un resumen de esta nota y foto sacadas de medium.com escrita por Robert Zhu y titulada "WebSockets & API Gateway" la cual nos ha parecido muy interesante.

WebSockets & API Gateway

A quick, hands-on demo

2018 was the year I won many imaginary arguments about why a serverless WebSocket API Gateway will never work.,Before I atone, let me explain: serverless patterns work best when state is separated from execution logic, but I argued that the two are inseparable in real-time applications, pertaining to connection state.,So when the API Gateway team announced WebSocket support at re:Invent, I was eager to learn more.,Let’s refactor a simple real-time app into a serverless real-time app and deploy it to a WebSocket API Gateway.

Hello Hello

Those ten lines of code are actually doing several things:Accepting incoming websocket connectionsListening for incoming messagesGiving the message handler access to the source socket, on which to send data back to the client(Implicitly) handling client disconnectIf we pasted this code into a serverless function, it would need to run constantly to handle incoming connection requests, which violates the on-demand nature of the serverless functions.,However, if we isolate the inner echo logic as a serverless function, we would need to provide some way for it to communicate with the WebSockets held by the API Gateway.,Since the serverless function is stateless, the object reference we have in the function closure above will not suffice.,That’s just a one line (18) change:To test the newly refactored server and client:# Terminal Tab Anode serverWithActions# Terminal Tab B, note 'ws' protocol, not 'wss'node clientWithActions ws://localhost:8080Now we’re ready to create the WebSocket API in API Gateway.,Open AWS API Gateway, click “Create API”, select WebSocket and fill in the following settings:Double check that the Route Selection Expression is “$request.body.action”, as this expression tells API Gateway how to determine which action to invoke.,Save the Lambda and return to the API Gateway console tab.

Whatsapp Whatsapp LinkedIn Pinterest LinkedIn LinkedIn
Puntuación: 5 / Votos: 1

LiveConnect Chat Omnicanal

En nuestra plataforma de chat omnicanal que puedes conectar multiples líneas de WhatsApp, cuentas de Instagram, páginas de Facebook y páginas web, para que sean antendidas por uno o multiples agentes desde la web o desde nuestra aplicación móvil.

Conoce LiveConnect® en 1 minuto en este video:
Video de LiveConnect
Habilita el audio, con el te explicamos rápidamente los detalles.

WhatsApp Multiagente - WhatsApp Multiusuario - Chat Omnicanal - Chat para Empresas - Plataforma de Chat

Otras Notas Recientes

Stats Pixel