/gcn-kafka-js

Official Node.js client for the General Coordinates Network (GCN)

Primary LanguageTypeScriptCreative Commons Zero v1.0 UniversalCC0-1.0

npm

GCN Kafka Client for Node.js

This is the official Node.js client for the General Coordinates Network (GCN). It is a very lightweight wrapper around Kafka.js.

To Install

Run this command to install with npm:

npm install gcn-kafka

To Use

Create a client:

import { Kafka } from 'gcn-kafka'
const kafka = new Kafka({
  client_id: 'fill me in',
  client_secret: 'fill me in',
})

List topics:

const admin = kafka.admin()
const topics = await admin.listTopics()
console.log(topics)

Subscribe to topics and receive alerts:

const consumer = kafka.consumer()
await consumer.subscribe({
  topics: [
    'gcn.classic.text.FERMI_GBM_FIN_POS',
    'gcn.classic.text.LVC_INITIAL',
  ],
})

await consumer.run({
  eachMessage: async (payload) => {
    const value = payload.message.value
    console.log(value?.toString())
  },
})

Testing and Development Kafka Clusters

GCN has three Kafka clusters: production, testing, and an internal development deployment. Use the optional domain parameter to select which broker to connect to.

// Production (default)
const kafka = new Kafka({
  client_id: 'fill me in',
  client_secret: 'fill me in',
  domain: 'gcn.nasa.gov',
})

// Testing
const kafka = new Kafka({
  client_id: 'fill me in',
  client_secret: 'fill me in',
  domain: 'test.gcn.nasa.gov',
})

// Development (internal)
const kafka = new Kafka({
  client_id: 'fill me in',
  client_secret: 'fill me in',
  domain: 'dev.gcn.nasa.gov',
})