allow disable rabbit
This commit is contained in:
parent
6fdf2d2427
commit
0fcf6745f1
44
bridge.pl
44
bridge.pl
@ -60,18 +60,21 @@ $amq->connect( {
|
||||
_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 $rabbit = Net::RabbitMQ->new();
|
||||
_debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}");
|
||||
$rabbit->connect($ENV{RABBITMQ_SERVER},
|
||||
{
|
||||
user => $ENV{RABBITMQ_USER},
|
||||
password => $ENV{RABBITMQ_PASSWORD},
|
||||
vhost => $ENV{RABBITMQ_VHOST},
|
||||
channel_max => 64,
|
||||
});
|
||||
_debug("Open rabbitmq channel");
|
||||
$rabbit->channel_open(1);
|
||||
my $rabbit;
|
||||
my %rabbit_queues;
|
||||
unless ($ENV{DISABLE_RABBIT}) {
|
||||
$rabbit = Net::RabbitMQ->new();
|
||||
_debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}");
|
||||
$rabbit->connect($ENV{RABBITMQ_SERVER},
|
||||
{
|
||||
user => $ENV{RABBITMQ_USER},
|
||||
password => $ENV{RABBITMQ_PASSWORD},
|
||||
vhost => $ENV{RABBITMQ_VHOST},
|
||||
channel_max => 64,
|
||||
});
|
||||
_debug("Open rabbitmq channel");
|
||||
$rabbit->channel_open(1);
|
||||
}
|
||||
|
||||
## Subscribe to ActiveMQ topics
|
||||
foreach my $topic (split (/\s*,\s*/, $ENV{AMQ_TOPICS})) {
|
||||
@ -99,15 +102,16 @@ while(1) {
|
||||
_debug("MQTT <- " . $ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination);
|
||||
$mqtt->retain($ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination, $incoming->body);
|
||||
|
||||
_debug("RABBIT <- " . $incoming->destination);
|
||||
unless($rabbit_queues{$incoming_destination}) {
|
||||
_debug("RABBIT Declaring queue $incoming_destination");
|
||||
$rabbit->queue_declare(1, $incoming_destination, { durable => 1 });
|
||||
$rabbit_queues{$incoming_destination}++;
|
||||
}
|
||||
$rabbit->publish(1, $incoming_destination, $incoming->body);
|
||||
|
||||
$amq->ack({ frame => $incoming });
|
||||
unless($ENV{DISABLE_RABBIT}) {
|
||||
_debug("RABBIT <- " . $incoming->destination);
|
||||
unless($rabbit_queues{$incoming_destination}) {
|
||||
_debug("RABBIT Declaring queue $incoming_destination");
|
||||
$rabbit->queue_declare(1, $incoming_destination, { durable => 1 });
|
||||
$rabbit_queues{$incoming_destination}++;
|
||||
}
|
||||
$rabbit->publish(1, $incoming_destination, $incoming->body);
|
||||
}
|
||||
# $amq->ack({ frame => $incoming });
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user