NOTICE: THIS IS A DRAFT
The publisher publishes endpoint details for services to "the cloud". The configurator reads those details from "the cloud" and dynamically forwards to those services
In this example we will start a self-publishing service that responds with "hello" that can be called from another service without knowledge of the endpoint
-
Download etcd: go to "https://github.com/coreos/etcd/releases/", scroll down to the "Downloads" section and pick the version for your operating system
-
Extract etcd in any directory and start etcd
-
In the membrane folder go to
examples/service-discovery-with-etcd/
-
Execute
configurator/start.bat
-
Open your favorite browser and go to
localhost:9001
, this opens the admin console of the configurator -
Notice that "Console" is the only available service, "Console" is the admin console
-
Execute the
publisher/start.bat
-
Open another tab in your browser and go to
localhost:8081/myService
and receive "hello" as response, this is a service from the publisher -
Go back to the admin console window and refresh the page, another service should appear
-
Open another tab in your browser and go to
localhost:8080/myService
and receivehello
as response, this is a service from the configurator -
Exit the
publisher.bat
and wait 20 seconds. -
Go back to the admin console window and refresh the page, the second service should disappear
This section describes the example in detail.
First take a look at the proxies.xml
file in the publisher folder.
<etcdPublisher baseUrl="http://localhost:4001" baseKey="/example" ttl="20"/>
<router>
<serviceProxy name="helloResponse" port="8081">
<path>/myService</path>
<groovy>
exc.response = Response.ok("Hello").build()
RETURN
</groovy>
</serviceProxy>
</router>
You will see that there is a service proxy that responds with hello
when going to http://localhost:8081 in you browser. On top of that you can see the <etcdPublisher>
that is responsible for publishing the endpoint details to an etcd.
The <etcdPublisher>
element has 3 values that you can set and by default it is set to publish to a locally started etcd on "http://localhost:4001" every 5 minutes.
baseUrl
is the url the etcd is residing onbaseKey
is the directory where the endpoint details are savedttl
is how long in seconds the data in the etcd should be valid
Now take a look at the proxies.xml
file in the configurator folder.
<etcdBasedConfigurator baseUrl="http://localhost:4001" baseKey="/example" port="8080"/>
<router>
<transport/>
<serviceProxy name="Console" port="9001">
<adminConsole />
</serviceProxy>
</router>
You will see a service proxy that provides the admin console on port 9001
. Additionally, on top you can see the etcdBasedConfigurator that reads from an etcd and creates service proxies for those services dynamically.
The etcdBasedConfigurator
has 3 values that you can set and by default it is set to read from an etcd on http://localhost:4001 and provides its service on port 8080
.
baseUrl
is the url the etcd is residing onbaseKey
is the directory where the call details are savedport
is the port theetcdBasedConfigurator
provides its service on
See:
- etcdBasedConfigurator reference
- etcdPublisher reference