Kafka
Sugoi has built-in support for Kafka. You only need to install the rdkafka
extension.
Consumers
This works the exact same way as the HTTP controllers. Use the KafkaConsumer
to register your handler for auto-discovery.
php
#[KafkaConsumer]
class OrderHandler
{
#[MessageSub(topic: 'orders')]
public function onSomething(SpanKafka $span, Order $order): void
{
$span->debug('Order accepted', Tensei::toArray($order));
$span->reject(); // Various Kafka specific message APIs are included on the Span.
}
}
Producers
Client/producer implementations will be auto-generated by the framework, you only need to define your interfaces and the framework will handle the rest in the background.
php
#[KafkaProducer]
interface OrderProducer
{
#[MessagePub(topic: 'orders')]
public function onOrderCreated(Order $order);
}
Configuration
yaml
sugoi:
messaging:
kafka:
brokers: kafka:9092
group-id: api-group