Browse Source

Merge branch 'topic1' of yanglin/logSystem-advance into master

yanglin 6 years ago
parent
commit
484932e687

+ 6 - 7
backend/controllers/SubscribeController.php

@@ -62,13 +62,13 @@ class SubscribeController extends BaseController
      */
     public function actionDelete()
     {
-        $model = new TopicForm();
-        $model->setScenario('delete_topic');
-        $model->load(['TopicForm' => Yii::$app->request->post()]);
+        $model = new SubscribeForm();
+        $model->setScenario('delete_subscribe');
+        $model->load(['SubscribeForm' => Yii::$app->request->post()]);
 
         $data = [];
         if ($model->validate()) {
-            $data = $model->deleteTopic();
+            $data = $model->Unsubscribe();
         } else {
             $model->handleError();
         }
@@ -86,9 +86,8 @@ class SubscribeController extends BaseController
      */
     public function actionList()
     {
-        $model = new TopicForm();
-        $data = $model->getQueueList();
-
+        $model = new SubscribeForm();
+        $data = $model->getSubscribeList();
         return [
             'code' => 200,
             'message' => Yii::t('error', 200),

+ 1 - 1
backend/controllers/TopicController.php

@@ -86,7 +86,7 @@ class TopicController extends BaseController
     public function actionList()
     {
         $model = new TopicForm();
-        $data = $model->getQueueList();
+        $data = $model->getTopicList();
 
         return [
             'code' => 200,

+ 15 - 17
backend/forms/SubscribeForm.php

@@ -81,9 +81,11 @@ class SubscribeForm extends BaseForm
 		try {
 			$connect = $this->getConnect();
 			$channel = $connect->channel();
-			$channel->exchange_delete($this->name, false, false );
+			$channel->queue_unbind($this->endpoint, $this->topicName, false );
+
+            list($subscriptionName,,) =  $channel->queue_unbind($this->endpoint, $this->topicName,  is_null($this->bindingKey)?'*':$this->bindingKey);
 			return [
-				'name' => $this->name,
+				'name' => $this->endpoint,
 				'result' => '删除成功'
 			];
 
@@ -96,10 +98,10 @@ class SubscribeForm extends BaseForm
 	 * [获取消息列表]
 	 * @author: libingke
 	 */
-	public function getQueueList()
+	public function getSubscribeList()
 	{
 		$authStr = Yii::$app->Amqp->user . ':' . Yii::$app->Amqp->pass;
-		$url = Yii::$app->Amqp->host . ':' . Yii::$app->Amqp->api_port . "/api/queues";
+		$url = Yii::$app->Amqp->host . ':' . Yii::$app->Amqp->api_port . "/api/bindings";
 
 		$curl = new Curl();
 		$curl->setOption(CURLOPT_USERPWD, $authStr);
@@ -115,19 +117,15 @@ class SubscribeForm extends BaseForm
 
 		$rows = [];
 		foreach ($result as $k => $v) {
-			//$name = $v['name'];
-			$name = $v['name'];
-			$rows[$name]['name'] 			= $name;
-			$rows[$name]['messages_count']	= $v['messages'];
-			$rows[$name]['message_bytes']	= $v['message_bytes'];
-			$rows[$name]['messages_ready']	= $v['messages_ready'];
-			//$rows[$name]['message_stats']	= $v['message_stats'];
-			$rows[$name]['consumers_count']	= $v['consumers'];
-			$rows[$name]['auto_delete']		= $v['auto_delete'];
-			$rows[$name]['durable']			= $v['durable'];
-			//$rows[$name]['arguments']		= $v['arguments'];
-			$rows[$name]['state']			= $v['state'];
-			$rows[$name]['idle_since']		= $v['idle_since'];
+		    //destination  exchange
+			$name = $v['destination'];
+			$rows[$name]['destination'] 			= $name;
+			$rows[$name]['source']	= $v['source'];
+            $rows[$name]['topicName']	= $v['source'];
+			$rows[$name]['destination_type']	= $v['destination_type'];
+			$rows[$name]['routing_key']	= $v['routing_key'];
+			$rows[$name]['arguments']	= $v['arguments'];
+			$rows[$name]['properties_key']	= $v['properties_key'];
 		}
 		unset($result);
 

+ 43 - 40
backend/forms/TopicForm.php

@@ -67,45 +67,48 @@ class TopicForm extends BaseForm
 		}
 	}
 
-	/**
-	 * [获取消息列表]
-	 * @author: libingke
-	 */
-	public function getQueueList()
-	{
-		$authStr = Yii::$app->Amqp->user . ':' . Yii::$app->Amqp->pass;
-		$url = Yii::$app->Amqp->host . ':' . Yii::$app->Amqp->api_port . "/api/queues";
-
-		$curl = new Curl();
-		$curl->setOption(CURLOPT_USERPWD, $authStr);
-		$result = json_decode($curl->get($url), true);
-		if ($curl->responseCode != 200)
-			throw new Exception(1002);
-
-		if ($curl->errorText)
-			throw new Exception(1002, $curl->errorText);
-
-		if (isset($result['error']) && is_string($result['error']))
-			throw new Exception(1002, $result['error']);
-
-		$rows = [];
-		foreach ($result as $k => $v) {
-			//$name = $v['name'];
-			$name = $v['name'];
-			$rows[$name]['name'] 			= $name;
-			$rows[$name]['messages_count']	= $v['messages'];
-			$rows[$name]['message_bytes']	= $v['message_bytes'];
-			$rows[$name]['messages_ready']	= $v['messages_ready'];
-			//$rows[$name]['message_stats']	= $v['message_stats'];
-			$rows[$name]['consumers_count']	= $v['consumers'];
-			$rows[$name]['auto_delete']		= $v['auto_delete'];
-			$rows[$name]['durable']			= $v['durable'];
-			//$rows[$name]['arguments']		= $v['arguments'];
-			$rows[$name]['state']			= $v['state'];
-			$rows[$name]['idle_since']		= $v['idle_since'];
-		}
-		unset($result);
 
-		return ['count' => count($rows), 'rows' => $rows];
-	}
+
+    /**
+     * [获取消息列表]
+     * @author: libingke
+     */
+    public function getTopicList()
+    {
+        $authStr = Yii::$app->Amqp->user . ':' . Yii::$app->Amqp->pass;
+        $url = Yii::$app->Amqp->host . ':' . Yii::$app->Amqp->api_port . "/api/exchanges";
+
+        $curl = new Curl();
+        $curl->setOption(CURLOPT_USERPWD, $authStr);
+        $result = json_decode($curl->get($url), true);
+
+
+        if ($curl->responseCode != 200)
+            throw new Exception(1002);
+
+        if ($curl->errorText)
+            throw new Exception(1002, $curl->errorText);
+
+        if (isset($result['error']) && is_string($result['error']))
+            throw new Exception(1002, $result['error']);
+
+        $rows = [];
+        foreach ($result as $k => $v) {
+            if($v['type'] = 'topic'){
+                $name = $v['name'];
+                $rows[$name]['name'] 			= $name;
+                $rows[$name]['auto_delete']		= $v['auto_delete'];
+                $rows[$name]['durable']			= $v['durable'];
+                $rows[$name]['arguments']		= $v['arguments'];
+                $rows[$name]['type']			= $v['type'];
+                $rows[$name]['vhost']		= $v['vhost'];
+            }
+        }
+        unset($result);
+
+        return ['count' => count($rows), 'rows' => $rows];
+    }
+
+
+
 }

+ 4 - 2
common/config/amqp-local.php

@@ -2,8 +2,10 @@
 
 return [
     'class' => 'components\service\Amqp',
-    'host'	=> '192.168.3.10',
-    'port'	=> '5672',
+    //  'host'	=> '192.168.3.10',
+    //  'port'	=> '5672',
+     'host'	=> '139.196.43.170',
+     'port'	=> '5673',
     'user'	=> 'guest',
     'pass'	=> 'Guest',
 ];

+ 4 - 4
common/config/main.php

@@ -25,8 +25,8 @@ return [
             'class' => '\components\components\messageQueue\MessageInterface',
             'key' => 'QkwzrML50o1KIK5bI-HbkVBcTSA_Ehdh',
             'protocol' => 'http',
-//            'host' => '120.78.153.45'
-            'host' => 'ki.logsystemadmin.airent.test.com'
+           'host' => '120.78.153.45'
+            //           'host' => 'ki.logsystemadmin.airent.test.com'
         ],
 
         'cache' => [
@@ -35,10 +35,10 @@ return [
 
         'redis' => [
             'class' => 'yii\redis\Connection',
-            'hostname' => '127.0.0.1',
+            'hostname'	=> '139.196.43.170',
             'port' => 6378,
             'database' => 0,
-            'password' => 'redis12078',
+            'password' => 'airent-redis~123',
         ],
 
 		'i18n' => [

+ 9 - 3
common/config/redis-local.php

@@ -2,8 +2,14 @@
 
 return [
     'class' => 'yii\redis\Connection',
-    'hostname'	=> '192.168.3.10',
-    'port' => 6379,
+
+//    'hostname'	=> '192.168.3.10',
+//    'port' => 6379,
+//    'database' => 0,
+//    'password' => 'redis12078',
+
+    'hostname'	=> '139.196.43.170',
+    'port' => 6378,
     'database' => 0,
-    'password' => 'redis12078',
+    'password' => 'airent-redis~123',
 ];

+ 17 - 12
components/Secret.php

@@ -36,18 +36,21 @@ class Secret extends Component
 		$this->_clientSignature = $clientSignature;
 
 		$cone = $this->findOne($client_id);
-		if (!$cone)
-			static::throwError("client id avail.");
+		if (!$cone){
+            static::throwError("client id avail.");
+        }
 
 		$sKey = isset($cone->client_key) ? $cone->client_key : '';
 
 		$headers = Yii::$app->request->getHeaders();
-		if (!$headers)
-			static::throwError("headers format avail.");
+		if (!$headers){
+            static::throwError("headers format avail.");
+        }
 
 		$strVerb =  strtoupper($headers->get('verb'));
-		if (!$strVerb || !in_array(($strVerb), ['POST', 'GET']))
-			static::throwError("headers verb avail.");
+		if (!$strVerb || !in_array(($strVerb), ['POST', 'GET'])){
+            static::throwError("headers verb avail.");
+        }
 
 		$strMd5 = $headers->get('content-md5');
 		if (!$this->checkContentMd5($strVerb, $strMd5, Yii::$app->request->getBodyParams())){
@@ -66,20 +69,22 @@ class Secret extends Component
         }
 
 		$strSM = $headers->get('signature-method');
-		if (strtoupper($strSM) != strtoupper($this->_signatureMethod))
-			static::throwError("headers signature method avail.");
+		if (strtoupper($strSM) != strtoupper($this->_signatureMethod)){
+            static::throwError("headers signature method avail.");
+        }
 
 		$strSV = $headers->get('signature-version');
-		if ($strSV !== $this->_signatureVersion)
-			static::throwError("headers signature version avail.");
+		if ($strSV !== $this->_signatureVersion){
+            static::throwError("headers signature version avail.");
+        }
 
 		$str = "{$strVerb}\n\n{$strMd5}\n{$strContentType}\n{$strDate}\n{$strSM}\n{$strSV}\n\n{$sKey}\n";
 		$base_sha1 = base64_encode(hash_hmac("sha1", $str, $sKey . '&', true));
 
 		$this->_serverSignature = md5($base_sha1);
-		if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature)
+		if ($this->_serverSignature != '' && $this->_serverSignature !== $this->_clientSignature){
 //			static::throwError("Signature verification failed.");
-
+        }
 		return true;
 	}