Automatic Service Registration

293 views
Skip to first unread message

Raymond Vargas

unread,
Dec 3, 2014, 9:40:18 AM12/3/14
to consu...@googlegroups.com
Hey Guys,

I'm exploring the use of Consul as a service registry in an enterprise Java project. This project will see multiple micro apps coming online and offline at various points in time. My question is, what does automatic service registration look like in consul, so that multiple applications are aware of where each one is located? From the material that I have read, it seems like in order to add an application to the consul service discovery system, an operator has to do it through the CLI. Can somebody walk me through how an application will just register itself when it comes online?

Thanks!

Alvaro Miranda

unread,
Dec 3, 2014, 12:35:37 PM12/3/14
to Raymond Vargas, consu...@googlegroups.com
hello

i am on my phone so cant search, but wanted to tell you that someone did a java library that you may want to have a look

as for your question, a simple example would be an app that use dns since is fair simple

each node, say clients will show up as

<node>.node.<dc>.consul

when you register a service will become available as

<service>.service.<dc>.consul

the more you add the more will came in the dns reply, one entry with several ip

so if you have 4 web and 2 databases



and thats is, each client need to just use those dns entries and the load will be sent to the nodes providing those services

if you add a check, only health services will be part of those services, so you stop/aviod sending traffic to the non-working node

too basic?
--
You received this message because you are subscribed to the Google Groups "Consul" group.
To unsubscribe from this group and stop receiving emails from it, send an email to consul-tool...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Armon Dadgar

unread,
Dec 3, 2014, 2:09:13 PM12/3/14
to Raymond Vargas, consu...@googlegroups.com
Hey Raymond,

There are a few options here. One strategy is the file based registration with Consul.
You create a service definition file (https://consul.io/docs/agent/services.html) and place
it inside a configuration dir (for example /etc/consul.d/redis.json). Consul will then pickup
that service on start, or with a reload. This method is very simple to integrate with configuration
management tools, since they can generate the file and trigger a reload.

Another option is to use the Consul HTTP API via a client. In this scenario, client applications
have to be aware of Consul. They need code to support registration on start. However,
that is usually a simple matter of calling the Agent.ServiceRegister (http://godoc.org/github.com/armon/consul-api#Agent.ServiceRegister)
or equivalent method of the client library.

One great Java specific client is the one made by Orbitz: https://github.com/OrbitzWorldwide/consul-client

Hope that helps!

Best Regards,
Armon Dadgar

Raymond Vargas

unread,
Dec 3, 2014, 2:32:32 PM12/3/14
to consu...@googlegroups.com, vargasr...@gmail.com
Thank you Armon, 

These are great suggestions for me to begin looking into as I begin learning about everything Consul has to offer. 


On Wednesday, December 3, 2014 2:09:13 PM UTC-5, Armon Dadgar wrote:
Hey Raymond,

There are a few options here. One strategy is the file based registration with Consul.
You create a service definition file (https://consul.io/docs/agent/services.html) and place
it inside a configuration dir (for example /etc/consul.d/redis.json). Consul will then pickup
that service on start, or with a reload. This method is very simple to integrate with configuration
management tools, since they can generate the file and trigger a reload.

Another option is to use the Consul HTTP API via a client. In this scenario, client applications
have to be aware of Consul. They need code to support registration on start. However,
that is usually a simple matter of calling the Agent.ServiceRegister (http://godoc.org/github.com/armon/consul-api#Agent.ServiceRegister)
or equivalent method of the client library.

One great Java specific client is the one made by Orbitz: https://github.com/OrbitzWorldwide/consul-client

Hope that helps!

Best Regards,
Armon Dadgar
Reply all
Reply to author
Forward
0 new messages