Skip to content

Latest commit

 

History

History
53 lines (41 loc) · 1.97 KB

README.md

File metadata and controls

53 lines (41 loc) · 1.97 KB

paho-akka

CI Known Vulnerabilities

What?

This is a Publish Subscribe library for akka to pub/sub to a MQTT server - ex mosquitto. paho-akka use paho as the underlying MQTT client.

We, at http://sandinh.com, use paho-akka to replace Distributed Publish Subscribe in Cluster

Install?

paho-akka is on Maven Center

How to use

val pubsub = actorOf(Props(classOf[MqttPubSub], PSConfig(
    brokerUrl = "tcp://test.mosquitto.org:1883", //all params is optional except brokerUrl
    userName = null,
    password = null,
    //messages received when disconnected will be stash. Messages isOverdue after stashTimeToLive will be discard
    stashTimeToLive = 1.minute,
    stashCapacity = 8000, //stash messages will be drop first haft elems when reach this size
    reconnectDelayMin = 10.millis, //for fine tuning re-connection logic
    reconnectDelayMax = 30.seconds
)))

pubsub ! new Publish(topic, payload)

class SubscribeActor extends Actor {
  pubsub ! Subscribe(topic, self)

  def receive = {
    case SubscribeAck(Subscribe(`topic`, `self`, _), fail) =>
      if (fail.isEmpty) context become ready
      else logger.error(fail.get, s"Can't subscribe to $topic")
  }

  def ready: Receive = {
    case msg: Message => ...
  }
}

Changelog

see [CHANGES.md]

Licence

This software is licensed under the Apache 2 license: http://www.apache.org/licenses/LICENSE-2.0

Copyright 2014 Sân Đình (http://sandinh.com)