View Source Solvent.Subscription (solvent v0.3.0)

Describes a consumer's wish to receive events, as well as how to deliver them.

See new/2 for instructions on how to create one of these structs, and then give that struct to Solvent.subscribe/1 to being receiving events.

Link to this section Summary

Functions

Test if a subscription should deliver a certain event.

Create a new subscription struct.

Link to this section Functions

Link to this function

match?(subscription, event)

View Source

Test if a subscription should deliver a certain event.

Create a new subscription struct.

This function does not subscribe to the event stream, but once you create a Solvent.Subscription struct, you can give it to Solvent.subscribe/1 to subscribe to events.

After providing a sink, you can additionally match for a source, multiple types, or provide filters to further match events.

examples

Examples

To create a subscription for matching all events passing through Solvent, just provide a sink.

iex> Solvent.Subscription.new({MyModule, :handle_event, []})

To match all events coming from a single source, provide a :source option. It should be a string.

iex> Solvent.Subscription.new({MyModule, :handle_event, []}, source: "https://myapp.example.com")

You can also match a set of event types.

iex> Solvent.Subscription.new({MyModule, :handle_event, []}, types: ["com.example.message.sent", "com.example.message.received"])

For more complex filtering, provide a struct implementing Solvent.Filter. You can build one from a keyword list with Solvent.build_filters/1.

iex> Solvent.Subscription.new({MyModule, :handle_event, []}, filter: Solvent.build_filters([prefix: [type: "com.example."]]))

Multiple options can be provided in the same subscription.

iex> Solvent.Subscription.new(
  {MyModule, :handle_event, []},
  source: "https://myapp.example.com",
  types: ["com.example.message.sent", "com.example.message.received"]
)