-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkafka.php
28 lines (23 loc) · 899 Bytes
/
kafka.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
<?php
use Enqueue\RdKafka\RdKafkaConnectionFactory;
// connect to Kafka broker at example.com:1000 plus custom options
$connectionFactory = new RdKafkaConnectionFactory(
[
'global' => [
'group.id' => uniqid('', true),
'metadata.broker.list' => 'example.com:1000',
'enable.auto.commit' => 'false',
],
'topic' => [
'auto.offset.reset' => 'beginning',
],
]
);
// if you have enqueue/enqueue library installed you can use a factory to build context from DSN
$context = (new \Enqueue\ConnectionFactoryFactory())->create('kafka:')->createContext();
$testEventsTopic = $context->createTopic('test_events');
$messages = ['messaga 1', 'messaga 2', 'messaga 3'];
foreach ($messages as $message) {
echo "\nMessage:\n$message\n\n";
$context->createProducer()->send($testEventsTopic, $message);
}