shish 8 mesi fa
parent
commit
e091965dfa

+ 3 - 8
app-ghs/controllers/TestController.php

@@ -45,14 +45,9 @@ class TestController extends BaseController
 
     public function actionRabbit()
     {
-        try{
-            GhsNotifyClass::newOrderNotify(3414434);
-            HdNotifyClass::newCgNotify(3456923);
-        }catch (\Exception $e){
-            $msg = $e->getMessage();
-            noticeUtil::push($msg, '15280215347');
-        }
-        echo '执行到了结束';
+        $producer = Yii::$app->rabbitmq->getProducer('stockProducer');
+        $msg = serialize(['type' => 'add', 'name' => 'shish']);
+        $producer->publish($msg, 'stockExchange', 'stockRoute');
     }
 
     public function actionFx()

+ 2 - 0
common/components/rabbitmq/stockConsumer.php

@@ -38,6 +38,8 @@ class stockConsumer implements ConsumerInterface
             switch ($type) {
                 case 'add':
                     $result = true;
+                    echo '持久化OK---';
+                    print_r($data);
                     break;
                 default:
                     noticeUtil::push("库存的消费者报错,未知 type: {$type}");

+ 3 - 23
common/config/rabbitMQ.php

@@ -24,14 +24,11 @@ $rabbitMQ = [
         [
             'name' => 'stockExchange',
             'type' => 'direct',
+            'durable' => true,
         ],
         [
             'name' => 'notifyExchange',
             'type' => 'direct',
-        ],
-        [
-            'name' => 'ex1',
-            'type' => 'direct'
         ]
     ],
 
@@ -39,10 +36,6 @@ $rabbitMQ = [
      * 队列
      */
     'queues' => [
-        [
-            'name' => 'queues1',
-            'passive' => false,
-        ],
         [
             'name' => 'customQueue',
             'passive' => false,
@@ -50,6 +43,7 @@ $rabbitMQ = [
         [
             'name' => 'stockQueue',
             'passive' => false,
+            'durable' => true,
         ],
         [
             'name' => 'notifyQueue',
@@ -76,12 +70,7 @@ $rabbitMQ = [
             'queue' => 'notifyQueue',
             'exchange' => 'notifyExchange',
             'routing_keys' => ['notifyRoute'],
-        ],
-        [
-            'queue' => 'queues1',
-            'exchange' => 'ex1',
-            'routing_keys' => ['route1'],
-        ],
+        ]
     ],
 
     /**
@@ -99,9 +88,6 @@ $rabbitMQ = [
         [
             //通知生产者
             'name' => 'notifyProducer',
-        ],
-        [
-            'name' => 'importDataProducer',
         ]
     ],
 
@@ -129,12 +115,6 @@ $rabbitMQ = [
             'callbacks' => [
                 'notifyQueue' => '\common\components\rabbitmq\notifyConsumer',
             ]
-        ],
-        [
-            'name' => 'importDataConsumer',
-            'callbacks' => [
-                'queues1' => '\common\components\rabbitmq\importDataConsumer',
-            ],
         ]
     ],
 ];