A brief demo of real-time plotting with Plotly, Go, and server-sent events

Golang SSE Demo

A brief demo of real-time plotting with Plotly, Go, and server-side events.

Overview

I first learned about Server-Sent Events from @mroth's How I Built Emojitracker and have been intrigued ever since.

However, it wasn't until I came across @benbjohnson's litestream-read-replica-demo that I realized just how easy they were to use. I thought there was all sorts of complexity, but no!

It's really simple...all you need to do is create a new EventSource in your JavaScript and feed it updates!

var sse = new EventSource("/api/stream");
sse.addEventListener("update", function (e) {
  // Do something!
});

Demo

This repo shows how to use Go to send events to the browser and, of course, draw a real-time chart with Plotly. :)

git clone https://github.com/dacort/golang-sse-demo.git
cd golang-sse-demo
go run *.go

Then browse to http://localhost:3000

💥

Screenshot

Similar Resources

Golang push server cluster

Golang push server cluster

gopush-cluster gopush-cluster is a go push server cluster. Features light weight high performance pure golang implementation message expired offline m

Dec 28, 2022

A push notification server written in Go (Golang).

A push notification server written in Go (Golang).

gorush A push notification micro server using Gin framework written in Go (Golang) and see the demo app. Contents gorush Contents Support Platform Fea

Jan 8, 2023

websocket based messaging server written in golang

Guble Messaging Server Guble is a simple user-facing messaging and data replication server written in Go. Overview Guble is in an early state (release

Oct 19, 2022

High-Performance server for NATS, the cloud native messaging system.

High-Performance server for NATS, the cloud native messaging system.

NATS is a simple, secure and performant communications system for digital systems, services and devices. NATS is part of the Cloud Native Computing Fo

Jan 2, 2023

NanoMDM is a minimalist Apple MDM server heavily inspired by MicroMDM

NanoMDM NanoMDM is a minimalist Apple MDM server heavily inspired by MicroMDM. Getting started & Documentation Quickstart A quick guide to get NanoMDM

Dec 28, 2022

Notifie Server is a learning list notifier

Notifie Server Notifie Server is a learning list notifier. E.g; If you want to l

Dec 24, 2021

Converter EPG XMLTV to OTT-play (by Alex) server side JSON

EPG converter for OTT-play FOSS Описание Инструмент создания телепрограммы для OTT-Play FOSS, использует 1 поток, и буферное чтение из файла, что позв

Jan 6, 2023

Cadence is a distributed, scalable, durable, and highly available orchestration engine to execute asynchronous long-running business logic in a scalable and resilient way.

Cadence Visit cadenceworkflow.io to learn about Cadence. This repo contains the source code of the Cadence server. To implement workflows, activities

Jan 9, 2023

The Xiaomi message push service is a system-level channel on MIUI and is universal across the platform, which can provide developers with stable, reliable, and efficient push services.

Go-Push-API MiPush、JiPush、UMeng MiPush The Xiaomi message push service is a system-level channel on MIUI and is universal across the platform, which c

Oct 20, 2022
Comments
  • Setting channel is racy

    Setting channel is racy

    			notify.mu.Lock()
    			notify.value = rand.Intn(100)
    			notify.mu.Unlock()
    
    			// notify.ch <- struct{}{}
    			close(notify.ch)
    			notify.ch = make(chan struct{})
    

    notify.ch = make(chan struct{}) is not in a lock, so it could race that someone reads it in the middle of a write.

    I think it would be simpler if you had something like:

    type broadcaster struct{ 
      value int
      notifier chan struct{} 
    }
    
    // in main 
    for {
      lock.Lock()
      notify = broadcaster { notifier: make(chan struct{}) }  
      lock.Unlock()
      time.Sleep()
      notify.value = math.Rand()
      close(notify.notifier)
    }
    
    // in the handler
    lock.RLock()
    localnotify := notify
    lock.RUnlock()
    <- localnotify.notifier
    send(localnotify.value)
    
Scalable real-time messaging server in language-agnostic way
Scalable real-time messaging server in language-agnostic way

Centrifugo is a scalable real-time messaging server in language-agnostic way. Centrifugo works in conjunction with application backend written in any

Jan 2, 2023
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.
💨 A real time messaging system to build a scalable in-app notifications, multiplayer games, chat apps in web and mobile apps.

Beaver A Real Time Messaging Server. Beaver is a real-time messaging server. With beaver you can easily build scalable in-app notifications, realtime

Jan 1, 2023
nanoQ — high-performance brokerless Pub/Sub for streaming real-time data

nanoQ — high-performance brokerless Pub/Sub for streaming real-time data nanoQ is a very minimalistic (opinionated/limited) Pub/Sub transport library.

Nov 9, 2022
Emits events in Go way, with wildcard, predicates, cancellation possibilities and many other good wins

Emitter The emitter package implements a channel-based pubsub pattern. The design goals are to use Golang concurrency model instead of flat callbacks

Jan 4, 2023
Imagine a simple, beautiful, secure, and freaking fast way to broadcast your events throw the internet

Event Superintendent Imagine a simple, beautiful, secure, and freaking fast way to broadcast your events throw the internet. That's exactly why you sh

Jul 18, 2022
This service consumes events about new posts in go blog (go.dev)

This service consumes events about new posts in go blog (go.dev) from message broker (rabbitmq) (gbu-scanner service publishes these events) and sends notifications to websocket and grpc streams consumers.

Jan 29, 2022
Batch messages over a time interval

timebatch timebatch is a package for batching messages over a time interval. This can be useful for receiving messages that occur "quickly" and sendin

Nov 3, 2021
⚡️ A lightweight service that will build and store your go projects binaries, Integrated with Github, Gitlab, Bitbucket and Bitbucket Server.
⚡️ A lightweight service that will build and store your go projects binaries, Integrated with Github, Gitlab, Bitbucket and  Bitbucket Server.

Rabbit A lightweight service that will build and store your go projects binaries. Rabbit is a lightweight service that will build and store your go pr

Nov 19, 2022
Uniqush is a free and open source software system which provides a unified push service for server side notification to apps on mobile devices.

Homepage Download Blog/News @uniqush Introduction Uniqush (\ˈyü-nə-ku̇sh\ "uni" pronounced as in "unified", and "qush" pronounced as in "cushion") is

Jan 9, 2023
golang long polling library. Makes web pub-sub easy via HTTP long-poll server :smiley: :coffee: :computer:
golang long polling library.  Makes web pub-sub easy via HTTP long-poll server :smiley: :coffee: :computer:

golongpoll Golang long polling library. Makes web pub-sub easy via an HTTP long-poll server. New in v1.1 Deprecated CreateManager and CreateCustomMana

Jan 6, 2023