Compare commits

...

4 Commits

Author SHA1 Message Date
Matthew Slowe
12e6122706 Fix indentation 2021-01-24 14:37:46 +00:00
0fcf6745f1 allow disable rabbit 2021-01-24 14:32:31 +00:00
6fdf2d2427 be nice and use strict 2021-01-23 16:44:00 +00:00
612526aca8 allow rabbitmq module install to fail, but be ok 2021-01-23 16:43:42 +00:00
2 changed files with 31 additions and 25 deletions

View File

@@ -1,4 +1,6 @@
FROM perl FROM perl
RUN yes | cpan install Net::MQTT::Simple Net::RabbitMQ Net::Stomp RUN yes | cpan install Net::MQTT::Simple || true
RUN yes | cpan install -f Net::RabbitMQ || true
RUN yes | cpan install Net::Stomp || true
COPY bridge.pl /bridge.pl COPY bridge.pl /bridge.pl
ENTRYPOINT ["/bridge.pl"] ENTRYPOINT ["/bridge.pl"]

View File

@@ -1,7 +1,7 @@
#!/usr/bin/perl #!/usr/bin/env perl
# use warnings; # use warnings;
# use strict; use strict;
use Net::Stomp; use Net::Stomp;
use Net::MQTT::Simple; use Net::MQTT::Simple;
@@ -60,7 +60,10 @@ $amq->connect( {
_debug("Connecting to mqtt://$ENV{MQTT_SERVER}"); _debug("Connecting to mqtt://$ENV{MQTT_SERVER}");
my $mqtt = Net::MQTT::Simple->new($ENV{MQTT_SERVER}) or die "Failed to connect to mqtt://$ENV{MQTT_SERVER}"; my $mqtt = Net::MQTT::Simple->new($ENV{MQTT_SERVER}) or die "Failed to connect to mqtt://$ENV{MQTT_SERVER}";
my $rabbit = Net::RabbitMQ->new(); my $rabbit;
my %rabbit_queues;
unless ($ENV{DISABLE_RABBIT}) {
$rabbit = Net::RabbitMQ->new();
_debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}"); _debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}");
$rabbit->connect($ENV{RABBITMQ_SERVER}, $rabbit->connect($ENV{RABBITMQ_SERVER},
{ {
@@ -71,7 +74,7 @@ $rabbit->connect($ENV{RABBITMQ_SERVER},
}); });
_debug("Open rabbitmq channel"); _debug("Open rabbitmq channel");
$rabbit->channel_open(1); $rabbit->channel_open(1);
my %rabbit_queues; }
## Subscribe to ActiveMQ topics ## Subscribe to ActiveMQ topics
foreach my $topic (split (/\s*,\s*/, $ENV{AMQ_TOPICS})) { foreach my $topic (split (/\s*,\s*/, $ENV{AMQ_TOPICS})) {
@@ -99,6 +102,7 @@ while(1) {
_debug("MQTT <- " . $ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination); _debug("MQTT <- " . $ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination);
$mqtt->retain($ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination, $incoming->body); $mqtt->retain($ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination, $incoming->body);
unless($ENV{DISABLE_RABBIT}) {
_debug("RABBIT <- " . $incoming->destination); _debug("RABBIT <- " . $incoming->destination);
unless($rabbit_queues{$incoming_destination}) { unless($rabbit_queues{$incoming_destination}) {
_debug("RABBIT Declaring queue $incoming_destination"); _debug("RABBIT Declaring queue $incoming_destination");
@@ -106,9 +110,9 @@ while(1) {
$rabbit_queues{$incoming_destination}++; $rabbit_queues{$incoming_destination}++;
} }
$rabbit->publish(1, $incoming_destination, $incoming->body); $rabbit->publish(1, $incoming_destination, $incoming->body);
}
$amq->ack({ frame => $incoming }); # $amq->ack({ frame => $incoming });
} }
$mq->disconnect(); $amq->disconnect();