Browse Source

add env()

visuddhinanda 2 years ago
parent
commit
2da388ce22
2 changed files with 7 additions and 16 deletions
  1. 5 14
      app/Console/Commands/TestMq.php
  2. 2 2
      app/Console/Commands/TestMqWorker.php

+ 5 - 14
app/Console/Commands/TestMq.php

@@ -3,9 +3,8 @@
 namespace App\Console\Commands;
 
 use Illuminate\Console\Command;
-use PhpAmqpLib\Connection\AMQPStreamConnection;
-use PhpAmqpLib\Message\AMQPMessage;
 
+use App\Http\Api\Mq;
 
 class TestMq extends Command
 {
@@ -14,7 +13,7 @@ class TestMq extends Command
      *
      * @var string
      */
-    protected $signature = 'test:mq ';
+    protected $signature = 'test:mq';
 
     /**
      * The console command description.
@@ -41,23 +40,15 @@ class TestMq extends Command
     public function handle()
     {
         //一对一
-		$connection = new AMQPStreamConnection(MQ_HOST, MQ_PORT, MQ_USERNAME, MQ_PASSWORD);
-		$channel = $connection->channel();
-		$channel->queue_declare('hello', false, true, false, false);
-
-		$msg = new AMQPMessage('Hello World!');
-		$channel->basic_publish($msg, '', 'hello');
-
-		echo " [x] Sent 'Hello World!'\n";
-		$channel->close();
-		$connection->close();
+		Mq::send('hello','ok');
 
         //一对多
+        /*
         $connection = new AMQPStreamConnection(MQ_HOST, MQ_PORT, MQ_USERNAME, MQ_PASSWORD);
         $channel->exchange_declare('hello_exchange','fanout',false,true);
         $channel->queue_declare('hello', false, true, false, false);
         $channel->exchange_bind('hello','exchange',"");
-
+*/
         return 0;
     }
 }

+ 2 - 2
app/Console/Commands/TestMqWorker.php

@@ -39,7 +39,7 @@ class TestMqWorker extends Command
      */
     public function handle()
     {
-		$connection = new AMQPStreamConnection(MQ_HOST, MQ_PORT, MQ_USERNAME, MQ_PASSWORD);
+		$connection = new AMQPStreamConnection(env("MQ_HOST"), env("MQ_PORT"), env("MQ_USERNAME"), env("MQ_PASSWORD"));
 		$channel = $connection->channel();
 
 		$channel->queue_declare('hello', false, true, false, false);
@@ -48,7 +48,7 @@ class TestMqWorker extends Command
 
 		$callback = function ($msg) {
 			echo ' [x] Received ', $msg->body, "\n";
-		  };
+		};
 
 		$channel->basic_consume('hello', '', false, true, false, false, $callback);