I have a perl script that subscribes to a message queue using AnyEvent :: MQTT.
At that moment, when all I want to do is print it when he receives the message. I am completely unfamiliar with perl, so I use the demo code in which it is included, including the bit that publishes something on STDIN as a message - this works fine, and I see all the messages received.
This code is as follows
use strict;
use warnings;
use AnyEvent::MQTT;
my $mqtt = AnyEvent::MQTT->new;
my $cv = $mqtt->subscribe(topic => '/AlarmMode',
callback => sub {
my ($topic, $message) = @_;
print $topic, ' ', $message, "\n"
});
my $qos = $cv->recv;
$cv = $mqtt->publish(handle => \*STDIN,
topic => '/topic');
The problem is that if I delete everything after the comment publish line-by-line from file handle, then my application will exit as soon as it starts.
I tried turning on the while loop, which sleeps for 5 seconds, but this does not work (the application just looks like it was hanging).
, - , , , : -)