From d82a8e78dd46bf716571b20506586186c812ab9e Mon Sep 17 00:00:00 2001 From: Pavel Dmitriev Date: Sun, 22 Jan 2023 15:04:19 +0300 Subject: [PATCH 1/2] update readme --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index f85c756..c14cc0c 100644 --- a/README.md +++ b/README.md @@ -8,3 +8,21 @@ * RABBITMQ_USER * RABBITMQ_PASSWORD * RABBITMQ_USE_SSL + +## docker-compose sample +``` +version: "2" + +services: + barcode-scanner: + image: mxfox.ru/mxfox/barcode-scanner-client:latest + devices: + - "/dev/ttyACM0:/dev/ttyACM0" + environment: + - 'SCANNER_PORT=/dev/ttyACM0' + - 'RABBITMQ_HOST=rabbitmq' + - 'RABBITMQ_USER=user' + - 'RABBITMQ_PASSWORD=pass' + - 'RABBITMQ_USE_SSL=false' + - 'RABBITMQ_VIRTUAL_HOST=/' +``` \ No newline at end of file -- 2.40.1 From 3ff0c017db5a0cdc98da0e4671564c31443f37e6 Mon Sep 17 00:00:00 2001 From: Pavel Dmitriev Date: Thu, 26 Jan 2023 13:08:14 +0300 Subject: [PATCH 2/2] added default routing tag --- barcodeScanner.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/barcodeScanner.php b/barcodeScanner.php index af8b168..43330f3 100644 --- a/barcodeScanner.php +++ b/barcodeScanner.php @@ -15,9 +15,8 @@ $rabbitLogin=getenv("RABBITMQ_USER"); $rabbitPass=getenv("RABBITMQ_PASSWORD"); $rabbitUseSSL=getenv("RABBITMQ_USE_SSL")==="true"; $rabbitVirtualHost=getenv("RABBITMQ_VIRTUAL_HOST")?getenv("RABBITMQ_VIRTUAL_HOST"):"/"; +$routingTag=getenv("DEFAULT_TAG")?getenv("DEFAULT_TAG"):null; - -$routingTag=null; $connection=null; $channel=null; @@ -54,6 +53,14 @@ function rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rab return $connection; } +function register($channel, $routingTag) { + print "Register\n"; + if (!empty($routingTag)) { + $msg = new AMQPMessage(json_encode(["type"=>"service","data"=>"register"])); + $channel->basic_publish($msg, 'fox.barcode', $routingTag); + } +} + function scanner($channel, $port) { global $routingTag; @@ -68,6 +75,7 @@ function scanner($channel, $port) { } } + while (1) { $buffer = fgets($fp, 4096); $rv=explode("\n", $buffer); -- 2.40.1