MessageBus allows to send messages between LiftActors even if they live in separate user sessions.
All LiftActors that subscribed to the given Topic will receive messages sent to this Topic.
If you want your actor to subscribe to the given Topic, you need to send the Subscribe message:
caseclass BeaverPhotosTopic(beaverId: String) extends Topic {
val name = "beaver-photos-" + beaverId
}
val topic = BeaverPhotosTopic("1")
MessageBus ! Subscribe(this, topic)
from this point, all messages sent to this topic will be received by the actor.
There are two ways to send a message to Topic: For and ForAll.
The For class takes a Topic instance and sends a payload only to actors subscribed to this particular Topic.
The ForAll class takes a Topic type and sends a payload to all actors subscribed to all Topics of the given type.
However, if we send a message in the following way:
MessageBus ! ForAll[BeaverTopic](message)
Both listener1 and listener2 will receive it.
LiftActor can unsubscribe from the given Topic by sending Unsubscribe message:
MessageBus ! Unsubscribe(this, BeaverTopic("1"))
In case of CometActors, the Subscribe/Unsubscribe actions should usually take place in localSetup
and localShutdown methods.
There are no limitations in a number of Topics to which a given LiftActor can be subscribed.
Actors subscribed to Topics should listen for messages in the same way as they listen
for any other message types (e.g. implementing messageHandler method or low/medium/highPriority method).
Linear Supertypes
LiftActor, ForwardableActor[Any, Any], GenericActor[Any], TypedActor[Any, Any], SpecializedLiftActor[Any], SimpleActor[Any], AnyRef, Any
MessageBus
allows to send messages betweenLiftActor
s even if they live in separate user sessions. AllLiftActor
s that subscribed to the givenTopic
will receive messages sent to thisTopic
.If you want your actor to subscribe to the given
Topic
, you need to send theSubscribe
message:from this point, all messages sent to this topic will be received by the actor.
There are two ways to send a message to
Topic
:For
andForAll
. TheFor
class takes aTopic
instance and sends a payload only to actors subscribed to this particularTopic
. TheForAll
class takes aTopic
type and sends a payload to all actors subscribed to allTopic
s of the given type.Let's consider two listeners:
If we send a message in the following way:
MessageBus ! For(BeaverTopic("1"), message)
only
listener1
will receive it.However, if we send a message in the following way:
Both
listener1
andlistener2
will receive it.LiftActor
can unsubscribe from the givenTopic
by sendingUnsubscribe
message:In case of
CometActor
s, theSubscribe
/Unsubscribe
actions should usually take place inlocalSetup
andlocalShutdown
methods.There are no limitations in a number of
Topic
s to which a givenLiftActor
can be subscribed.Actors subscribed to
Topic
s should listen for messages in the same way as they listen for any other message types (e.g. implementingmessageHandler
method orlow
/medium
/highPriority
method).