allow disable rabbit

This commit is contained in:
Matthew Slowe 2021-01-24 14:32:31 +00:00
parent 6fdf2d2427
commit 0fcf6745f1

View File

@ -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,8 +110,8 @@ 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 });
} }