Fork me on GitHub

Examples - REST client/server and Discovery

Running the example

The example consists of 4 separate applications:

  • mock-database
  • mock-zookeeper
  • goodbye
  • hello

You will run 1 instance of mock-database and mock-zookeeper. You can run multiple versions of goodbye. For example purposes, run at least 2. Lastly, run one instance of hello.

From the soabase directory (assuming a *nix system):

# Run the mock database in the background
java -jar ./target/mock-database.jar &

# Run the mock zookeeper in the background
java -jar ./target/mock-zookeeper.jar &

# Run 2 instances of the goodbye app in the background
java -jar ./target/goodbye.jar &
java -jar ./target/goodbye.jar &

# Run the hello app in the background
java -jar ./target/hello.jar &
# You will see output that shows the ports for the hello app - save these

Performing the example tasks

curl http://localhost:HelloMainPort/hello

This will make an HTTP/REST call to the Hello app. The Hello app will then use Discovery to query a Goodbye app instance. The Hello app will then return the Goodbye app's result plus its own. You will see the Hello app's instance name and service name. You will also see one of the Goodbye app's instance names. If you execute the REST call again you should see a different Goodbye app instance. The default load balancer is round robin so each REST call should cycle through all the Goodbye apps.

This example shows the following features:

Discovery Integration Soabase automatically registers services with the Sobase Discovery system.
Integrated REST Client Soabase wraps both the Apache HTTP Client and the Jersey Client so that they are integrated with Soabase's Discovery system. The URL used is //0.goodbye/goodbye. Soabase will see the "0.name" pattern and replace this by looking up the service in the Discovery system. If the call fails, it will get retried via a new lookup from the Discovery system.
Request Id In an SOA system, a single external user request will result in many internal service calls. A method for tying all of them together back to the original request is vital. Sobase adds a Request Id header which the wrapped REST Clients are aware of. In the example you see that the Hello app's REST call to the Goodbye app maintained the same Request Id.