npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

socket.io-amqp0

v7.0.2

Published

socket.io adapter for amqp 0.9.1+ (e.g. RabbitMQ)

Downloads

41,668

Readme

socket.io-amqp0

Build Status NPM version

Table of contents

How to use

import { Server } from 'socket.io';
import { createAdapter } from 'socket.io-amqp0';
import { connect } from 'amqplib';

const io = new Server(3000);
io.adapter(createAdapter({ amqpConnection: () => connect('amqp://localhost') }));

By running Socket.IO with the socket.io-amqp0 adapter you can run multiple Socket.IO instances in different processes or servers that can all broadcast and emit events to and from each other.

So any of the following commands:

io.emit('hello', 'to all clients');
io.to('room42').emit('hello', "to all clients in 'room42' room");

io.on('connection', (socket) => {
  socket.broadcast.emit('hello', 'to all clients except sender');
  socket.to('room42').emit('hello', "to all clients in 'room42' room except sender");
});

will properly be broadcast to the clients through various AMQP exchanges/queues.

If you need to emit events to socket.io instances from a non-socket.io process, you should use socket.io-emitter.

How does it work under the hood?

This adapter extends the in-memory adapter that is included by default with the Socket.IO server.

The in-memory adapter stores the relationships between Sockets and Rooms in two Maps.

When you run socket.join("room21"), here's what happens:

console.log(adapter.rooms); // Map { "room21" => Set { "mdpk4kxF5CmhwfCdAHD8" } }
console.log(adapter.sids); // Map { "mdpk4kxF5CmhwfCdAHD8" => Set { "mdpk4kxF5CmhwfCdAHD8", "room21" } }
// "mdpk4kxF5CmhwfCdAHD8" being the ID of the given socket

Those two Maps are then used when broadcasting:

  • a broadcast to all sockets (io.emit()) loops through the sids Map, and send the packet to all sockets
  • a broadcast to a given room (io.to("room21").emit()) loops through the Set in the rooms Map, and sends the packet to all matching sockets

The AMQP adapter extends the broadcast function of the in-memory adapter: the packet is also published to an AMQP exchange with the same name as the room.

Each Socket.IO server that has at least one socket in the room receives this packet from its own queue bound to the exchange, and broadcasts it to its own list of connected sockets.

License

ISC