Jelajahi Sumber

开店初始化

shish 6 tahun lalu
induk
melakukan
9e78c4a6f3

+ 1 - 1
common/components/rabbitmq/consumer/CommonConsumer.php → common/components/rabbitmq/consumer/commonConsumer.php

@@ -11,7 +11,7 @@ namespace common\components\rabbitmq\consumer;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 
-class CommonConsumer implements ConsumerInterface
+class commonConsumer implements ConsumerInterface
 {
 	/**
 	 * @param AMQPMessage $msg

+ 1 - 1
common/components/rabbitmq/consumer/ImportDataConsumer.php → common/components/rabbitmq/consumer/importDataConsumer.php

@@ -11,7 +11,7 @@ namespace common\components\rabbitmq\consumer;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 
-class ImportDataConsumer implements ConsumerInterface
+class importDataConsumer implements ConsumerInterface
 {
 
 	/**

+ 1 - 1
common/components/rabbitmq/consumer/InformConsumer.php → common/components/rabbitmq/consumer/informConsumer.php

@@ -13,7 +13,7 @@ use biz\message\services\InformUserService;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 
-class InformConsumer implements ConsumerInterface
+class informConsumer implements ConsumerInterface
 {
 	
 	/**

+ 45 - 0
common/components/rabbitmq/consumer/openShopInitConsumer.php

@@ -0,0 +1,45 @@
+<?php
+/**
+ * 通知的消费者
+ * User: shish <shish@zhhinc.com>
+ * Date: 2019/9/9 0009
+ * Time: 14:54
+ */
+
+namespace common\components\rabbitmq\consumer;
+
+use biz\message\services\InformAdminService;
+use biz\message\services\InformUserService;
+use mikemadisonweb\rabbitmq\components\ConsumerInterface;
+use PhpAmqpLib\Message\AMQPMessage;
+
+class openShopInitConsumer implements ConsumerInterface
+{
+	
+	/**
+	 * ConsumerInterface::MSG_ACK - Acknowledge message (mark as processed) and drop it from the queue
+	 * ConsumerInterface::MSG_REJECT - Reject and drop message from the queue
+	 * ConsumerInterface::MSG_REQUEUE - Reject and requeue message in RabbitMQ
+	 */
+	public function execute(AMQPMessage $msg)
+	{
+		$data = unserialize($msg->body);
+		print_r($data);
+//		return ConsumerInterface::MSG_ACK;
+		$userType = $data['userType'];
+		if ($userType == 'user') {
+			$return = InformUserService::consumeInformQueue($data);
+			if ($return) {
+				return ConsumerInterface::MSG_ACK;
+			}
+		}
+		if ($userType == 'admin') {
+			$return = InformAdminService::consumeInformQueue($data);
+			if ($return) {
+				return ConsumerInterface::MSG_ACK;
+			}
+		}
+		return ConsumerInterface::MSG_REQUEUE;
+	}
+	
+}

+ 1 - 1
common/components/rabbitmq/consumer/PrintMsgConsumer.php → common/components/rabbitmq/consumer/printMsgConsumer.php

@@ -11,7 +11,7 @@ namespace common\components\rabbitmq\consumer;
 use mikemadisonweb\rabbitmq\components\ConsumerInterface;
 use PhpAmqpLib\Message\AMQPMessage;
 
-class PrintMsgConsumer implements ConsumerInterface
+class printMsgConsumer implements ConsumerInterface
 {
 	/**
 	 * @param AMQPMessage $msg

+ 43 - 19
common/config/rabbitMQ.php

@@ -35,12 +35,16 @@ $rabbitMQ = [
 	 */
 	'exchanges' => [
 		[
-			'name' => 'exCommon',
-			'type' => 'direct' // direct
+			'name' => 'commonExchange',
+			'type' => 'direct'
 		],
 		[
-			'name' => 'exInform',
-			'type' => 'direct' // direct
+			'name' => 'informExchange',
+			'type' => 'direct'
+		],
+		[
+			'name' => 'openShopInitExchange',
+			'type' => 'direct'
 		],
 		/*
 		[
@@ -67,7 +71,11 @@ $rabbitMQ = [
 			'passive' => false,
 		],
 		[
-			'name' => 'queueInform',
+			'name' => 'informQueue',
+			'passive' => false,
+		],
+		[
+			'name' => 'openShopInitQueue',
 			'passive' => false,
 		],
 		/*
@@ -103,13 +111,18 @@ $rabbitMQ = [
 	'bindings' => [
 		[
 			'queue' => 'queueCommon',
-			'exchange' => 'exCommon',
-			'routing_keys' => ['routeCommon'],
+			'exchange' => 'commonExchange',
+			'routing_keys' => ['commonRoute'],
+		],
+		[
+			'queue' => 'informQueue',
+			'exchange' => 'informExchange',
+			'routing_keys' => ['informRoute'],
 		],
 		[
-			'queue' => 'queueInform',
-			'exchange' => 'exInform',
-			'routing_keys' => ['routeInform'],
+			'queue' => 'openShopInitQueue',
+			'exchange' => 'openShopInitExchange',
+			'routing_keys' => ['openShopInitRoute'],
 		],
 		/*
 		[
@@ -130,12 +143,16 @@ $rabbitMQ = [
 	 */
 	'producers' => [
 		[
-			//常规生产者
-			'name' => 'producerCommon',
+			//通用生产者
+			'name' => 'commonProducer',
 		],
 		[
-			//通知模块生产者
-			'name' => 'producerInform',
+			//通知生产者
+			'name' => 'informProducer',
+		],
+		[
+			//通知生产者
+			'name' => 'openShopInitProducer',
 		],
 		/*
 		[
@@ -155,16 +172,23 @@ $rabbitMQ = [
 	'consumers' => [
 		[
 			//常规消费者
-			'name' => 'consumerCommon',
+			'name' => 'commonConsumer',
+			'callbacks' => [
+				'queueCommon' => '\common\components\rabbitmq\consumer\commonConsumer', //设定队列的数据给谁转回调而以,只是个配置
+			],
+		],
+		[
+			//通知
+			'name' => 'informConsumer',
 			'callbacks' => [
-				'queueCommon' => '\common\components\rabbitmq\consumer\ImportDataConsumer', //设定队列的数据给谁转回调而以,只是个配置
+				'informQueue' => '\common\components\rabbitmq\consumer\informConsumer', //设定队列的数据给谁转回调而以,只是个配置
 			],
 		],
 		[
-			//通知模块消费者
-			'name' => 'consumerInform',
+			//授权公众号开店初始化
+			'name' => 'openShopInitConsumer',
 			'callbacks' => [
-				'queueInform' => '\common\components\rabbitmq\consumer\InformConsumer', //设定队列的数据给谁转回调而以,只是个配置
+				'informQueue' => '\common\components\rabbitmq\consumer\openShopInitConsumer', //设定队列的数据给谁转回调而以,只是个配置
 			],
 		],
 		/*