Jean Sumara 5 rokov pred
commit
573793b31d
5 zmenil súbory, kde vykonal 1775 pridanie a 0 odobranie
  1. 3 0
      .gitignore
  2. 24 0
      composer.json
  3. 1666 0
      composer.lock
  4. 15 0
      index.php
  5. 67 0
      src/App/Listener/ExportListener.php

+ 3 - 0
.gitignore

@@ -0,0 +1,3 @@
+.idea
+.env
+vendor

+ 24 - 0
composer.json

@@ -0,0 +1,24 @@
+{
+  "name": "export",
+  "description": "Export files from Flowdat",
+  "version": "1.0.0",
+  "authors": [
+    {
+      "name": "Jean Sumara",
+      "email": "jean.sumara@interlink.com.ar"
+    }
+  ],
+  "require": {
+    "vlucas/phpdotenv": "*",
+    "php-amqplib/php-amqplib": ">=2.6.1",
+    "doctrine/orm": "^2.5",
+    "symfony/yaml": "2.*"
+  },
+  "autoload": {
+    "psr-4": {
+      "Flowdat\\Export\\": [
+        "src"
+      ]
+    }
+  }
+}

Rozdielové dáta súboru neboli zobrazené, pretože súbor je príliš veľký
+ 1666 - 0
composer.lock


+ 15 - 0
index.php

@@ -0,0 +1,15 @@
+<?php
+
+use Flowdat\Export\App\Listener\ExportListener;
+
+require __DIR__ . '/vendor/autoload.php';
+
+$dotenv = Dotenv\Dotenv::createImmutable(__DIR__);
+$dotenv->load();
+
+$exportFtthListener = new ExportListener();
+try {
+    $exportFtthListener->run();
+} catch (Exception $e) {
+
+}

+ 67 - 0
src/App/Listener/ExportListener.php

@@ -0,0 +1,67 @@
+<?php
+
+
+namespace Flowdat\Export\App\Listener;
+
+
+use PhpAmqpLib\Connection\AMQPStreamConnection;
+
+class ExportListener
+{
+    private $connectionAMQP;
+    private $channelAMQP;
+    private $nameQueue;
+
+    public function __construct()
+    {
+        $this->connectionAMQP = new AMQPStreamConnection(getenv('HOST_AMQP'), getenv('PORT_AMQP'), getenv('USER_AMQP'), getenv('PASS_AMQP'));
+        $this->channelAMQP = $this->connectionAMQP->channel();
+    }
+
+    /**
+     * @return mixed
+     */
+    public function getNameQueue()
+    {
+        return $this->nameQueue;
+    }
+
+    /**
+     * @param mixed $nameQueue
+     */
+    public function setNameQueue($nameQueue)
+    {
+        $this->nameQueue = $nameQueue;
+    }
+
+    public function run(){
+        echo 'Running listener';
+
+        $envNameQueue = getenv('FTTH_AMQP');
+        if($this->getNameQueue()){
+            $envNameQueue = $this->getNameQueue();
+        }
+        $callbackMessage = function($msg) {
+            $msgBody = unserialize($msg->body);
+
+            var_dump($msgBody);
+        };
+
+        $this->channelAMQP->queue_declare($envNameQueue, false, true ,false, false);
+        $this->channelAMQP->basic_consume($envNameQueue, 'ftth_export', false, true, false, false, $callbackMessage);
+
+        while (count($this->channelAMQP->callbacks)){
+            try {
+                $this->channelAMQP->wait();
+            } catch (\ErrorException $e) {
+                throw new \Exception("We found a some problem when AMQP is awaiting", $e->getMessage());
+            }
+        }
+
+        $this->channelAMQP->close();
+        try {
+            $this->connectionAMQP->close();
+        } catch (\Exception $e) {
+        }
+    }
+}