gcn-kafka
TypeScript icon, indicating that this package has built-in type declarations

0.3.0 • Public • Published

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

/gcn-kafka/

    Package Sidebar

    Install

    npm i gcn-kafka

    Weekly Downloads

    457

    Version

    0.3.0

    License

    CC0-1.0

    Unpacked Size

    13.4 kB

    Total Files

    5

    Last publish

    Collaborators

    • lpsinger
    • dakota002