GithubHelp home page GithubHelp logo

thekubera / laravel-pub-sub Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 75 KB

This repository demonstrates a Producer-Consumer setup using Apache Kafka.

Dockerfile 1.44% PHP 58.13% JavaScript 0.32% Blade 40.11%
apache-k docker docker-compose laravel-11 microservices nginx pub-sub

laravel-pub-sub's Introduction

Laravel Kafka Pub-Sub Application

This repository demonstrates a Producer-Consumer setup using Apache Kafka. The application consists of two main components:

  • A producer that sends messages to a Kafka topic.
  • A consumer that reads messages from the Kafka topic.

It utilizes two separate Laravel applications for producer and consumer functionality.

Prerequisites

  • Docker
  • Docker Compose

Getting Started

  1. Clone the Repository:

    git clone https://github.com/thekubera/laravel-pub-sub
  2. Start Services:

    Navigate to the project directory and execute the following command to initiate the Docker containers:

    docker compose up
  3. Copy and Adjust Environment Files:

    Once the build and startup are successful, copy the .env.example file to .env for both the producer and consumer Laravel applications, and make any necessary adjustments:

    For Producer:

    docker exec <producer-container-name> cp .env.example .env

    For Consumer:

    docker exec <consumer-container-name> cp .env.example .env

    Note: Replace <producer-container-name> and <consumer-container-name> with the actual container names obtained from docker-compose ps.

  4. Generate Laravel Application Keys:

    Generate application keys for both the producer and consumer Laravel applications:

    For Producer:

    docker exec <producer-container-name> php artisan key:generate

    For Consumer:

    docker exec <consumer-container-name> php artisan key:generate
  5. Access Producer Interface:

    Open your web browser and navigate to http://localhost:8000/producer/ to interact with the message producer.

  6. Consume Messages:

    To consume messages from the Kafka topic, run the following command in a separate terminal window:

    docker exec <consumer-container-name> php artisan kafka:consume

Code Exploration

For understanding the producer and consumer logic, explore the following files:

  • ProducerController.php (Producer application)
  • KafkaConsumerCommand.php (Consumer application)

Additional Notes

  • Ensure the Docker containers are running while accessing the producer interface and consuming messages.
  • This is a simple illustration of how messages can be published and subscribed to using Kafka. Additional considerations may be necessary depending on your specific requirements.

Contributions

This is a basic example to get you started with a Laravel Kafka Pub-Sub application. As you might see, it currently just produces a simple "Hello World!" message.

Want to enhance it? Feel free to contribute!

We welcome your contributions through issues and pull requests to make this Kafka Pub-Sub application even better!

laravel-pub-sub's People

Contributors

thekubera avatar

Watchers

 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.