import { Controller, Sse, Headers } from '@nestjs/common';
import { interval, Observable } from 'rxjs';
import { map } from 'rxjs/operators';
interface FeedPayload {
id: number;
import { Response } from 'express';
type Client = { id: number; res: Response };
const clients = new Map<string, Set<Client>>();
let nextId = 1;
package com.example.notifications;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import java.io.IOException;
const { EventEmitter } = require('events');
const HIGH_WATER_MARK = 1 << 20; // 1 MiB of buffered bytes per client
class SseHub extends EventEmitter {
constructor() {
const { EventEmitter } = require('events');
class NotificationBus extends EventEmitter {
constructor(bufferSize = 100) {
super();
this.setMaxListeners(0);
package sse
type Broker struct {
subscribers map[chan []byte]struct{}
subscribe chan chan []byte
unsubscribe chan chan []byte
@RestController
@RequestMapping("/api/notifications")
public class NotificationController {
private final SseEmitterRegistry registry;
private final NotificationService service;
package realtime
import (
"fmt"
"net/http"
"time"
require 'set'
require 'json'
class Broadcaster
def initialize
@mutex = Mutex.new