vadiktok/rabbitmq-elastica-bundle
Composer 安装命令:
composer require vadiktok/rabbitmq-elastica-bundle
包简介
README 文档
README
As you probably know Elastica populate command is very slow and unstable.
This bundle provides simple functionality to populate Elastica indexes using RabbitMQ bundle
General idea was taken from Enqueue Elastica Bundle
Installation
$ composer require vadiktok/rabbitmq-elastica-bundle
- Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:
<?php
// app/AppKernel.php
// ...
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
// ...
new Vadiktok\RabbitMQElasticaBundle\VadiktokRabbitMQElasticaBundle(),
);
// ...
}
}
- Define RabbitMQ producer and consumer in your app/config.yml file:
old_sound_rabbit_mq:
producers:
vadiktok_elastica:
connection: default
exchange_options: { name: elastica, type: direct }
queue_options: { name: elastica }
consumers:
vadiktok_elastica:
connection: default
exchange_options: { name: elastica, type: direct }
queue_options: { name: elastica }
callback: vadiktok.rabbitmq.elastica.consumer
Usage
- Run elastica populate command with --pager-persister option set to "rabbitmq"
$ php bin/console fos:elastica:populate --pager-persister=rabbitmq
Also you might want to use --max-per-page option. By default it is set to 100 and in my case 20k worked perfectly.
This command simply creates MQ messages with number of pages, amount of results and index name/type. Consumer takes care about fetching results and pushing into Elasticsearch server.
One page equals one message in queue. So if you have 1m records and set --max-per-page to 10k -- you will have 100 messages published.
- Consume your messages with
$ php bin/console rabbitmq:consume vadiktok_elastica -vvv
The more consumers you run -- the faster your indexes will be populated. According to my experience reasonable amount of consumers is from 5 to 10.
Also I recommend to use SupervisorD for that.
Configuration
By default bundle will look at vadiktok_elastica producer and publish all messages to it.
But you may also want to modify that name. In this case just add this into your config.yml file:
vadiktok_rabbit_mq_elastica:
producers:
your_producer_id: ~
Or even more. Imagine you want to split your indexes into different queues. All you have to do is define your consumers/producers same that is described in Installation section and then tell the bundle which producer to use:
vadiktok_rabbit_mq_elastica:
producers:
your_producer_id_1: [index_name_1, index_name_2]
your_producer_id_2: [index_name_3, index_name_4]
Now imagine you need your new data first instead of waiting to index data from the first record. All you have to do is to add "order" parameter:
vadiktok_rabbit_mq_elastica:
order: DESC
vadiktok/rabbitmq-elastica-bundle 适用场景与选型建议
vadiktok/rabbitmq-elastica-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.59k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2018 年 03 月 27 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 vadiktok/rabbitmq-elastica-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vadiktok/rabbitmq-elastica-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 2.59k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2018-03-27