Compare commits
4 Commits
618bc5d76c
...
v1.0
Author | SHA1 | Date | |
---|---|---|---|
![]() |
12e6122706 | ||
0fcf6745f1 | |||
6fdf2d2427 | |||
612526aca8 |
@@ -1,4 +1,6 @@
|
||||
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
|
||||
ENTRYPOINT ["/bridge.pl"]
|
18
bridge.pl
18
bridge.pl
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/perl
|
||||
#!/usr/bin/env perl
|
||||
|
||||
# use warnings;
|
||||
# use strict;
|
||||
use strict;
|
||||
|
||||
use Net::Stomp;
|
||||
use Net::MQTT::Simple;
|
||||
@@ -60,7 +60,10 @@ $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();
|
||||
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},
|
||||
{
|
||||
@@ -71,7 +74,7 @@ $rabbit->connect($ENV{RABBITMQ_SERVER},
|
||||
});
|
||||
_debug("Open rabbitmq channel");
|
||||
$rabbit->channel_open(1);
|
||||
my %rabbit_queues;
|
||||
}
|
||||
|
||||
## Subscribe to ActiveMQ topics
|
||||
foreach my $topic (split (/\s*,\s*/, $ENV{AMQ_TOPICS})) {
|
||||
@@ -99,6 +102,7 @@ while(1) {
|
||||
_debug("MQTT <- " . $ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination);
|
||||
$mqtt->retain($ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination, $incoming->body);
|
||||
|
||||
unless($ENV{DISABLE_RABBIT}) {
|
||||
_debug("RABBIT <- " . $incoming->destination);
|
||||
unless($rabbit_queues{$incoming_destination}) {
|
||||
_debug("RABBIT Declaring queue $incoming_destination");
|
||||
@@ -106,9 +110,9 @@ while(1) {
|
||||
$rabbit_queues{$incoming_destination}++;
|
||||
}
|
||||
$rabbit->publish(1, $incoming_destination, $incoming->body);
|
||||
|
||||
$amq->ack({ frame => $incoming });
|
||||
}
|
||||
# $amq->ack({ frame => $incoming });
|
||||
|
||||
}
|
||||
|
||||
$mq->disconnect();
|
||||
$amq->disconnect();
|
||||
|
Reference in New Issue
Block a user