-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathConsumerBot.scala
36 lines (25 loc) · 965 Bytes
/
ConsumerBot.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package data_distribution
import akka.actor.{Actor, ActorLogging, ActorRef}
import akka.cluster.Cluster
import akka.cluster.ddata.Replicator._
import akka.cluster.ddata.{DistributedData, ORSetKey}
/**
* Created by pabloperezgarcia on 19/02/2017.
*
* In this example the consumer it will subscribe to a specific ORSetKey and it will receive all changes happens
* in the ORSetKey
*
* http://doc.akka.io/docs/akka/2.4.16/scala/distributed-data.html
*/
class ConsumerBot(name:String) extends Actor with ActorLogging {
implicit val node = Cluster(context.system)
val DataKey: ORSetKey[String] = ORSetKey[String]("uniqueKey")
val replicator: ActorRef = DistributedData(context.system).replicator
replicator ! Subscribe(DataKey, self)
def receive = {
case _: UpdateResponse[_] => //ignore
case replicatorMessage@Changed(DataKey) =>
val data = replicatorMessage.get(DataKey)
log.info(s"$name: {}", data.elements)
}
}