SlideShare a Scribd company logo
Service Oriented Architecture
with Consul
Rajesh Sharma
@broncha
VantageBit
Soa with consul
Problems when you scale a
SOA/microservices
Host resolution (service discovery)
Con guration updates
Solutions
Apache zookeeper
etcd
doozerd
consul
Consul
It is a tool for discovering and con guring services in
your infrastructure, with features like
Service Discovery
Health Checking
Key/Value Store
Installation
Just download a binary le and you are good to go.
Con guration
Server nodes
con g.json
{
"server": true,
"data_dir": "/var/consul",
"encrypt": "2346rxJm2aFuMNxWCKWnvPBA==",
"log_level": "INFO",
"enable_syslog": true,
"bind_addr": "172.31.0.195",
"start_join": ["172.31.12.223", "172.31.28.140"],
"ui": true
}
Client nodes
con g.json
{
"server": false,
"data_dir": "/var/consul",
"encrypt": "2346rxJm2aFuMNxWCKWnvPBA==",
"log_level": "INFO",
"enable_syslog": true,
"bind_addr": "172.31.21.186",
"start_join": ["172.31.28.140","172.31.12.223","172.31.0.195
}
services.json
{
"services": [
{
"id": "application@ip-172-31-21-186",
"name": "application",
"address": "172.31.21.186",
"port": 8080,
"checks": [
{
"name": "Application/Apache on port 8080",
"tcp": "localhost:8080",
"interval": "10s",
"timeout": "1s"
}
]
}
]
}
The HTTP Interface
Catalog API
/v1/catalog/nodes
[
{
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "baz",
"Address": "10.1.10.11",
"TaggedAddresses": {
"lan": "10.1.10.11",
"wan": "10.1.10.11"
},
"Meta": {
"instance_type": "t2.medium"
}
} ...
]
/v1/catalog/services
{
"consul": [],
"redis": [],
"postgresql": [
"primary",
"secondary"
]
}
/v1/catalog/service/<service>
[
{
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"Address": "192.168.10.10",
"Meta": {
"instance_type": "t2.medium"
},
"CreateIndex": 51,
"ModifyIndex": 51,
"ServiceAddress": "172.17.0.3",
"ServiceEnableTagOverride": false,
"ServiceID": "32a2a47f7992:nodea:5000",
"ServiceName": "foobar",
"ServicePort": 5000,
"ServiceTags": [
"tacos"
]
}
/v1/catalog/node/<node>
{
"Node": {
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"Address": "10.1.10.12"
},
"Services": {
"consul": {
"ID": "consul",
"Service": "consul",
"Port": 8300
},
"redis": {
"ID": "redis",
"Service": "redis",
"Tags": [
"v1"
],
"Port": 6379
Health Check API
/v1/health/node/<node>
[
{
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"CheckID": "serfHealth",
"Name": "Serf Health Status",
"Status": "passing",
"Notes": "",
"Output": "",
"ServiceID": "",
"ServiceName": ""
},
{
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"CheckID": "service:redis",
"Name": "Service 'redis' check",
"Status": "passing",
"Notes": "",
/v1/health/checks/<service>
[
{
"Node": "foobar",
"CheckID": "service:redis",
"Name": "Service 'redis' check",
"Status": "passing",
"Notes": "",
"Output": "",
"ServiceID": "redis",
"ServiceName": "redis"
}
]
/v1/health/service/<service>
[
{
"Node": {
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"Address": "10.1.10.12"
},
"Service": {
"ID": "redis",
"Service": "redis",
"Tags": null,
"Address": "10.1.10.12",
"Port": 6379
},
"Checks": [
{
"Node": "foobar",
"CheckID": "service:redis",
"Name": "Service 'redis' check",
/v1/health/service/<service>?passing
[
{
"Node": {
"ID": "40e4a748-2192-161a-0510-9bf59fe950b5",
"Node": "foobar",
"Address": "10.1.10.12"
},
"Service": {
"ID": "redis",
"Service": "redis",
"Tags": null,
"Address": "10.1.10.12",
"Port": 6379
},
"Checks": [
{
"Node": "foobar",
"CheckID": "service:redis",
"Name": "Service 'redis' check",
The Key-Value Store API
GET /v1/kv/<key>
[
{
"CreateIndex": 100,
"ModifyIndex": 200,
"LockIndex": 200,
"Key": "zip",
"Flags": 0,
"Value": "dGVzdA==",
"Session": "adf4238a-882b-9ddc-4a9d-5b6758e4159e"
}
]
PUT /v1/kv/<key>
DELETE /v1/kv/<key>
The DNS Interface
Instead of making HTTP API requests to Consul, a
host can use the DNS server directly via name
lookups
redis.service.us-east-1.consul
master.rabbitmq.service.us-east-1.consul
slave.redis.service.consul
Consul will listen on 127.0.0.1:8600 for DNS
queries in the consul. domain
We can use dnsmasq to route DNS queries for
consul. domains to 127.0.0.1:8600
Unhealthy nodes are automatically ltered
Node Lookups
<node>.node[.datacenter].<domain>
$ dig @127.0.0.1 -p 8600 foo.node.consul ANY
; <<>> DiG 9.8.3-P1 <<>> @127.0.0.1 -p 8600 foo.node.consul ANY
; (1 server found)
;; truncating comment sections for brevity
;; QUESTION SECTION:
;foo.node.consul. IN ANY
;; ANSWER SECTION:
foo.node.consul. 0 IN A 10.1.10.12
;; AUTHORITY SECTION:
consul. 0 IN SOA ns.consul. postmaster.consul. 139283
Service Lookups
[tag.]<service>.service[.datacenter].<domain>
$ dig master.redis.service.consul
; <<>> DiG 9.10.3-P4-Ubuntu <<>> master.redis.service.consul
;; truncating comment sections for brevity
;; QUESTION SECTION:
;master.redis.service.consul. IN A
;; ANSWER SECTION:
master.redis.service.consul. 0 IN A 172.31.28.140
;; Query time: 2 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Wed Feb 01 10:36:28 UTC 2017
;; MSG SIZE rcvd: 88
Distributed lock and Leader
election
Pick a key
service/<servicename>/leader`
Create a session
$ curl -X PUT -d '{"Name": "rabbitmq-service"}' 
http://localhost:8500/v1/session/create
# response
{
"ID": "4ca8e74b-6350-7587-addf-a18084928f3c"
}
Acquire a session for given key
$ curl -X PUT -d <body> 
http://localhost:8500/v1/kv/<key>?acquire=<session>
If return value is true key was acquired and this
node is the leader
Else some other node already acquired that key
and is the leader
Other nodes can discover the leader node using
the session info API
$ curl http://localhost:8500/v1/kv/<key>
[
{
"Session": "4ca8e74b-6350-7587-addf-a18084928f3c",
"Value": "Ym9keQ==",
"Flags": 0,
"Key": "<key>",
"LockIndex": 1,
"ModifyIndex": 29,
"CreateIndex": 29
}
]
If the key has no associated Session, then there is
no leader
The nodes would be watching the key to check if it
was released and try to become the leader
$ curl 
http://localhost:8500/v1/session/info/4ca8e74b-6350-7587-addf-a1
[
{
"LockDelay": 1.5e+10,
"Checks": [
"serfHealth"
],
"Node": "consul-primary-bjsiobmvdij6-node-lhe5ihreel7y"
"Name": "dbservice",
"ID": "4ca8e74b-6350-7587-addf-a18084928f3c",
"CreateIndex": 28
}
]
Questions?

More Related Content

PDF
PostgreSQL High-Availability and Geographic Locality using consul
PDF
Codified PostgreSQL Schema
PDF
Modern tooling to assist with developing applications on FreeBSD
ODP
Getting started with RDO Havana
PDF
Production Readiness Strategies in an Automated World
TXT
Juniper Srx Log
PPTX
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
PDF
Dynamic Database Credentials: Security Contingency Planning
PostgreSQL High-Availability and Geographic Locality using consul
Codified PostgreSQL Schema
Modern tooling to assist with developing applications on FreeBSD
Getting started with RDO Havana
Production Readiness Strategies in an Automated World
Juniper Srx Log
Nagios Conference 2014 - Rob Hassing - How To Maintain Over 20 Monitoring App...
Dynamic Database Credentials: Security Contingency Planning

What's hot (20)

PPTX
LinkRest at JeeConf 2017
PDF
Top Node.js Metrics to Watch
PDF
Incrementalism: An Industrial Strategy For Adopting Modern Automation
PDF
4Developers: Dns vs webapp
PPTX
It's 10pm: Do You Know Where Your Writes Are?
PDF
Unity Makes Strength
PDF
Static Typing in Vault
PDF
Altitude SF 2017: Advanced VCL: Shielding and Clustering
PDF
Bootstrapping multidc observability stack
PPTX
Vault - Secret and Key Management
PDF
HTTP For the Good or the Bad
PDF
Docker Monitoring Webinar
PDF
Bootstrapping multidc observability stack
PPTX
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
PDF
Altitude SF 2017: Debugging Fastly VCL 101
PDF
Observability with Consul Connect
PPT
Pyrax talk
PDF
Lua tech talk
PDF
Roll Your Own API Management Platform with nginx and Lua
PPTX
ProxySQL & PXC(Query routing and Failover Test)
LinkRest at JeeConf 2017
Top Node.js Metrics to Watch
Incrementalism: An Industrial Strategy For Adopting Modern Automation
4Developers: Dns vs webapp
It's 10pm: Do You Know Where Your Writes Are?
Unity Makes Strength
Static Typing in Vault
Altitude SF 2017: Advanced VCL: Shielding and Clustering
Bootstrapping multidc observability stack
Vault - Secret and Key Management
HTTP For the Good or the Bad
Docker Monitoring Webinar
Bootstrapping multidc observability stack
Vulnerability intelligence with vulners.com / Кирилл Ермаков, Игорь Булатенко...
Altitude SF 2017: Debugging Fastly VCL 101
Observability with Consul Connect
Pyrax talk
Lua tech talk
Roll Your Own API Management Platform with nginx and Lua
ProxySQL & PXC(Query routing and Failover Test)
Ad

Viewers also liked (20)

PDF
JEE on DC/OS
PDF
Simple REST with Dropwizard
PDF
Production Ready Web Services with Dropwizard
PDF
Dropwizard Spring - the perfect Java REST server stack
PDF
Dropwizard and Groovy
PPTX
Dropwizard Introduction
PDF
WildFly Swarm: Criando Microservices com Java EE 7
PDF
Simple REST-APIs with Dropwizard and Swagger
PDF
Dropwizard
PDF
ESB integration for node.js
PPTX
J1 2015 "Building a Microservice Ecosystem: Some Assembly Still Required"
PDF
Cloud Native Microservices with Spring Cloud
PDF
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
ODP
Microservice Architecture JavaCro 2015
PDF
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
PPTX
Building REST APIs with Spring Boot and Spring Cloud
PDF
Microservices - java ee vs spring boot and spring cloud
PDF
Service discovery in a microservice architecture using consul
PDF
Power, patterns and pains of microservices
PDF
DockerCon SF 2015: Enabling Microservices @Orbitz
JEE on DC/OS
Simple REST with Dropwizard
Production Ready Web Services with Dropwizard
Dropwizard Spring - the perfect Java REST server stack
Dropwizard and Groovy
Dropwizard Introduction
WildFly Swarm: Criando Microservices com Java EE 7
Simple REST-APIs with Dropwizard and Swagger
Dropwizard
ESB integration for node.js
J1 2015 "Building a Microservice Ecosystem: Some Assembly Still Required"
Cloud Native Microservices with Spring Cloud
promgen - prometheus managemnet tool / simpleclient_java hacks @ Prometheus c...
Microservice Architecture JavaCro 2015
Spring IO 2016 - Spring Cloud Microservices, a journey inside a financial entity
Building REST APIs with Spring Boot and Spring Cloud
Microservices - java ee vs spring boot and spring cloud
Service discovery in a microservice architecture using consul
Power, patterns and pains of microservices
DockerCon SF 2015: Enabling Microservices @Orbitz
Ad

Similar to Soa with consul (20)

PPTX
Service Discovery Like a Pro
PDF
Getting Started with Consul
PDF
Consul First Steps
PDF
Consul: Service Mesh for Microservices
PPTX
Intro to Consul
PDF
Service discovery like a pro (presented at reversimX)
PDF
OCP with super tengen toppa
PPTX
Discover/Register Everything in consul
PDF
Consul and docker swarm cluster
PDF
(Re)discover your AEM
PDF
Introduction to Consul
PDF
Consul tutorial
PDF
20190727 HashiCorp Consul Workshop: 管管你們家 config 啦
PDF
Consul: Microservice Enabling Microservices and Reactive Programming
PDF
Consul administration at scale
PDF
HashiStack. To the cloud and beyond...
PDF
Infrastructure development using Consul
PDF
Consul - service discovery and others
PDF
Workshop Consul .- Service Discovery & Failure Detection
PPTX
Service Discovery with Consul - Arunvel Arunachalam
Service Discovery Like a Pro
Getting Started with Consul
Consul First Steps
Consul: Service Mesh for Microservices
Intro to Consul
Service discovery like a pro (presented at reversimX)
OCP with super tengen toppa
Discover/Register Everything in consul
Consul and docker swarm cluster
(Re)discover your AEM
Introduction to Consul
Consul tutorial
20190727 HashiCorp Consul Workshop: 管管你們家 config 啦
Consul: Microservice Enabling Microservices and Reactive Programming
Consul administration at scale
HashiStack. To the cloud and beyond...
Infrastructure development using Consul
Consul - service discovery and others
Workshop Consul .- Service Discovery & Failure Detection
Service Discovery with Consul - Arunvel Arunachalam

Recently uploaded (20)

PDF
Encapsulation theory and applications.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Modernizing your data center with Dell and AMD
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
cuic standard and advanced reporting.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
KodekX | Application Modernization Development
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Electronic commerce courselecture one. Pdf
PPT
Teaching material agriculture food technology
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
A Presentation on Artificial Intelligence
PDF
Machine learning based COVID-19 study performance prediction
PDF
Chapter 3 Spatial Domain Image Processing.pdf
Encapsulation theory and applications.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Modernizing your data center with Dell and AMD
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Empathic Computing: Creating Shared Understanding
Encapsulation_ Review paper, used for researhc scholars
cuic standard and advanced reporting.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
The AUB Centre for AI in Media Proposal.docx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Spectral efficient network and resource selection model in 5G networks
KodekX | Application Modernization Development
NewMind AI Weekly Chronicles - August'25 Week I
Electronic commerce courselecture one. Pdf
Teaching material agriculture food technology
Understanding_Digital_Forensics_Presentation.pptx
A Presentation on Artificial Intelligence
Machine learning based COVID-19 study performance prediction
Chapter 3 Spatial Domain Image Processing.pdf

Soa with consul