packages feed

legion-discovery-client-0.1.0.3: README.md

# legion-discovery-client

This is a Haskell client library used to communicate with the Legion
Discovery discovery service.


## Performing a query without registering a service.

If you want to perform a query without registering yourself a service,
the following example is how you might typically accomplish that. Note
that even though you are not starting a service, you must still specify
a name and a version for the local program. The reason for this is
that Legion Discovery keeps track of all requests in order to build a
dependency graph of your service ecosystem.

```haskell
import Network.HTTP.Client as C
import OM.Discovery (connect, query)

...

let
  name = "my-program" {- the name of this client program. -}
  version = "0.1" {- the version of this client program.  -}
  targetService = "some-service" {- the name of the service you are looking for. -}
  targetRange = "> 1.1.1 && < 1.2" {- the range of acceptable versions you wish to find. -}
in do
  manager <- C.newManager C.defaultManagerSettings
  discovery <- connect name version manager

  servicesInstances <- query targetService targetRange discovery
  ...
```


## Registering a service.

The following example shows how to register a service, using
`withService`.

```haskell
import Network.HTTP.Client as C
import OM.Discovery (connect, withService)

...

let
  name = "my-program" {- the name of this client program. -}
  version = "0.1" {- the version of this client program.  -}
  serviceAddr = "http://ec2-foo-bar.amazon.com:8080" {- the address on which your service is running. -}
in do
  manager <- C.newManager C.defaultManagerSettings
  discovery <- connect name version manager

  withService serviceAddr discovery $ do
    {-
      Your service code here. When this IO block exits (for any reason,
      including exceptions) then the service will unregister itself.
    -}
```