How to connect and send messages

Basic integration covers the following use case:

  1. Client (business application / web browser) subscribes and listen to one or multiple channels.
  2. Server (or any other business app) publishes messages to the corresponding channels. The messages will be instantly delivered to subscribed clients.

How to subscribe

Clients (web browsers) can subscribe using standard browser EventSource API. You just need to provide a broker server name (e.g. hub11.dev-labs.io) and a comma separate list of channels to subscribe.

Example of a simple listener (no security):

// define the list of channels to subscribe
const URL = "https://hub11.dev-labs.io?channels=alfa,bravo,charlie"

// subscribe and start listening
const evtSource = new EventSource(URL, {withCredentials: false});

// define a handler - what to do when a new message comes in
evtSource.onmessage = function(msg) {
   console.log(msg); // just log the incoming message to console
}

How to send a message

To send a message to the particular channel you just need to send a POST request to the broker server with the following JSON payload:

{
    "channel": "alfa",
    "data": "Hello world!"
}

The following javascript code sends a message to "alfa" channel:

fetch('https://hub11.dev-labs.io', {
    method: 'post',
    body: JSON.stringify({
       "channel": "alfa", 
       "data": "Hello world!"
    })
  })

Security

When you work with a secure instance of buzzPost your need to add an authentication KEY to subscribe and POST messages. Please contact support for details.

NextServiceNow integration