Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

An opinionated Symfony bundle for a painless integration of Apache Kafka.

License

NotificationsYou must be signed in to change notification settings

geekcell/kafka-symfony-bundle

Repository files navigation

An opinionated Symfony bundle for a painless integration ofApache Kafka.

Requirements

Installation

To use this bundle, require it in Composer

composer require geekcell/kafka-bundle

Quickstart

Inherit fromRecord to define records you want to send to Kafka.

useGeekCell\KafkaBundle\Record;useFlixTech\AvroSerializer\Objects\Schema;class OrderDtoextends Record{publicint$id;publicint$productId;publicint$customerId;publicint$quantity;publicfloat$total;publicstring$status ='PENDING';publicfunctiongetKey(): ?string    {// Nullable; if provided it will be used as message key// to preserve message ordering.returnsprintf('order_%s',$this->id);    }protectedfunctionwithFields(RecordType$root):Schema    {// See for examples:// https://github.com/flix-tech/avro-serde-php/tree/master/test/Objects/Schema$root            ->field('id', Schema::int())            ->field('productId', Schema::int())            ->field('customerId', Schema::int())            ->field('quantity', Schema::int())            ->field('total', Schema::float())            ->field('status',                 Schema::enum()                    ->name('OrderStatusEnum')                    ->symbols(...['PENDING','PAID','SHIPPED','CANCELLED'])                    ->default('PENDING'),            );return$root;    }}

Create an event, which implements theEvent contract and returns the above record assubject.

useGeekCell\KafkaBundle\Contracts\Event;class OrderPlacedEventimplements Event{publicfunction__construct(privateOrderDto$orderDto,    ) {    }publicfunctiongetSubject():Record    {return$this->orderDto;    }}

If you dispatchEvent via the standard Symfony event dispatcher, it will be automatically be serialized into Avro format, registered, send to Kafka based on your configuration.

$this->eventDispatcher->dispatch(newOrderPlacedEvent($orderDto));

Bundle Configuration Example

geek_cell_kafka:avro:schema_registry_url:'http://schemaregistry:8081'schemas:defaults:namespace:'com.acme.avro'events:lookup:# Look up events in the following directories            -'src/Event'kafka:brokers:'broker:9091,broker:9092'global:# Global config params for librdkafka (not pre-validated)# https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md#global-configuration-propertiestopic:# Topic config params for librdkafka (not pre-validated)# https://github.com/confluentinc/librdkafka/blob/master/CONFIGURATION.md#topic-configuration-properties

[8]ページ先頭

©2009-2025 Movatter.jp