talentrydev / message-broker-bundle
Symfony 扩展,用于集成 talentrydev/message-broker 库
5.1.0-rc8
2024-08-15 14:45 UTC
Requires
- php: ^8.3
- predis/predis: ^1.1 || ^2.0
- symfony/config: ^6.3
- symfony/dependency-injection: ^6.3
- symfony/framework-bundle: ^6.3
- symfony/yaml: ^6.3
- talentrydev/message-broker: 5.1.0-rc8
Requires (Dev)
- phpunit/phpunit: ^11
- squizlabs/php_codesniffer: ^3.5
- symfony/monolog-bundle: ^3.8
README
这是一个用于将 talentrydev/message-broker 库集成到 Symfony 项目的 Symfony 扩展。
安装
- 运行
composer require talentrydev/message-broker-bundle
- 将 MessageBrokerBundle 添加到内核的
registerBundles
方法
return [
//...
new \Talentry\MessageBrokerBundle\MessageBrokerBundle();
];
配置
Bundle 提供以下配置
选项 | 类型 | 默认值 | 可用值 | 必需 | 描述 |
---|---|---|---|---|---|
aws_region | string | eu-central-1 | 任何有效的 AWS 区域 | 仅当使用 sns 或 sqs 实现时 | AWS 区域 |
channels | array | - | 见下文 | no | 用于配置通道和序列化策略 |
kafka | array | - | 见下文 | no | 用于配置 Kafka |
namespace | string | - | 任何字符串 | no | 用于前缀 SQS 队列名称 |
publisher_implementation | string | sqs | sqs,sns,array,kafka | yes | 选择用于发布消息的消息代理实现 |
sns_endpoint | string | - | 任何有效的 URL | no | 允许使用自定义 AWS SNS 实现(例如 localstack);对于测试很有用 |
sns_topic_arn | string | - | 任何有效的 AWS SNS ARN | 仅当使用 sns 发布者实现时 | SNS 主题的 ARN,消息将发布到该主题 |
sqs_endpoint | string | - | 任何有效的 URL | no | 允许使用自定义 AWS SQS 实现(例如 localstack);对于测试很有用 |
subscriber_implementation | string | sqs | sqs,array,kafka | yes | 选择用于接收消息的消息代理实现 |
通道配置
选项 | 类型 | 默认值 | 可用值 | 必需 | 描述 |
---|---|---|---|---|---|
name | string | - | 任何有效的通道名称 | yes | 通道名称 |
serialization_strategy | string | - | 有效的序列化策略类名 | yes | 实现 MessageSerializationStrategy 的类的 FQCN |
Kafka 配置
选项 | 类型 | 默认值 | 可用值 | 必需 | 描述 |
---|---|---|---|---|---|
auto_offset_reset | string | earliest | latest, earliest, none | 仅当使用 kafka 实现时 | https://kafka.apache.org/documentation/#consumerconfigs_auto.offset.reset |
broker_list | string | - | 有效的主机名列表 | 仅当使用 kafka 实现时 | https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/rdkafka.addbrokers.html |
enable_partition_eof | string | true | true 或 false | 仅当使用 kafka 实现时 | https://docs.confluent.io/3.2.1/clients/librdkafka/CONFIGURATION_8md.html |
enable_auto_commit | string | false | true 或 false | 仅当使用 kafka 实现时 | https://kafka.apache.org/documentation/#consumerconfigs_enable.auto.commit |
log_level | integer | 3 | 任何 LOG* PHP 常量 | 仅当使用 kafka 实现时 | 设置 Kafka PHP 模块的日志级别 | |||
max_poll_interval_ms | integer | 300000 | 任何整数 | 仅当使用 kafka 实现时 | https://kafka.apache.org/documentation/#consumerconfigs_max.poll.interval.ms |
session_timeout_ms | integer | 45000 | 任何整数 | 仅当使用 kafka 实现时 | https://kafka.apache.org/documentation/#connectconfigs_session.timeout.ms |
使用 kafka 实现的重要注意事项
- 为了使用 kafka 实现,您需要安装 php-rdkafka 扩展:https://arnaud.le-blanc.net/php-rdkafka-doc/phpdoc/index.html
- 不支持死信队列
- 消费者的水平扩展相当有限:消费者的数量不能超过给定主题上的分区数
- 如果消息的处理时间超过
max.poll.interval.ms
,则消费者将被踢出组,并且不会收到任何更多消息