Local Pub-Sub (Within an actor system)

In Akka, an event bus is used to provide the functionality of pub-sub within an actor system. Actors can subscribe to certain types of events and when that event happens, messages are sent to all the subscriber actors. There is a lot of flexibility in how you subscribe to event using classification strategy. Akka provides the following strategies:

Lookup

This is sort of an exact matching of classifiers e.g. you subscribe to ABC and you will get messages for ABC. You can however customize how the classifier is extracted from events e.g. the event is:

case class Message(topic: String, payload: Any)

Then actors can subscribe to various topics e.g. Sports, Finance etc and when a message containing that topic is published, it'll be delivered to all the subscribers of that topic.

Subchannel

If the events (messages) have some form of hierarchy and you want to be able to subscribe for events at certain level in the hierarchy, you should use subchannel classification e.g. events could be

news
news/sports
news/sports/cricket
news/sports/cricket/domestic

Then you can subscribe to news (get all news), news/sports (get only sports news), news/sports/cricket (only cricket news in sports etc. Again you can customize how the hierarchy is defined and how the classifier is extracted from messages.

Scanning

In cases where there is no strict hierarchy in events (e.g. all events/messages containing word X or with amount greater than X), you can use scanning classification. When an event is published, all the subscribers are scanned and event is delivered to ones for which the event satisfies the criteria (e.g. message with amount 100 will be delivered to all the actors subscribed to messages with amount greater than 50).

results matching ""

    No results matching ""