and rabbit
This commit is contained in:
parent
e0c4d835c3
commit
5bae47c1cf
@ -1,5 +1,5 @@
|
||||
FROM debian
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y make libnet-stomp-perl libanyevent-rabbitmq-perl
|
||||
RUN apt-get install -y make libnet-stomp-perl libanyevent-rabbitmq-perl build-essential
|
||||
RUN yes | cpan install Net::MQTT::Simple
|
||||
|
||||
RUN yes | cpan install -f Net::RabbitMQ
|
||||
|
28
bridge.pl
28
bridge.pl
@ -34,6 +34,12 @@ foreach (
|
||||
|
||||
MQTT_SERVER
|
||||
MQTT_PUBLISH_BASE
|
||||
|
||||
RABBITMQ_SERVER
|
||||
RABBITMQ_PORT
|
||||
RABBITMQ_USER
|
||||
RABBITMQ_PASSWORD
|
||||
RABBITMQ_VHOST
|
||||
)
|
||||
) {
|
||||
assert($ENV{$_}, "`$_' not available");
|
||||
@ -50,8 +56,22 @@ $amq->connect( {
|
||||
|
||||
|
||||
## Connect to MQTT
|
||||
_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}";
|
||||
|
||||
use Net::RabbitMQ;
|
||||
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);
|
||||
|
||||
## Subscribe to ActiveMQ topics
|
||||
foreach my $topic (split (/\s*,\s*/, $ENV{AMQ_TOPICS})) {
|
||||
_debug("Subscribing to amq://$ENV{AMQ_SERVER}:$ENV{AMQ_PORT}/topic/$topic");
|
||||
@ -76,9 +96,13 @@ while(1) {
|
||||
|
||||
_debug("AMQ -> " . $incoming->destination);
|
||||
_debug("MQTT <- " . $ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination);
|
||||
|
||||
$mqtt->retain($ENV{MQTT_PUBLISH_BASE} . "/" . $incoming_destination, $incoming->body);
|
||||
|
||||
_debug("RABBIT <- " . $incoming->destination);
|
||||
$rabbit->publish(1, "test", $incoming->body);
|
||||
|
||||
$amq->ack({ frame => $incoming });
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
$mq->disconnect();
|
Loading…
x
Reference in New Issue
Block a user