BloomRealtimeCluster class

High-throughput multi-isolate cluster orchestrator for Bloom Realtime.

Distributes incoming WebSocket connections across multiple CPU cores using kernel-level port sharing (shared: true), synchronizing pub/sub broadcasts in-memory across isolates via high-speed isolate SendPort mesh routing.

Architecture

  • Each isolate worker runs an independent BloomChannelHub and HttpServer.
  • Kernel load-balances incoming TCP connections across isolate worker sockets.
  • Whenever a client or server broadcasts on any worker, the payload is forwarded across isolate SendPort peer links so all subscribers across all cores receive the update.

Example

void main() async {
  final cluster = await BloomRealtimeCluster.bind(
    port: 8080,
    wsPath: '/ws/realtime',
    workers: 4,
  );
  print('Realtime cluster running with ${cluster.workerCount} workers on port ${cluster.port}');

  // Broadcast from cluster master
  cluster.broadcast('system:alerts', {'message': 'Maintenance in 5 minutes'});

  // Gracefully shut down
  // cluster.close();
}

Properties

hashCode int
The hash code for this object.
no setterinherited
port int
Listening TCP port for the cluster.
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
workerCount int
Number of active worker isolates running in the cluster.
final

Methods

broadcast(String channel, Map<String, dynamic> payload, {bool asBinary = false}) → void
Broadcasts an event across all cluster workers and connected WebSocket clients.
close() → void
Shuts down all worker isolates, closes HTTP servers, and releases listening ports.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Methods

bind({String address = '0.0.0.0', int port = 8080, String wsPath = '/ws', int? workers, CompressionOptions compression = CompressionOptions.compressionOff, bool tcpNoDelay = true}) Future<BloomRealtimeCluster>
Spawns and starts a multi-isolate realtime cluster.