rainier-notify
Laravel's notifications: a message to somebody, over whichever channels they can be reached on.
This is not an event
The two get confused because both fan out, and they fan out for different reasons and to different things.
| An event | A notification | |
|---|---|---|
| Says | "this happened" | "tell them this" |
| Recipient | none | exactly one, per send |
| Fan-out decided by | who subscribed, at boot | the notification and the recipient, per send |
| Payload | one shape | one per channel |
| Nobody handles it | normal | almost certainly a bug |
| Direction | producer → whoever is listening | producer → a named recipient |
PostPublished is an event: a fact, with no opinion about who should hear
about it. NewPostFromAuthorYouFollow is a notification: it has a
recipient, and it knows it should be an email and a row in their bell
menu.
They compose, and that composition is the usual wiring:
// The event says what happened.
events.listen(|event: Arc<PostPublished>| async move {
let notifier = resolve::<Notifier>()?;
// The notification says who to tell, and how.
for follower in followers_of(event.post.author_id).await? {
notifier.send(&follower, &NewPost { post: event.post.clone() }).await?;
}
Ok(())
});
Collapsing them loses something either way. An event with a recipient cannot be listened to by anything else — an analytics listener has no business receiving "tell Ada about this". A notification with no recipient cannot ask Ada whether she wanted an email.
The shape
use ;
# async
Channels are selected by type
Channels::new().with::<MailChannel>(), not ["mail"]. The same reasoning
as middleware and configuration keys: a misspelled
"mial" is a notification that silently goes nowhere, and deleting a
channel should break every notification that used it in the compiler.
Failure is per channel
An SMTP outage must not also cost the database row that puts the
notification in the recipient's bell menu, so a channel failing does not
stop the others. [Receipt] says what happened on each;
[Receipt::into_result] turns "nothing got through at all" into an error.
A recipient with no address on a channel is skipped, not failed — a user with no phone number should still get the email.