npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

node-kafka-rest

v0.15.0

Published

kafka consumer & producer via HTTP REST

Downloads

5

Readme

Node Kafka REST API

DISCLAIMER: The goal of this project is to mimic confluent/kafka-rest-proxy to offer a faster interface to topic data for applications like kafka-topics-ui, as kafka-rest-proxy troubles with larger message payloads or a large amount of messages on the topic. If you are looking for a complete rest-proxy for kafka, this is not the tool you are looking for.

Quick start

  • Run kafka-setup: yarn run kafka:start
  • Open kafka topics ui: http://localhost:8000

Curling the API

Get topics

curl -X GET \
  http://localhost:8082/topics \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "name": "peter",
    "format": "json",
    "auto.offset.reset": "earliest"
  }'

Get topic infos

curl -X GET \
  http://localhost:8082/topics/peters-topic \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "name": "peter",
    "format": "json",
    "auto.offset.reset": "earliest"
  }'

Create a consumer

curl -X POST \
  http://localhost:8082/consumers/peter \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "name": "peter",
    "format": "json",
    "auto.offset.reset": "earliest"
  }'

Use consumer to subscribe to topic

curl -X POST \
  http://localhost:8082/consumers/peter/instances/peter/subscription \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{
    "topics": ["peters-topic", "ks-fourth-4b63a506-4e46-4c78-a0b2-24922a1124db"]
  }'

Fetch data

curl -X GET \
  http://localhost:8082/consumers/peter/instances/peter/records \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'

Close and remove consumer

curl -X DELETE \
  http://localhost:8082/consumers/peter/instances/peter \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json'

Using Docker

If you want to customize any Kafka REST parameters, simply add them as environment variables, e.g.:

  • To set the http.port parameter set the environment to KAFKA_REST_HTTP_PORT: 8082.
  • To turn on debug mode for consumer and producer set KAFKA_REST_DEBUG: "all".
  • To set the group.id only for consumer set the environment to KAFKA_REST_CONSUMER_GROUP_ID: "kafka-rest-consumer-group".

The full list and descriptions of config parameters can be found here.

Check out our docker compose example:

---
version: "2"
services:
  zookeeper:
    image: wurstmeister/zookeeper:latest
    ports:
      - 2181:2181

  kafka:
    image: wurstmeister/kafka:0.10.2.1
    ports:
      - "9092:9092"
    links:
      - zookeeper
    depends_on:
      - zookeeper
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_PORT: 9092
      KAFKA_ADVERTISED_HOST_NAME: "kafka"
      KAFKA_ADVERTISED_LISTENERS: "PLAINTEXT://kafka:9092"
      KAFKA_LISTENERS: "PLAINTEXT://:9092"
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_CREATE_TOPICS: "test:1:1"
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: "true"

  kafka-rest:
    image: nodefluent/kafka-rest
    ports:
      - 8082:8082
    links:
      - kafka
      - zookeeper
    depends_on:
      - kafka
      - zookeeper
    environment:
      KAFKA_REST_DEBUG: "all"
      KAFKA_REST_HTTP_PORT: 8082
      KAFKA_REST_CONSUMER_METADATA_BROKER_LIST: "kafka:9092"
      KAFKA_REST_PRODUCER_METADATA_BROKER_LIST: "kafka:9092"

  kafka-topics-ui:
    image: landoop/kafka-topics-ui
    ports:
      - 8000:8000
    links:
      - kafka-rest
    depends_on:
      - kafka-rest
    environment:
      KAFKA_REST_PROXY_URL: "http://kafka-rest:8082"
      PROXY: "true"