Git Product home page Git Product logo

atomickafka's Introduction

AtomicKafka_MastHead


Dependencies

  • Kafka-JS
  • Socket-IO (Server & Client)
  • React
  • Dotenv

Getting Started:

1. Initialize Kafka Cluster:

Atomic Kafka currently supports running Apache Kafka clusters either using a Docker image or by connecting to Confluent Cloud.

Docker:

  • Download this .yml and run the following command in your terminal:
    docker-compose up -d
    

Confluent Cloud:

  • Follow the steps on Confluent Cloud to create a free account with Confluent cloud. Obtain the API_ACCESS_KEY, API_ACCESS_SECRET, and BOOTSTRAP_SERVER

2. Configure .env file.

Include the following lines in your .env depending on your Kafka environment.

  • Docker .env config: (API_KEY and API_SECRET are intentionally left blank)
    PORT=<USER_DEFINED>
    API_KEY=
    API_SECRET=
    KAFKA_BOOTSTRAP_SERVER=localhost:9092
    KAFKA_SSL=false
  • Confluent Cloud .env config: (PORT intentionally left blank)
    PORT=<USER_DEFINED>
    API_KEY=<API_ACCESS_KEY>
    API_SECRET=<API_ACCESS_SECRET>
    KAFKA_BOOTSTRAP_SERVER=<BOOTSTRAP_SERVER>

3. Create Server Instance:

Initialize a server instance of your choice (HTTP, Node.js, etc). The example below contemplates a Node.js Express server.

ATTENTION: a Server instance must be created for every remote Atomic Kafka Client.

  1. Initialize and configure expressApp according to desired specifications.
  2. Require in AtomicKafkaServer.
  3. Define a server that listens on the user-defined PORT environment variable.
  4. Initialize an AtomicKafkaServer instance aks by passing in the server.
//initialize and configure expressApp according to user specifications

const AtomicKafkaServer = require('atomic-kafka/server')

const server = expressApp.listen(process.env.PORT, () => {
  console.log(`Listening on port ${process.env.PORT}`);
})

const aks = new AtomicKafkaServer(server);

4A. Create the Consumer and enable the built-in websocket on the server:

  1. Initailize a newConsumer on the aks instance and pass in the group_ID_string.
  2. Enable the built-in websocket by invoking socketConsume and passing in the group_ID_string, an event_string, and the topic_string.
atomicKafkaInstance.newConsumer('group_ID_string');
atomicKafkaInstance.socketConsume('group_ID_string', 'event_string', 'topic_string');

4B. Create the Producer and enable the built-in websocket on the server:

  1. Initailize a newProducer on the aks instance and pass in the topic_string.
  2. Enable the built-in websocket by invoking globalProducer and passing in an event_string and the topic_string.
atomicKafkaInstance.newProducer('topic_string');
atomicKafkaInstance.globalProduce('postMessage', 'test_topic')

5A. JavaScript - Import Client Interface (React & Hooks)

import AtomicKafkaClient from 'atomic-kafka/client';

5B. TypeScript - Import Client Interface (React & Hooks)

declare function require(name:string)
const AtomicKafkaClient = require('atomic-kafka/client').default

6A. Create and implement Consumer client component (JS & TS):

  1. Initialize akc as an AtomicKafkaClient. Pass in AtomicKafkaServer instance host's URI_STRING
  2. Define a callback to process message payload through the React state management tool of your choice.
  3. Implement useInterval to consume from the kafka cluster on interval.
  4. Return the invocation of the consumer function on the akc instance. Pass in a user-defined websocket event_string, the previously defined callback, and the interval_delay in milliseconds.
function Consumer_Component () {

  const akc = new AtomicKafkaClient(URI_STRING);

  const callback = (payload) => {
    //user-defined function definition
  }

  akc.useInterval(() => akc.consumer(<event_string>, callback), <interval_delay>)
}

6B.: Create and implement Producer client component (JS & TS):

  1. Initialize akc as an AtomicKafkaClient. Pass in AtomicKafkaServer instance host's URI_STRING
  2. Generate a payload formatted as an arbitrarily-nested JSON object. The example below defines a payload, but it can be generated at any point in the client according to the user's specification.
  3. Invoke the consumer function. Pass in the websocket event_string and the payload.
function Producer_Component () {

  const akc = new AtomicKafkaClient(URI_STRING);

  const payload = {
    //arbitrarily nested key value pairs
  };

  akc.producer(<event_string>, payload);
}

atomickafka's People

Contributors

dbehmoaras avatar josephjslee avatar nikhilmassand avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.