Created
March 6, 2021 15:20
-
-
Save jonathanstowe/ba4ab32cc4e4027278c4d977ee2a79e2 to your computer and use it in GitHub Desktop.
Cro::MQTT spoiler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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