0.2.1 • Published 10 days ago

gcn-kafka v0.2.1

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
10 days ago

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',
})