Sign inSign up

asobchenyuk/node-app

By asobchenyuk

Updated almost 2 years ago

In this docker, we use a node for the backend

Image
Web servers
0

771

asobchenyuk/node-app repository overview

Node.js Kafka Consumer Application

This repository contains a Node.js application that connects to a Kafka cluster, consumes messages, and sends them to connected WebSocket clients. The application is containerized using Docker and can be deployed using Docker Compose.

Features

  • Connects to a Kafka cluster using SSL and SASL authentication
  • Consumes messages from a specified Kafka topic
  • Sends consumed messages to connected WebSocket clients
  • Configurable through environment variables

Environment Variables

The application uses the following environment variables which should be defined in a .env file:

  • KAFKA_BROKERS: List of Kafka brokers, separated by commas
  • KAFKA_TOPIC: Kafka topic to subscribe to
  • KAFKA_USERNAME: SASL username for Kafka authentication
  • KAFKA_PASSWORD: SASL password for Kafka authentication
  • KAFKA_PROTOCOL: Protocol for Kafka (e.g., SASL_SSL)
  • KAFKA_MECHANISM: SASL mechanism (e.g., PLAIN)
  • PORT: Port on which the WebSocket server will listen

Usage

Build and Run with Docker
  1. Clone the repository:

    git clone https://github.com/yourusername/node-app.git
    cd node-app
    
  2. Create a .env file and populate it with your environment variables:

    KAFKA_BROKERS=
    KAFKA_TOPIC=
    KAFKA_USERNAME=
    KAFKA_PASSWORD=
    KAFKA_PROTOCOL=
    KAFKA_MECHANISM=
    PORT=
    
  3. Build the Docker image:

    docker-compose build
    
  4. Run the Docker container:

    docker-compose up
    
Build and Push to Docker Hub
  1. Build the Docker image:

    docker build -t yourusername/node-app:latest .
    
  2. Login to Docker Hub:

    docker login
    
  3. Push the Docker image to Docker Hub:

    docker push yourusername/node-app:latest
    
Running Locally
  1. Install dependencies:

    npm install
    
  2. Run the application:

    npm start
    

Docker Compose

To use Docker Compose for local development and testing, follow these steps:

  1. Create a docker-compose.yml file in the root of your project:

    version: '3.3'
    services:
      node-app:
        build:
          context: .
          dockerfile: Dockerfile
          args:
            - PORT=${PORT}
        container_name: mhp-node
        ports:
          - "${PORT}:${PORT}"
        env_file:
          - .env
        volumes:
          - ./:/usr/src/app
          - ./cm-auto-in_cluster_ca_cert.pem:/usr/src/app/cm-auto-in_cluster_ca_cert.pem
          - ./truststore.jks:/usr/src/app/truststore.jks
    
  2. Run Docker Compose:

    docker-compose up
    
  3. Stop Docker Compose:

    docker-compose down
    

License

This project is licensed under the MIT License.

Tag summary

Content type

Image

Digest

sha256:48f2e980e

Size

421.2 MB

Last updated

almost 2 years ago

docker pull asobchenyuk/node-app