Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jonathanstowe/ba4ab32cc4e4027278c4d977ee2a79e2 to your computer and use it in GitHub Desktop.
Save jonathanstowe/ba4ab32cc4e4027278c4d977ee2a79e2 to your computer and use it in GitHub Desktop.
Cro::MQTT spoiler
use Cro::MQTT;
my $subscriptions = subscriptions {
subscribe 'hello-world', {
consume -> $m { say "GOT HELLO WORLD ", $m.message.decode }
}
subscribe 'another-world', {
consume -> $m { say "GOT ANOTHER WORLD ", $m.message.decode }
}
}
my $service = Cro::MQTT.new(
port => 1883,
:$subscriptions
);
$service.start;
react {
whenever signal(SIGINT) {
$service.stop;
done;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment