Deploy a free, open-source Pusher alternative ?

I’ve been many times in a situation where I needed Pusher to broadcast messages from Laravel events to the frontend applications. This can be a bummer when you don’t have enough money to pay for a Pusher plan once you reach a specific threshold or you …


This content originally appeared on DEV Community and was authored by Alex Renoki ?? ?️‍?

I’ve been many times in a situation where I needed Pusher to broadcast messages from Laravel events to the frontend applications. This can be a bummer when you don’t have enough money to pay for a Pusher plan once you reach a specific threshold or you want to manage the Pusher instance yourself and scale it yourself, as an alternative.

pWS is a free, open-source alternative for the Pusher service. ?

The server is built on top of uWebSockets.js — a C application ported to Node.js, that claims to be running 8.5x that of Fastify and at least 10x that of Socket.IO. (source)

The difference between pWS and Socket.IO is in terms of speed. pWS is supported by Pusher-maintained clients, bringing portability and plug-and-play functionality with already frontend apps that already use Pusher clients.
The server is entirely compatible with the Pusher Protocol v7 and tries to keep up with the HTTP REST API reference as fast as possible.

Contrary to Pusher, you do not need Pusher credentials or a Pusher plan to make it work. The application is a standalone, plug-and-play alternative to Pusher.

? Installation

pWS is available as CLI or as a Docker container, bringing full flexibility to run in the environment you wish.

npm install -g @soketi/pws
yarn global add @soketi/pws

To start the sample server, run:

pws-server start

When running with Docker, all you have to do is to find the right image you want to install:

docker run -p 6001:6001 soketi/pws:1.0.0-14-alpine

After this, a Pusher server is available at port 6001:
Pusher clients are fully compatible with the WebSocket protocol implemented in this project. You just have to point the client to the server address:

const PusherJS = require('pusher-js');

let client = new PusherJS('app-key', {
    wsHost: '127.0.0.1',
    wsPort: 6001,
    forceTLS: false,
    encrypted: true,
    disableStats: true,
    enabledTransports: ['ws', 'wss'],
});

client.subscribe('chat-room').bind('message', (message) => {
    alert(`${message.sender} says: ${message.content}`);
});

?‍? App Management

Apps can be defined at the configuration level or can be pulled from a third-party API, such as MySQL or PostgreSQL for better management of who can access the WebSockets server and who can publish the events.

pWS has support for SQL-based databases and even DynamoDB and can be easily configured via environment variables.

↔ Horizontal Scaling

pWS is optimized to work in multi-node or multi-process environments, like Kubernetes or PM2, where horizontal scalability is one of the main core features that can be built upon. The main concern when scaling horizontally is how can I make the nodes communicate between them?
To be able to scale it horizontally and efficiently enable node-to-node or process-to-process communication, pWS leverages a Redis connection.
You can configure pWS to run with Redis as a primary adapter for the local-persistent data with an environment variable:

ADAPTER_DRIVER=redis pws-server start

? Extensive documentation

pWS has many other supported features, like rate limiting, graceful shutdowns for servers that still have active connections, Prometheus support for scaling, and even compatibility for Pusher Webhooks to send frontend events to your backend.

Read the extensive documentation on https://pws.soketi.app

? Contributing

Please open issues or feature requests within the Issues board on Github or if you think there are some improvements needed, submit a Pull Request and we will discuss it there.

? Supporting our work

If you enjoyed this article or you are using one or more Renoki Co. open-source packages in your production apps, in presentation demos, hobby projects, school projects or so, spread some kind words about our work or sponsor our work via Patreon for some exclusive articles full of Laravel tips and best practices. ?


This content originally appeared on DEV Community and was authored by Alex Renoki ?? ?️‍?


Print Share Comment Cite Upload Translate Updates
APA

Alex Renoki ?? ?️‍? | Sciencx (2021-08-10T07:19:52+00:00) Deploy a free, open-source Pusher alternative ?. Retrieved from https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/

MLA
" » Deploy a free, open-source Pusher alternative ?." Alex Renoki ?? ?️‍? | Sciencx - Tuesday August 10, 2021, https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/
HARVARD
Alex Renoki ?? ?️‍? | Sciencx Tuesday August 10, 2021 » Deploy a free, open-source Pusher alternative ?., viewed ,<https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/>
VANCOUVER
Alex Renoki ?? ?️‍? | Sciencx - » Deploy a free, open-source Pusher alternative ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/
CHICAGO
" » Deploy a free, open-source Pusher alternative ?." Alex Renoki ?? ?️‍? | Sciencx - Accessed . https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/
IEEE
" » Deploy a free, open-source Pusher alternative ?." Alex Renoki ?? ?️‍? | Sciencx [Online]. Available: https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/. [Accessed: ]
rf:citation
» Deploy a free, open-source Pusher alternative ? | Alex Renoki ?? ?️‍? | Sciencx | https://www.scien.cx/2021/08/10/deploy-a-free-open-source-pusher-alternative-%f0%9f%93%a1/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.