Copyright | (c) FPComplete, 2015 |
---|---|
License | MIT |
Maintainer | Tim Dysinger <tim@fpcomplete.com> |
Stability | experimental |
Portability | POSIX |
Safe Haskell | None |
Language | Haskell2010 |
This module helps you proxy information to Consul from the internet & also react to changes to K/V data coming from Consul.
┌─────────┐ ┌─────────┐ │ JSON │ │ LOAD │ │ HTTP │─────▶│ BALANCR │ │ POST │ │ │ └─────────┘ └─────────┘ │ ┌────────────┬──────┘─ ─ ─ │ │ ▼ ▼ ▼ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ │ │ │ ┌──│ WAI App │ │ WAI App │ │ WAI App │ │ │ │ │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘ │ ▲ ▲ │ │ │ │ ┌────────────┴────────────┘ │ │ │ │ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │ │ │ │ │ │ └─▶│ Consul │──│ Consul │──│ Consul │ │ │ │ │ │ │ └─────────┘ └─────────┘ └─────────┘
- data ConsulSettings
- defaultConsulSettings :: ConsulSettings
- getConsulCallback :: ConsulSettings -> ConsulCallback
- getConsulFilter :: ConsulSettings -> Request -> Bool
- getConsulHost :: ConsulSettings -> Text
- getConsulKey :: ConsulSettings -> Text
- getConsulLimit :: ConsulSettings -> Maybe Int
- getConsulPort :: ConsulSettings -> PortNumber
- mkConsulProxy :: (MonadIO m, Functor m) => ConsulSettings -> m Middleware
- mkConsulWatch :: (MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> m Void
- setConsulCallback :: ConsulCallback -> ConsulSettings -> ConsulSettings
- setConsulFilter :: (Request -> Bool) -> ConsulSettings -> ConsulSettings
- setConsulHost :: Text -> ConsulSettings -> ConsulSettings
- setConsulKey :: Text -> ConsulSettings -> ConsulSettings
- setConsulLimit :: Maybe Int -> ConsulSettings -> ConsulSettings
- setConsulPort :: PortNumber -> ConsulSettings -> ConsulSettings
- withConsul :: (Monad m, MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> (Middleware -> m a) -> m a
Documentation
data ConsulSettings Source
Consul Settings for watching & proxying Consul data
getConsulCallback :: ConsulSettings -> ConsulCallback Source
getConsulFilter :: ConsulSettings -> Request -> Bool Source
getConsulKey :: ConsulSettings -> Text Source
mkConsulProxy :: (MonadIO m, Functor m) => ConsulSettings -> m Middleware Source
Create WAI middleware that can be used to proxy incoming data into Consul (one-way). This function initiates our consul client and returns the middleware for WAI to use. The middleware will filter incoming requests that match ConsulSettings csFilter. If there is a match it will create a make the key value put call for Consul using the incoming request body as the data for the Consul K/V.
mkConsulWatch :: (MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> m Void Source
Creates a background process to receive notifications. Notifications happen via blocking HTTP request. (The HTTP client manager used has been configured to wait forever for a response.) The ConsulSettings (csHost, csPort & csKey) are used to connect to Consul and watch for key-value changes. When Consul's value changes, it will respond to the HTTP request. Upon receiving a good changed-value response, we fire the csCallback function to allow for a reaction to the data change. If there there is a problem with the request/response cycle or an exception in the supplied callback function, we just re-make the rquest & wait patiently for changes again.
setConsulCallback :: ConsulCallback -> ConsulSettings -> ConsulSettings Source
setConsulFilter :: (Request -> Bool) -> ConsulSettings -> ConsulSettings Source
setConsulHost :: Text -> ConsulSettings -> ConsulSettings Source
setConsulKey :: Text -> ConsulSettings -> ConsulSettings Source
setConsulLimit :: Maybe Int -> ConsulSettings -> ConsulSettings Source
withConsul :: (Monad m, MonadBaseControl IO m, MonadLoggerIO m) => ConsulSettings -> (Middleware -> m a) -> m a Source
Creates a complete Consul middleware for the cluster. Combines mkConsulWatch async function (watches Consul data for updates) & mkConsulProxy (proxys data from the internet to Consul) into one common-use function. This will probably be the function you want. See the example/ application for more insight.