Publishing to kafka

After configuring all your message options, use the send method to send the message to Kafka.

use Junges\Kafka\Facades\Kafka;

Kafka::publish('topic')
    ->withKey('kafka-key')
    ->withHeaders(['header-key' => 'header-value'])
    ->withBody(['key' => 'value'])
    ->send();

The publish method queues the message, and it is delivered in the background. If you need to wait until the message is delivered, use publishSync instead:

use Junges\Kafka\Facades\Kafka;

Kafka::publishSync('topic')
    ->withKey('kafka-key')
    ->withBody(['key' => 'value'])
    ->send();

You can also wait for every queued message to be delivered at any moment by calling Kafka::flush().

Sponsorship

Support Laravel Kafka by sponsoring me!

Laravel Kafka is free and Open Source software, built to empower developers like you. Your support helps maintain and enhance the project. If you find it valuable, please consider sponsoring me on GitHub. Every contribution makes a difference and keeps the development going strong! Thank you!

Become a Sponsor Want to hide this message? Sponsor at any tier of $10/month or more!