Compare commits

..

3 Commits
V0.1 ... master

Author SHA1 Message Date
Pavel Dmitriev 2c41f45273 Merge pull request 'develop' (#3) from develop into master
continuous-integration/drone/push Build is passing Details
Reviewed-on: #3
2023-01-26 13:09:26 +03:00
Pavel Dmitriev 3ff0c017db added default routing tag
continuous-integration/drone/push Build is failing Details
2023-01-26 13:08:14 +03:00
Pavel Dmitriev d82a8e78dd update readme
continuous-integration/drone/push Build is passing Details
2023-01-22 15:04:19 +03:00
2 changed files with 28 additions and 2 deletions

View File

@ -8,3 +8,21 @@
* RABBITMQ_USER * RABBITMQ_USER
* RABBITMQ_PASSWORD * RABBITMQ_PASSWORD
* RABBITMQ_USE_SSL * 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=/'
```

View File

@ -15,9 +15,8 @@ $rabbitLogin=getenv("RABBITMQ_USER");
$rabbitPass=getenv("RABBITMQ_PASSWORD"); $rabbitPass=getenv("RABBITMQ_PASSWORD");
$rabbitUseSSL=getenv("RABBITMQ_USE_SSL")==="true"; $rabbitUseSSL=getenv("RABBITMQ_USE_SSL")==="true";
$rabbitVirtualHost=getenv("RABBITMQ_VIRTUAL_HOST")?getenv("RABBITMQ_VIRTUAL_HOST"):"/"; $rabbitVirtualHost=getenv("RABBITMQ_VIRTUAL_HOST")?getenv("RABBITMQ_VIRTUAL_HOST"):"/";
$routingTag=getenv("DEFAULT_TAG")?getenv("DEFAULT_TAG"):null;
$routingTag=null;
$connection=null; $connection=null;
$channel=null; $channel=null;
@ -54,6 +53,14 @@ function rabbitConnect($rabbitHost, $rabbitPort, $rabbitLogin, $rabbitPass, $rab
return $connection; 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) { function scanner($channel, $port) {
global $routingTag; global $routingTag;
@ -68,6 +75,7 @@ function scanner($channel, $port) {
} }
} }
while (1) { while (1) {
$buffer = fgets($fp, 4096); $buffer = fgets($fp, 4096);
$rv=explode("\n", $buffer); $rv=explode("\n", $buffer);