The payload
of For
message will be delivered by MessageBus
to all LiftActor
s that subscribed
to the given Topic
.
The payload
of ForAll
message will be delivered by MessageBus
to all LiftActor
s that subscribed
to the given Topic
type.
The payload
of ForAll
message will be delivered by MessageBus
to all LiftActor
s that subscribed
to the given Topic
type. For example:
case class WombatPhotosTopic(wombatId: String) extends Topic { val name = "wombat-topic-" + wombatId } case class BeaverPhotosTopic(beaverId: String) extends Topic { val name = "beaver-topic-" + beaverId } MessageBus ! Subscribe(listener1, WombatPhotosTopic("1")) MessageBus ! Subscribe(listener2, WombatPhotosTopic("2")) MessageBus ! Subscribe(listener3, BeaverPhotosTopic("1")) MessageBus ! ForAll[WombatPhotosTopic](WombatPhoto('wombat.jpg'))
the WombatPhoto('wombat.jpg')
message will be sent to listener1
and listener2
because they are both subscribed
to topic of type WombatPhotosTopic
. listener3
will not receive this message because it's not subscribed
to topic of type WombatPhotosTopic'.
the type of Topic
. Message will be sent to all Topic
s of this type.
message that should be sent to Topic
PublisherActor
is the component that is responsible for sending messages to subscribed listeners.
PublisherActor
is the component that is responsible for sending messages to subscribed listeners.
It is an internal actor used by MessageBus
and created automatically when a new Topic
instance
is registered in MessageBus
.
Subscribe
is a message that should be sent to MessageBus
when LiftActor
wants to subscribe
to the given Topic
.
Subscribe
is a message that should be sent to MessageBus
when LiftActor
wants to subscribe
to the given Topic
. For example:
MessageBus ! Subscribe(this, topic)
For CometActor
s this will usually take place in the localSetup
method.
reference to LiftActor
that wants to subscribe to topic
reference to Topic
to which the actor
should be subscribed
Topic instances can be perceived as a street advertising columns.
Topic instances can be perceived as a street advertising columns. Components interested in some
sort of messages will subscribe to appropriate Topic
instance in MessageBus
that controls message
flow between message publishers and listeners.
For example, we might have some components interested in receiving beaver photo updates and components
interested in receiving wombat photo updates. For this situation, we would create two Topics
:
case object BeaverPhotosTopic extends Topic { val name = "beaver-photos" } case object WombatPhotosTopic extends Topic { val name = "wombat-photos" }
All messages sent to BeaverPhotosTopic
would be received only by components subscribed to BeaverPhotosTopic
.
All messages sent to WombatPhotosTopic
would be received only by components subscribed to WombatPhotosTopic
.
Unsubscribe
is a message that should be sent to MessageBus
when LiftActor
wants to unsubscribe
from the given Topic
.
Unsubscribe
is a message that should be sent to MessageBus
when LiftActor
wants to unsubscribe
from the given Topic
. For example:
MessageBus ! Unsubscribe(this, topic)
For CometActor
s this will usually take place in the localShutdown
method.
reference to LiftActor
that wants to unsubscribe from topic
reference to Topic
from which the actor
should be unsubscribed
MessageBus
allows to send messages between LiftActor
s even if they live in separate user sessions.
MessageBus
allows to send messages between LiftActor
s even if they live in separate user sessions.
All LiftActor
s 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:
case class 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 Topic
s of the given type.
Let's consider two listeners:
MessageBus ! Subscribe(listener1, BeaverTopic("1")) MessageBus ! Subscribe(listener2, BeaverTopic("2"))
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:
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 CometActor
s, the Subscribe
/Unsubscribe
actions should usually take place in localSetup
and localShutdown
methods.
There are no limitations in a number of Topic
s to which a given LiftActor
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. implementing messageHandler
method or low
/medium
/highPriority
method).
The
payload
ofFor
message will be delivered byMessageBus
to allLiftActor
s that subscribed to the givenTopic
. For example:The
WombatPhoto('wombat.jpg')
message will be delivered to allLiftActor
s that previously subscribed toWombatPhotosTopic
sendingSubscribe
toMessageBus
.Actors should listen for messages delivered from
MessageBus
as an effect ofFor
sent by sender in the same way as for any other message types (e.g. implementingmessageHandler
method orlow
/medium
/highPriority
method).reference to
Topic
to which the message should be sentmessage that should be sent to
Topic