allow disable rabbit
This commit is contained in:
parent
6fdf2d2427
commit
0fcf6745f1
20
bridge.pl
20
bridge.pl
@ -60,18 +60,21 @@ $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;
|
||||||
_debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}");
|
my %rabbit_queues;
|
||||||
$rabbit->connect($ENV{RABBITMQ_SERVER},
|
unless ($ENV{DISABLE_RABBIT}) {
|
||||||
|
$rabbit = Net::RabbitMQ->new();
|
||||||
|
_debug("Connecting to rabbitmq://$ENV{RABBITMQ_SERVER}");
|
||||||
|
$rabbit->connect($ENV{RABBITMQ_SERVER},
|
||||||
{
|
{
|
||||||
user => $ENV{RABBITMQ_USER},
|
user => $ENV{RABBITMQ_USER},
|
||||||
password => $ENV{RABBITMQ_PASSWORD},
|
password => $ENV{RABBITMQ_PASSWORD},
|
||||||
vhost => $ENV{RABBITMQ_VHOST},
|
vhost => $ENV{RABBITMQ_VHOST},
|
||||||
channel_max => 64,
|
channel_max => 64,
|
||||||
});
|
});
|
||||||
_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 });
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user