AnyEvent-MQTT
view release on metacpan or search on metacpan
SYNOPSIS
use AnyEvent::MQTT;
my $mqtt = AnyEvent::MQTT->new;
my $cv = $mqtt->subscribe(topic => '/topic',
callback => sub {
my ($topic, $message) = @_;
print $topic, ' ', $message, "\n"
});
my $qos = $cv->recv; # subscribed, negotiated QoS == $qos
# publish a simple message
$cv = $mqtt->publish(message => 'simple message',
topic => '/topic');
$cv->recv; # sent
# publish line-by-line from file handle
$cv = $mqtt->publish(handle => \*STDIN,
topic => '/topic');
$cv->recv; # sent
# publish from AnyEvent::Handle
$cv = $mqtt->publish(handle => AnyEvent::Handle->new(my %handle_args),
topic => '/topic');
$cv->recv; # sent
DESCRIPTION
AnyEvent module for MQTT client.
IMPORTANT: This is an early release and the API is still subject to
change.
DISCLAIMER
This is not official IBM code. I work for IBM but I'm writing this in
my spare time (with permission) for fun.
Constructs a new AnyEvent::MQTT object. The supported parameters are:
host
The server host. Defaults to 127.0.0.1.
port
The server port. Defaults to 1883.
timeout
The timeout for responses from the server.
keep_alive_timer
The keep alive timer.
user_name
The user name for the MQTT broker.
password
The password for the MQTT broker.
tls
Set flag to enable TLS encryption, Default is no encryption.
will_topic
Set topic for will message. Default is undef which means no will
message will be configured.
will_qos
Set QoS for will message. Default is 'at-most-once'.
will_retain
Set retain flag for will message. Default is 0.
will_message
Set message for will message. Default is the empty message.
clean_session
Set clean session flag for connect message. Default is 1.
client_id
Sets the client id for the client overriding the default which is
NetMQTTpmNNNNN where NNNNN is the current process id.
message_log_callback
Defines a callback to call on every message.
on_error
Defines a callback to call when some error occurs.
Two parameters are passed to the callback.
$on_error->($fatal, $message)
where $fatal is a boolean flag and $message is the error message. If
the error is fatal, $fatal is true.
handle_args
a reference to a list to pass as arguments to the
L<AnyEvent::Handle> constructor (defaults to
an empty list reference).
This method attempts to destroy any resources in the event of a
disconnection or fatal error.
This method is used to publish to a given topic. It returns an AnyEvent
condvar which is notified when the publish is complete (written to the
kernel or ack'd depending on the QoS level). The parameter hash must
included at least a topic value and one of:
( run in 0.557 second using v1.01-cache-2.11-cpan-98e64b0badf )