Skip to content

A minimal example of running Apache Pulsar with websockets server and client side (in a browser)

License

Notifications You must be signed in to change notification settings

yngvark/apache-pulsar-websockets-example

Repository files navigation

A minimal example of running Apache Pulsar with websockets server and client side (in a browser)

How to run

1. Run Pulsar server

Clone this repo and run

docker-compose up -d

2. Run a Pulsar producer

npm install
node producer.js

3. Run a consumer in a browser

Open your favourite browser's console, and paste in the following Javascript:

// http://pulsar.apache.org/docs/en/client-libraries-websocket.html#nodejs-consumer

var websocket = new WebSocket("ws://localhost:38080/ws/v2/consumer/persistent/public/default/my-topic/my-sub")
websocket.onopen = (event) => {
    console.log("Connected!")
}

websocket.onmessage = (event) => {
    j = JSON.parse(event.data)
    console.log("Received message", j)
    console.log("Payload: ", atob(j.payload)) // Base64 decode
}

// websocket.close()

This code can only be run once at a time. Run

websocket.close()

if you want to start a new consumer.

About

A minimal example of running Apache Pulsar with websockets server and client side (in a browser)

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Sponsor this project

Packages

No packages published