Sending multiple messages with the same producer
Every connection has a single producer, created the first time you publish a message and shared by every message published through that connection afterwards. You don't need to do anything to reuse it:
use Junges\Kafka\Facades\Kafka; foreach ($orders as $order) { Kafka::publish('orders')->withKey((string) $order->id)->withBody($order->toArray())->send(); }
The messages are delivered in the background and flushed when the application terminates. If you need to wait until all of them are delivered before moving on, call 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!