1. Go to this page and download the library: Download ziffmedia/laravel-ksql 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/ */
ziffmedia / laravel-ksql example snippets
$client = new Ziffmedia\LaravelKsql\Client("http://my.ksqldb.server:8088");
$client = new Ziffmedia\LaravelKsql\Client("http://my.ksqldb.server:8088", "myusername", "mypassword");
class QueryResult
{
public string $query; // the sql string used to produce this result
public array $columns; // an associative array keyed by column names in the result, with values equal to the data type for that column
public string|null $name; // the convenience name key used for this query. Value will be null unless this result was produced from multiplexing
public array $data; // an associative array of column name to column value. This will represent one row of a results data set.
}
class KsqlStreamChanged
{
public QueryResult $result;
}
$client = new Ziffmedia\LaravelKsql\Client("http://my.ksqldb.server:8088");
// full synchronous query returning an array of QueryResult objects
/** @var QueryResult[] $result */
$result = $client->query("SELECT * FROM MYTABLE LIMIT 5");
// use an optional row handler
$client->query("SELECT * FROM MYTABLE LIMIT 5", function(QueryResult $row) {
dump($row);
})
// emit events using the built-in event class
$client->query("SELECT * FROM MYTABLE LIMIT 5", true);
// emit events using a custom event class
$client->query("SELECT * FROM MYTABLE LIMIT 5", App\Event\MyTableChanged::class);
$client = new Ziffmedia\LaravelKsql\Client("http://my.ksqldb.server:8088");
// emit events using the built-in event class
$client->stream("SELECT * FROM MYTABLE EMIT CHANGES");
// use an optional row handler
$client->stream("SELECT * FROM MYTABLE EMIT CHANGES", function(QueryResult $row) {
dump($row);
})
// emit events using a custom event class
$client->stream("SELECT * FROM MYTABLE EMIT CHANGES", App\Event\MyTableChanged::class);
$client = new Ziffmedia\LaravelKsql\Client("http://my.ksqldb.server:8088");
$client->multiplex()
->query('mytable', "SELECT * FROM MYTABLE EMIT CHANGES")
->query('yourtable', 'SELECT * FROM YOURTABLE EMIT CHANGES')
->stream();
bash
$> php artisan ksql-consumer
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.