Lagom Version: 1.3
Attempting to do: Notify all actors in the cluster that an event has been received from a message queue, this prompts them all to update in memory caches.
Issue encountered: When publishing my akka message, my code on the subscription never seems to fire. though i receive the following:
Message [java.lang.String] from Actor[akka://my-impl-application/deadLetters] to Actor[akka://my-impl-application/system/distributedPubSubMediator#855479769] was not delivered. [2] dead letters encountered. This logging can be turned off or adjusted with configuration settings âakka.log-dead-lettersâ and âakka.log-dead-letters-during-shutdownâ.
My Investigation: I have tried to find examples and found I was getting similar issues even using example code such as https://github.com/knoldus/lagom-pub-sub.g8
Iâve noted almost all examples seems to suggest subscription be done async to publish logic (in the example the subscription is only done when a stream is opened), which doesnât suit my needs. An example of the overall logic of my code is below (this isnât the code, itâs a nice simplification):
public class MyService {
@Inject
//KafkaService is just an instance of com.lightbend.lagom.javadsl.api.Service with a single Topic
public MyService(KafkaService service, PubSubRegistry pubSubRegistry) {
PubSubRef<String> pubSubRef = pubSubRegistry.refFor(TopicId.of(String.class, "my_topic"));
service.myTopic().subscribe()
.atLeastOnce(Flow.<String>create().fromFunction(msg -> {
pubSubRef.publish(msg);
return Done.getInstance();
});
pubSubRef.subscriber().subscribe().map(msg -> {
System.out.println(msg);
return msg;
});
}
}
application.conf
play.akka.actor-system = "my-impl-application"
akka {
actor {
provider = "cluster"
}
remote {
log-remote-lifecycle-events = off
netty.tcp {
hostname = "127.0.0.1"
port = 2552
}
}
}
akka.cluster.seed-nodes = [
"akka.tcp://my-impl-application@127.0.0.1:2552"]
Expected: When an actor in my cluster receives a kafka event, an akka msg is published which ALL other actors consume and then do something.
Current Workaround: Currently as per https://doc.akka.io/docs/akka/2.4/java/distributed-pub-sub.html Iâm just building my own akka pubsub structure, though I would much prefer to use the built in Lagom feature