diff --git a/Dockerfile b/Dockerfile index 7538c99..eed0056 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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 diff --git a/bridge.pl b/bridge.pl index 0625018..fb65c95 100755 --- a/bridge.pl +++ b/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 }); -} \ No newline at end of file +} + +$mq->disconnect(); \ No newline at end of file