mirror of
https://github.com/ash-project/ash.git
synced 2024-09-20 13:33:20 +12:00
131 lines
3 KiB
Text
131 lines
3 KiB
Text
# DSL: Ash.Notifier.PubSub
|
|
|
|
A pubsub notifier extension.
|
|
|
|
|
|
## pub_sub
|
|
A section for configuring how resource actions are published over pubsub
|
|
|
|
See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guide for more.
|
|
|
|
|
|
### Nested DSLs
|
|
* [publish](#pub_sub-publish)
|
|
* [publish_all](#pub_sub-publish_all)
|
|
|
|
|
|
### Examples
|
|
```
|
|
pub_sub do
|
|
module MyEndpoint
|
|
prefix "post"
|
|
broadcast_type :phoenix_broadcast
|
|
|
|
publish :destroy, ["foo", :id]
|
|
publish :update, ["bar", :name] event: "name_change"
|
|
publish_all :create, "created"
|
|
end
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
### Options
|
|
| Name | Type | Default | Docs |
|
|
| --- | --- | --- | --- |
|
|
| `module`* | `atom` | | The module to call `broadcast/3` on e.g module.broadcast(topic, event, message). |
|
|
| `prefix` | `String.t` | | A prefix for all pubsub messages, e.g `users`. A message with `created` would be published as `users:created` |
|
|
| `broadcast_type` | `:notification \| :phoenix_broadcast \| :broadcast` | :notification | What shape the event payloads will be in. See |
|
|
| `name` | `atom` | | A named pub sub to pass as the first argument to broadcast. |
|
|
|
|
|
|
|
|
## pub_sub.publish
|
|
```elixir
|
|
publish action, topic
|
|
```
|
|
|
|
|
|
Configure a given action to publish its results over a given topic.
|
|
|
|
See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guides for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
publish :create, "created"
|
|
```
|
|
|
|
```
|
|
publish :assign, "assigned"
|
|
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
| Name | Type | Default | Docs |
|
|
| --- | --- | --- | --- |
|
|
| `action`* | `atom` | | The name of the action that should be published |
|
|
| `topic`* | ``any`` | | The topic to publish |
|
|
### Options
|
|
| Name | Type | Default | Docs |
|
|
| --- | --- | --- | --- |
|
|
| `event` | `String.t` | | The name of the event to publish. Defaults to the action name |
|
|
| `dispatcher` | `atom` | | The module to use as a dispatcher. If none is set, the pubsub module provided is used. |
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Notifier.PubSub.Publication`
|
|
|
|
## pub_sub.publish_all
|
|
```elixir
|
|
publish_all type, topic
|
|
```
|
|
|
|
|
|
Works just like `publish`, except that it takes a type
|
|
and publishes all actions of that type
|
|
|
|
See the [PubSub](/documentation/topics/pub_sub.md) and [Notifiers](/documentation/topics/notifiers.md) guides for more.
|
|
|
|
|
|
|
|
|
|
### Examples
|
|
```
|
|
publish_all :create, "created"
|
|
```
|
|
|
|
|
|
|
|
### Arguments
|
|
| Name | Type | Default | Docs |
|
|
| --- | --- | --- | --- |
|
|
| `type` | `:create \| :update \| :destroy` | | Publish on all actions of a given type |
|
|
| `topic`* | ``any`` | | The topic to publish |
|
|
### Options
|
|
| Name | Type | Default | Docs |
|
|
| --- | --- | --- | --- |
|
|
| `action` | `atom` | | The name of the action that should be published |
|
|
| `event` | `String.t` | | The name of the event to publish. Defaults to the action name |
|
|
| `dispatcher` | `atom` | | The module to use as a dispatcher. If none is set, the pubsub module provided is used. |
|
|
|
|
|
|
|
|
|
|
|
|
### Introspection
|
|
|
|
Target: `Ash.Notifier.PubSub.Publication`
|
|
|
|
|
|
|
|
|