|
|
@@ -2,138 +2,172 @@
|
|
|
/**
|
|
|
* rabbitmq的配置
|
|
|
*/
|
|
|
-
|
|
|
$rabbitmq = [
|
|
|
- /*'on before_consume' => function ($event) {
|
|
|
- if (isset(\Yii::$app->db)) {
|
|
|
- $db = \Yii::$app->db;
|
|
|
- if ($db->getIsActive()) {
|
|
|
- $db->close();
|
|
|
- }
|
|
|
- $db->open();
|
|
|
- }
|
|
|
- },
|
|
|
- 'logger' => [
|
|
|
- 'enable' => true,
|
|
|
- 'category' => 'amqp',
|
|
|
- 'print_console' => true,
|
|
|
- ],*/
|
|
|
- 'class' => 'mikemadisonweb\rabbitmq\Configuration',
|
|
|
- 'connections' => [
|
|
|
- [
|
|
|
- 'host' => '127.0.0.1',
|
|
|
- 'port' => '5672',
|
|
|
- 'user' => 'guest',
|
|
|
- 'password' => 'guest',
|
|
|
- 'vhost' => '/', //虚拟主机
|
|
|
- ]
|
|
|
- ],
|
|
|
-
|
|
|
- /**
|
|
|
- * 交换器
|
|
|
- * 交换类型(type):direct、topic、headers、fanout
|
|
|
- * 列出交换器: rabbitmqctl list_exchanges
|
|
|
- */
|
|
|
- 'exchanges' => [
|
|
|
- [
|
|
|
- 'name' => 'ex_1',
|
|
|
- 'type' => 'direct' // direct
|
|
|
- ],
|
|
|
- [
|
|
|
- 'name' => 'topic_ex_1',
|
|
|
- 'type' => 'topic', // topic
|
|
|
- 'passive' => false,
|
|
|
- 'durable' => true,
|
|
|
- 'auto_delete' => false,
|
|
|
- 'internal' => false,
|
|
|
- 'nowait' => false,
|
|
|
- 'arguments' => null,
|
|
|
- 'ticket' => null,
|
|
|
- 'declare' => true,
|
|
|
- ],
|
|
|
- ],
|
|
|
-
|
|
|
- /**
|
|
|
- * 队列
|
|
|
- */
|
|
|
- 'queues' => [
|
|
|
- [
|
|
|
- 'name' => 'queue_1',
|
|
|
- 'passive' => false,
|
|
|
- ],
|
|
|
- [
|
|
|
- 'name' => 'queue_2',
|
|
|
- 'passive' => false,
|
|
|
- 'durable' => true,
|
|
|
- 'exclusive' => false,
|
|
|
- 'auto_delete' => false,
|
|
|
- 'nowait' => false,
|
|
|
- 'arguments' => null,
|
|
|
- 'ticket' => null,
|
|
|
- 'declare' => true,
|
|
|
- ],
|
|
|
- [
|
|
|
- 'name' => 'queue_3',
|
|
|
- 'passive' => false,
|
|
|
- 'durable' => true,
|
|
|
- 'exclusive' => false,
|
|
|
- 'auto_delete' => false,
|
|
|
- 'nowait' => false,
|
|
|
- 'arguments' => null,
|
|
|
- 'ticket' => null,
|
|
|
- 'declare' => true,
|
|
|
- ],
|
|
|
- ],
|
|
|
-
|
|
|
- /**
|
|
|
- * 交换和队列之间的关系称为绑定
|
|
|
- * 列出绑定: rabbitmqctl list_bindings
|
|
|
- */
|
|
|
- 'bindings' => [
|
|
|
- [
|
|
|
- 'queue' => 'queue_1',
|
|
|
- 'exchange' => 'ex_1',
|
|
|
- 'routing_keys' => ['route_1'],
|
|
|
- ],
|
|
|
- [
|
|
|
- 'queue' => 'queue_2',
|
|
|
- 'exchange' => 'topic_ex_1',
|
|
|
- 'routing_keys' => ['route_1', 'route_prefix.*', '*.route_suffix', '*.*.last', '*'],
|
|
|
- ],
|
|
|
- [
|
|
|
- 'queue' => 'queue_3',
|
|
|
- 'exchange' => 'topic_ex_1',
|
|
|
- 'routing_keys' => ['route_3', 'route3_prefix.*', '*.route_suffix', '*.*.last'],
|
|
|
- ],
|
|
|
- ],
|
|
|
-
|
|
|
- /**
|
|
|
- * 生产者
|
|
|
- */
|
|
|
- 'producers' => [
|
|
|
- [
|
|
|
- 'name' => 'producer_1',
|
|
|
- ],
|
|
|
- [
|
|
|
- 'name' => 'producer_2',
|
|
|
- 'connection' => 'default',
|
|
|
- 'safe' => true,
|
|
|
- 'content_type' => 'text/plain',
|
|
|
- 'delivery_mode' => 2,
|
|
|
- 'serializer' => 'serialize',
|
|
|
- ]
|
|
|
- ],
|
|
|
-
|
|
|
- /**
|
|
|
- * 消费者
|
|
|
- */
|
|
|
- 'consumers' => [
|
|
|
- [
|
|
|
- 'name' => 'consumer_1',
|
|
|
- 'callbacks' => [
|
|
|
- 'queue_1' => '\common\components\rabbitmq\consumer\ImportDataConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
- ],
|
|
|
- ],
|
|
|
+ /*'on before_consume' => function ($event) {
|
|
|
+ if (isset(\Yii::$app->db)) {
|
|
|
+ $db = \Yii::$app->db;
|
|
|
+ if ($db->getIsActive()) {
|
|
|
+ $db->close();
|
|
|
+ }
|
|
|
+ $db->open();
|
|
|
+ }
|
|
|
+ },
|
|
|
+ 'logger' => [
|
|
|
+ 'enable' => true,
|
|
|
+ 'category' => 'amqp',
|
|
|
+ 'print_console' => true,
|
|
|
+ ],*/
|
|
|
+ 'class' => 'mikemadisonweb\rabbitmq\Configuration',
|
|
|
+ 'connections' => [
|
|
|
+ [
|
|
|
+ 'host' => '127.0.0.1',
|
|
|
+ 'port' => '5672',
|
|
|
+ 'user' => 'guest',
|
|
|
+ 'password' => 'guest',
|
|
|
+ 'vhost' => '/', //虚拟主机
|
|
|
+ ]
|
|
|
+ ],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 交换器
|
|
|
+ * 交换类型(type):direct、topic、headers、fanout
|
|
|
+ * 列出交换器: rabbitmqctl list_exchanges
|
|
|
+ */
|
|
|
+ 'exchanges' => [
|
|
|
+ [
|
|
|
+ 'name' => 'exCommon',
|
|
|
+ 'type' => 'direct' // direct
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => 'exInform',
|
|
|
+ 'type' => 'direct' // direct
|
|
|
+ ],
|
|
|
+ /*
|
|
|
+ [
|
|
|
+ 'name' => 'topic_ex_1',
|
|
|
+ 'type' => 'topic', // topic
|
|
|
+ 'passive' => false,
|
|
|
+ 'durable' => true,
|
|
|
+ 'auto_delete' => false,
|
|
|
+ 'internal' => false,
|
|
|
+ 'nowait' => false,
|
|
|
+ 'arguments' => null,
|
|
|
+ 'ticket' => null,
|
|
|
+ 'declare' => true,
|
|
|
+ ],
|
|
|
+ */
|
|
|
+ ],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 队列
|
|
|
+ */
|
|
|
+ 'queues' => [
|
|
|
+ [
|
|
|
+ 'name' => 'queueCommon',
|
|
|
+ 'passive' => false,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => 'queueInform',
|
|
|
+ 'passive' => false,
|
|
|
+ ],
|
|
|
+ /*
|
|
|
+ [
|
|
|
+ 'name' => 'queue_2',
|
|
|
+ 'passive' => false,
|
|
|
+ 'durable' => true,
|
|
|
+ 'exclusive' => false,
|
|
|
+ 'auto_delete' => false,
|
|
|
+ 'nowait' => false,
|
|
|
+ 'arguments' => null,
|
|
|
+ 'ticket' => null,
|
|
|
+ 'declare' => true,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'name' => 'queue_3',
|
|
|
+ 'passive' => false,
|
|
|
+ 'durable' => true,
|
|
|
+ 'exclusive' => false,
|
|
|
+ 'auto_delete' => false,
|
|
|
+ 'nowait' => false,
|
|
|
+ 'arguments' => null,
|
|
|
+ 'ticket' => null,
|
|
|
+ 'declare' => true,
|
|
|
+ ],
|
|
|
+ */
|
|
|
+ ],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 交换和队列之间的关系称为绑定
|
|
|
+ * 列出绑定: rabbitmqctl list_bindings
|
|
|
+ */
|
|
|
+ 'bindings' => [
|
|
|
+ [
|
|
|
+ 'queue' => 'queueCommon',
|
|
|
+ 'exchange' => 'exCommon',
|
|
|
+ 'routing_keys' => ['routeCommon'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'queue' => 'queueInform',
|
|
|
+ 'exchange' => 'exInform',
|
|
|
+ 'routing_keys' => ['routeInform'],
|
|
|
+ ],
|
|
|
+ /*
|
|
|
+ [
|
|
|
+ 'queue' => 'queue_2',
|
|
|
+ 'exchange' => 'topic_ex_1',
|
|
|
+ 'routing_keys' => ['route_1', 'route_prefix.*', '*.route_suffix', '*.*.last', '*'],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 'queue' => 'queue_3',
|
|
|
+ 'exchange' => 'topic_ex_1',
|
|
|
+ 'routing_keys' => ['route_3', 'route3_prefix.*', '*.route_suffix', '*.*.last'],
|
|
|
+ ],
|
|
|
+ */
|
|
|
+ ],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 生产者
|
|
|
+ */
|
|
|
+ 'producers' => [
|
|
|
+ [
|
|
|
+ //常规生产者
|
|
|
+ 'name' => 'producerCommon',
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ //通知模块生产者
|
|
|
+ 'name' => 'producerInform',
|
|
|
+ ],
|
|
|
+ /*
|
|
|
+ [
|
|
|
+ 'name' => 'producer_2',
|
|
|
+ 'connection' => 'default',
|
|
|
+ 'safe' => true,
|
|
|
+ 'content_type' => 'text/plain',
|
|
|
+ 'delivery_mode' => 2,
|
|
|
+ 'serializer' => 'serialize',
|
|
|
+ ]
|
|
|
+ */
|
|
|
+ ],
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 消费者
|
|
|
+ */
|
|
|
+ 'consumers' => [
|
|
|
+ [
|
|
|
+ //常规消费者
|
|
|
+ 'name' => 'consumerCommon',
|
|
|
+ 'callbacks' => [
|
|
|
+ 'queueCommon' => '\common\components\rabbitmq\consumer\ImportDataConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ //通知模块消费者
|
|
|
+ 'name' => 'consumerInform',
|
|
|
+ 'callbacks' => [
|
|
|
+ 'queueInform' => '\common\components\rabbitmq\consumer\ImportDataConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
+ ],
|
|
|
+ ],
|
|
|
+ /*
|
|
|
[
|
|
|
'name' => 'consumer_2',
|
|
|
'connection' => 'default',
|
|
|
@@ -150,7 +184,8 @@ $rabbitmq = [
|
|
|
'proceed_on_exception' => false,
|
|
|
'deserializer' => 'unserialize',
|
|
|
],
|
|
|
- ],
|
|
|
+ */
|
|
|
+ ],
|
|
|
];
|
|
|
|
|
|
return $rabbitmq;
|