1. Go to this page and download the library: Download werk365/larakafka library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Werk365\LaraKafka\LaraKafka;
$kafka = new LaraKafka();
$kafka->setTopic("string") //optional, defaults to application name
->setKey("string") // optional, default will be the caller classname
->setHeaders(["key" => "value"]) // optional, default will contain more information about caller
->setBody("string") // Body can also be set like: $kafka = new LaraKafka("body")
->produce();
namespace App\Services;
use Illuminate\Support\Facades\Log;
class KafkaService
{
public static function ingest($key, $headers, $body)
{
Log::info(json_encode($body));
}
}
namespace App\Services;
use Werk365\LaraKafka\LaraKafka;
class KafkaService
{
public static function ingest($key, $headers, $body)
{
$kafka = new LaraKafka();
$kafka->storeMessage($body->event_attributes, ["user"]);
}
}