This example includes two maven modules:
-
services that exposes a number of services
-
consumer that consumes services
The consumer is configured in the src/main/resources/application.properties in which we blacklist some services for being discovered and we add some additional services not managed by consul
# Configure service filter camel.cloud.service-filter.blacklist[service-1] = localhost:9012
# Configure additional services camel.cloud.service-discovery.services[service-2] = localhost:9021,localhost:9022,localhost:9023
Using multiple shells:
-
start consul:
$ cd services $ src/main/bash/consul-run-linux.sh (for linux) $ src/main/bash/consul-run-osx.sh (for mac osx)
-
start the service-1 service group:
$ cd services $ mvn spring-boot:run -Dspring-boot.run.profiles=service-1
-
start the service-2 service group:
$ cd services $ mvn spring-boot:run -Dspring-boot.run.profiles=service-2
-
start the consumer
$ cd consumer $ mvn spring-boot:run
In a new shell:
$ curl localhost:8080/camel/serviceCall/service1 Hi!, I'm service-1 on camel-1/route1 $ curl localhost:8080/camel/serviceCall/service2 Hi!, I'm service-1 on camel-1/route2
If you keep calling the http endpoint you’ll notice they are consumed using a round robin policy and that one of the services registered in consul is not taken into account according to the blacklist.
You can open the Consul web console
http://localhost:8500/ui
Where you can find information about the services and its state.
If you hit any problem using Camel or have some feedback, then please let us know.
We also love contributors, so get involved :-)
The Camel riders!