Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Synopsis
- newtype Key a msg = Key [Bind]
- data Bind
- data Route
- key :: Text -> Key Route msg
- word :: Text -> Key a msg -> Key a msg
- any1 :: Key a msg -> Key Bind msg
- many :: Key a msg -> Key Bind msg
- keyText :: Key a msg -> Text
- fromBind :: Bind -> Text
- toBind :: Text -> Bind
- toBindKey :: Key a msg -> Key Bind msg
- type family RequireRoute (a :: Type) :: Constraint where ...
Documentation
Messages are published with a specific identifier called a Routing key. Queues can use Binding Keys to control which messages are delivered to them.
Routing keys have no dynamic component and can be used to publish messages
commentsKey :: Key Route Comment commentsKey = key "posts" & word "new"
Binding keys can contain wildcards, only used for matching messages
commentsKey :: Key Bind Comment commentsKey = key "posts" & any1 & word "comments" & many
key :: Text -> Key Route msg Source #
Start a new routing key (can also be used for bindings)
key "messages" -- matches "messages"
word :: Text -> Key a msg -> Key a msg Source #
A specific word. Can be used to chain Routing keys or Binding keys
key "messages" & word "new" -- matches "messages.new"
any1 :: Key a msg -> Key Bind msg Source #
Match any one word. Equivalent to *
. Converts to a Binding key and can no longer be used to publish messaages
key "messages" & any1 -- matches "messages.new" -- matches "messages.update"
many :: Key a msg -> Key Bind msg Source #
Match zero or more words. Equivalient to #
. Converts to a Binding key and can no longer be used to publish messages
key "messages" & many -- matches "messages" -- matches "messages.new" -- matches "messages.1234.update"
toBindKey :: Key a msg -> Key Bind msg Source #
We can convert Route Keys to Bind Keys safely, as they are usable for both publishing and binding
type family RequireRoute (a :: Type) :: Constraint where ... Source #
Custom error message when trying to publish to Binding keys
RequireRoute Bind = TypeError ('Text "Expected Routing Key but got Binding Key instead. Messages can be published only with keys that exclusivlely use `key` and `word`" :$$: 'Text "\n key \"message\" & word \"new\" \n") | |
RequireRoute a = () |