exoticca/kafka-transport 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

exoticca/kafka-transport

Composer 安装命令:

composer require exoticca/kafka-transport

包简介

A Symfony bundle for integrating Kafka with Messenger

README 文档

README

exoticcaLogoBlack (1)

Exoticca Kafka Transport Bundle

What is it for?

The Exoticca Kafka Messenger Bundle extends Symfony Messenger's capability to use Kafka as a transport, facilitating integration with event-driven architectures.

Motivation

Existing solutions to integrate Kafka with Symfony Messenger present limitations when working with complex event architectures. This bundle addresses these issues by offering greater flexibility and traceability in event management.

Features

  • Generic Serialization and Deserialization: Manages the entire message flow using Symfony's serializer.
  • Message Production and Consumption: Supports both single-topic and multi-topic scenarios, enabling complex event flows.
  • Selective Message Consumption: Allows consuming only relevant messages for the application while efficiently discarding the rest.
  • Enhanced Traceability: Supports defining custom headers generically for any message.
  • Optional Schema Validation: Integrates with Schema Registry using Apache Avro, allowing selective validation by transport.
  • Apache Union Schema Compatibility: Thanks to enhancements on the reference library avro-php.

Installation

composer require exoticca/kafka-transport

Add the bundle to the list of bundles in config/bundles.php:

Exoticca\KafkaMessenger\ExoticcaKafkaBundle::class => ['all' => true],

Basic Configuration

Create a configuration file at config/packages/exoticca_kafka_messenger.yaml with the minimal setup:

exoticca_kafka_messenger:
  identifier:
    staticMethod: 'eventName'
  consumer:
    validate_schema: false
    config:
      group.id: 'group-id'
  producer:
    validate_schema: false
    config: {}

Explanation

  • staticMethod: A static method that returns a string, required in all messages to enable complex Kafka routing.
  • validate_schema: By default, schema validation against Schema Registry is disabled.
  • config: Allows adding specific Kafka configuration. See the official documentation for more details.

Transport Configuration

Example of transport configuration in messenger.yaml:

kafka:
  dsn: '%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_DSN)%'
  options:
    topics: [ 'test_topic' ]
    consumer:
      routing:
        - name: 'test_event'
          class: 'Exoticca\Domain\Event\TestEvent'
      config:
        group.id: 'group-id'

routing:
  'Exoticca\RMS\Domain\Event\TestEvent': kafka

Security

You can set your security settings in the bundle configuration.

exoticca_kafka_messenger:
  consumer:
    config:
      security.protocol: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SECURITY_PROTOCOL)%"
  producer:
    config:
      security.protocol: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SECURITY_PROTOCOL)%"
      
when@prod:
  exoticca_kafka_messenger:
    consumer:
      config:
        sasl.mechanisms: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_MECHANISMS)%"
        sasl.username: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_USERNAME)%"
        sasl.password: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_PASSWORD)%"
    producer:
      config:
        sasl.mechanisms: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_MECHANISMS)%"
        sasl.username: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_USERNAME)%"
        sasl.password: "%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_SASL_PASSWORD)%"

Execution

To consume the message:

bin/console messenger:consume kafka -vvv

The bundle will automatically deserialize the message.

Advanced Usage

Consume Multiple Message Types from a Single Topic

If a topic contains multiple event types (e.g., CustomerRegistered, CustomerUpdated, CustomerDeleted), you can configure the bundle to consume only the relevant messages and automatically commit the rest.

Consume from Multiple Topics in a Single Transport

Example:

complex_transport:
  dsn: '%env(KAFKA_EVENTS_MESSENGER_TRANSPORT_DSN)%'
  options:
    topics: ['customers', 'orders']
    consumer:
      config:
        group.id: 'group-id'
      routing:
        - name: 'customer_created'
          class: 'Exoticca\Domain\Customer\Event\CustomerCreated'
        - name: 'order_created'
          class: 'Exoticca\Domain\Order\Event\OrderCreated'

Acknowledgments

Special thanks to the avro-php library for facilitating integration with Apache Avro.

exoticca/kafka-transport 适用场景与选型建议

exoticca/kafka-transport 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 30.2k 次下载、GitHub Stars 达 2, 最近一次更新时间为 2025 年 02 月 26 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「queue」 「symfony」 「bundle」 「transport」 「Messenger」 「kafka」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 exoticca/kafka-transport 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 exoticca/kafka-transport 我们能提供哪些服务?
定制开发 / 二次开发

基于 exoticca/kafka-transport 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 30.2k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 25
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 2
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-02-26