|
|
@@ -3,20 +3,6 @@
|
|
|
* 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' => [
|
|
|
[
|
|
|
@@ -27,43 +13,26 @@ $rabbitMQ = [
|
|
|
'vhost' => '/', //虚拟主机
|
|
|
]
|
|
|
],
|
|
|
-
|
|
|
/**
|
|
|
* 交换器
|
|
|
- * 交换类型(type):direct、topic、headers、fanout
|
|
|
- * 列出交换器: rabbitmqctl list_exchanges
|
|
|
*/
|
|
|
'exchanges' => [
|
|
|
[
|
|
|
- 'name' => 'commonExchange',
|
|
|
- 'type' => 'direct'
|
|
|
+ 'name' => 'customExchange',
|
|
|
+ 'type' => 'direct',
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'informExchange',
|
|
|
- 'type' => 'direct'
|
|
|
+ 'name' => 'stockExchange',
|
|
|
+ 'type' => 'direct',
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'openShopInitExchange',
|
|
|
- 'type' => 'direct'
|
|
|
+ 'name' => 'notifyExchange',
|
|
|
+ 'type' => 'direct',
|
|
|
],
|
|
|
[
|
|
|
'name' => 'ex1',
|
|
|
'type' => '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,
|
|
|
- ],
|
|
|
- */
|
|
|
+ ]
|
|
|
],
|
|
|
|
|
|
/**
|
|
|
@@ -75,41 +44,17 @@ $rabbitMQ = [
|
|
|
'passive' => false,
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'queueCommon',
|
|
|
+ 'name' => 'customQueue',
|
|
|
'passive' => false,
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'informQueue',
|
|
|
+ 'name' => 'stockQueue',
|
|
|
'passive' => false,
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'openShopInitQueue',
|
|
|
+ 'name' => 'notifyQueue',
|
|
|
'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,
|
|
|
- ],
|
|
|
- */
|
|
|
],
|
|
|
|
|
|
/**
|
|
|
@@ -118,37 +63,25 @@ $rabbitMQ = [
|
|
|
*/
|
|
|
'bindings' => [
|
|
|
[
|
|
|
- 'queue' => 'queueCommon',
|
|
|
- 'exchange' => 'commonExchange',
|
|
|
- 'routing_keys' => ['commonRoute'],
|
|
|
+ 'queue' => 'customQueue',
|
|
|
+ 'exchange' => 'customExchange',
|
|
|
+ 'routing_keys' => ['customRoute'],
|
|
|
],
|
|
|
[
|
|
|
- 'queue' => 'informQueue',
|
|
|
- 'exchange' => 'informExchange',
|
|
|
- 'routing_keys' => ['informRoute'],
|
|
|
+ 'queue' => 'stockQueue',
|
|
|
+ 'exchange' => 'stockExchange',
|
|
|
+ 'routing_keys' => ['stockRoute'],
|
|
|
],
|
|
|
[
|
|
|
- 'queue' => 'openShopInitQueue',
|
|
|
- 'exchange' => 'openShopInitExchange',
|
|
|
- 'routing_keys' => ['openShopInitRoute'],
|
|
|
+ 'queue' => 'notifyQueue',
|
|
|
+ 'exchange' => 'notifyExchange',
|
|
|
+ 'routing_keys' => ['notifyRoute'],
|
|
|
],
|
|
|
[
|
|
|
'queue' => 'queues1',
|
|
|
'exchange' => 'ex1',
|
|
|
'routing_keys' => ['route1'],
|
|
|
],
|
|
|
- /*
|
|
|
- [
|
|
|
- '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'],
|
|
|
- ],
|
|
|
- */
|
|
|
],
|
|
|
|
|
|
/**
|
|
|
@@ -156,30 +89,20 @@ $rabbitMQ = [
|
|
|
*/
|
|
|
'producers' => [
|
|
|
[
|
|
|
- //通用生产者
|
|
|
- 'name' => 'commonProducer',
|
|
|
+ //客户操作生产者
|
|
|
+ 'name' => 'customProducer',
|
|
|
],
|
|
|
[
|
|
|
- //通知生产者
|
|
|
- 'name' => 'informProducer',
|
|
|
+ //库存管理生产者
|
|
|
+ 'name' => 'stockProducer',
|
|
|
],
|
|
|
[
|
|
|
//通知生产者
|
|
|
- 'name' => 'openShopInitProducer',
|
|
|
+ 'name' => 'notifyProducer',
|
|
|
],
|
|
|
[
|
|
|
'name' => 'producers',
|
|
|
- ],
|
|
|
- /*
|
|
|
- [
|
|
|
- 'name' => 'producer_2',
|
|
|
- 'connection' => 'default',
|
|
|
- 'safe' => true,
|
|
|
- 'content_type' => 'text/plain',
|
|
|
- 'delivery_mode' => 2,
|
|
|
- 'serializer' => 'serialize',
|
|
|
]
|
|
|
- */
|
|
|
],
|
|
|
|
|
|
/**
|
|
|
@@ -187,51 +110,32 @@ $rabbitMQ = [
|
|
|
*/
|
|
|
'consumers' => [
|
|
|
[
|
|
|
- //常规消费者
|
|
|
- 'name' => 'commonConsumer',
|
|
|
+ //客户操作消费者
|
|
|
+ 'name' => 'customConsumer',
|
|
|
'callbacks' => [
|
|
|
- 'queueCommon' => '\common\components\rabbitmq\consumer\commonConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
- ],
|
|
|
+ 'customQueue' => '\common\components\rabbitmq\consumer\customConsumer',
|
|
|
+ ]
|
|
|
],
|
|
|
[
|
|
|
- //通知
|
|
|
- 'name' => 'informConsumer',
|
|
|
+ //库存管理消费者
|
|
|
+ 'name' => 'stockConsumer',
|
|
|
'callbacks' => [
|
|
|
- 'informQueue' => '\common\components\rabbitmq\consumer\informConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
- ],
|
|
|
+ 'stockQueue' => '\common\components\rabbitmq\consumer\stockConsumer',
|
|
|
+ ]
|
|
|
],
|
|
|
[
|
|
|
- //授权公众号开店初始化
|
|
|
- 'name' => 'openShopInitConsumer',
|
|
|
+ //通知消费者
|
|
|
+ 'name' => 'notifyConsumer',
|
|
|
'callbacks' => [
|
|
|
- 'openShopInitQueue' => '\common\components\rabbitmq\consumer\openShopInitConsumer', //设定队列的数据给谁转回调而以,只是个配置
|
|
|
- ],
|
|
|
+ 'notifyQueue' => '\common\components\rabbitmq\consumer\notifyConsumer',
|
|
|
+ ]
|
|
|
],
|
|
|
[
|
|
|
- 'name' => 'importdataconsumer',
|
|
|
+ 'name' => 'importDataConsumer',
|
|
|
'callbacks' => [
|
|
|
'queues1' => '\common\components\rabbitmq\consumer\importDataConsumer',
|
|
|
],
|
|
|
- ],
|
|
|
- /*
|
|
|
- [
|
|
|
- 'name' => 'consumer_2',
|
|
|
- 'connection' => 'default',
|
|
|
- 'callbacks' => [
|
|
|
- 'queue_2' => '\common\components\rabbitmq\consumer\PrintMsgConsumer',
|
|
|
- ],
|
|
|
- 'qos' => [
|
|
|
- 'prefetch_size' => 0,
|
|
|
- 'prefetch_count' => 0,
|
|
|
- 'global' => false,
|
|
|
- ],
|
|
|
- 'idle_timeout' => 0,
|
|
|
- 'idle_timeout_exit_code' => null,
|
|
|
- 'proceed_on_exception' => false,
|
|
|
- 'deserializer' => 'unserialize',
|
|
|
- ],
|
|
|
- */
|
|
|
+ ]
|
|
|
],
|
|
|
];
|
|
|
-
|
|
|
return $rabbitMQ;
|