Bayou

Installation

bundle add bayou
gem install bayou

Usage

require "bayou"

##
# define peers
# Bayou.peer['peer id'] = { host: 'localhost', port: 1883 }
# Bayou.peet['peer id'] = "mqtt://localhost:1883"
Bayou.peer["here"] = { host: 'localhost', port: 1883 }

##
#  hook target ("hi") handler
#  hook[:key] = value #=> set hook return param
#  hook[:key] #=> get hook param
#  hook.push(topic: 'new topic' || hook[:topic], target: 'new target', hook[:target], ...) #=> push packet to target in topic
#  hook.loop { |hooked| hooked } #=> handle hook and push params
Bayou.on["hi"] = lambda { |hook| puts %[HI: #{hook}] }

##
# pull packets in topic ("topic") from peer ("here") to target handler
#  Bayou.pull("peer id", "topic", ...) #=> accepts any number of topics
Bayou.pull("here", ENV['NODE'])

##
# send packet ({ message: 'Hello, World!' }) to target ("hi") in topic ("topic") at peer ("here")
#  Bayou.push("peer id", "topic", "target", data={})
Bayou.push("here", "topic", "hi", message: 'Hello, World!')