Giter VIP home page Giter VIP logo

Comments (7)

mateusjunges avatar mateusjunges commented on August 21, 2024 1

This library doesn't provide the command to consume messages, so you are free to implement it whatever way you think is better, but yeah, if all consumers looks like this, it's a good implementation.

from laravel-kafka.

mateusjunges avatar mateusjunges commented on August 21, 2024

Hi @renatocosta, i'm building and example project using this library. Will make it public as soon as it's ready, but for now, you can create a command something like this:

class ConsumeXKafkaTopic extends Command
{
    protected $signature = 'kafka:consume-X-topic';

    protected $description = 'Consume messages from kafka topic X';

    public function handle()
    {
        $consumer = Kafka::createConsumer()
            ->subscribe('X-topic')
            ->withConsumerGroupId('your-group-id')
            ->withHandler(new XTopicConsumer())
            ->withAutoCommit()
            ->build();

        $consumer->consume();
    }
}

from laravel-kafka.

renatocosta avatar renatocosta commented on August 21, 2024

Thank you again @mateusjunges

By the way, When I used Enqueue lib had a class processor to keep on reading the messages 24/7.
Is there in this library anything like that?

from laravel-kafka.

mateusjunges avatar mateusjunges commented on August 21, 2024

I think enqueue use queue-interop to do this. I haven't tested it so can't confirm it works with this library.

from laravel-kafka.

renatocosta avatar renatocosta commented on August 21, 2024

That's right.
If I understand correctly the ConsumeXKafkaTopic class would be called manually via the command line so that reading a new message?

from laravel-kafka.

mateusjunges avatar mateusjunges commented on August 21, 2024

Yes, but i use supervisor to run the command in background for me.

from laravel-kafka.

renatocosta avatar renatocosta commented on August 21, 2024

I don't know as you implemented it but I think that it would be a reusable class to be derived from another one.

class ConsumeXKafkaTopic extends Command
{
    protected $signature;

    protected $description;

    protected string $topicName;

    protected $groupId;

    protected $topicConsumerHandler;

    public function handle()
    {
        $consumer = Kafka::createConsumer()
            ->subscribe($this->topicName)
            ->withConsumerGroupId($this->groupId)
            ->withHandler($this->topicConsumerHandler)
            ->withAutoCommit()
            ->build();

        $consumer->consume();
    }
}
final class ConsumeUsers extends ConsumeXKafkaTopic
{
    public function __construct()
    {
     parent::signature = ' kafka:consume-users-topic';
     parent::description = 'Consume messages from kafka topic Users';
     parent::topicName = 'users';
     parent::topicConsumerHandler = new XTopicConsumer();
     parent::groupId = 'UserGroups';
    }

    public function handle()
    {
      parent::handle();
    }
}

Just an idea.

from laravel-kafka.

Related Issues (20)

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.