All Projects → smoketurner → dropwizard-consul

smoketurner / dropwizard-consul

Licence: Apache-2.0 License
Dropwizard Consul Bundle

Programming Languages

java
68154 projects - #9 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to dropwizard-consul

meshery-consul
Meshery adapter for Consul
Stars: ✭ 50 (-9.09%)
Mutual labels:  consul
vim-hcl
Syntax highlighting for HashiCorp Configuration Language (HCL)
Stars: ✭ 83 (+50.91%)
Mutual labels:  consul
nomad-consult-ansible-centos
Deploy nomad & consult on centos with ansible
Stars: ✭ 17 (-69.09%)
Mutual labels:  consul
helloworld-web
Hello World web application in 39 different ways in Java
Stars: ✭ 18 (-67.27%)
Mutual labels:  dropwizard
dropwizard-orient-server
Embedded OrientDB server for dropwizard
Stars: ✭ 16 (-70.91%)
Mutual labels:  dropwizard
image-hub
Image Hub is a sample application for exploring WebAssembly modules used as Envoy filters.
Stars: ✭ 56 (+1.82%)
Mutual labels:  consul
fm.consulinterop
a lib for build micro-service
Stars: ✭ 33 (-40%)
Mutual labels:  consul
Study.Microservices
一步一步,由浅入深,学习如何使用.net core搭建微服务框架。
Stars: ✭ 18 (-67.27%)
Mutual labels:  consul
super-duper-vault-train
🚄▼▼▼▼▼▼
Stars: ✭ 19 (-65.45%)
Mutual labels:  consul
consul-envoy
Consul to Envoy API listener
Stars: ✭ 35 (-36.36%)
Mutual labels:  consul
Distributed-eStore
Ecommerce SPA application with a microservices architecture implemented from scratch. Tech stack - Docker, Consul, Fabio, RabbitMQ, .Net Core, Mediatr, CQRS, React, Redux. .NET Core Microservices template, .NET React Redux, .NET RabbitMQ, .NET Distributed, Docker, .NET Core with Docker.
Stars: ✭ 99 (+80%)
Mutual labels:  consul
dropwizard-mongo
A Dropwizard bundle for MongoDB
Stars: ✭ 20 (-63.64%)
Mutual labels:  dropwizard
droptools
Addon bundle for Dropwizard to support jOOQ for database access
Stars: ✭ 78 (+41.82%)
Mutual labels:  dropwizard
tuggle
Distributed file mirroring proxy in Consul cluster
Stars: ✭ 16 (-70.91%)
Mutual labels:  consul
ms2consul demo
python微服务,注册到consul的demo
Stars: ✭ 35 (-36.36%)
Mutual labels:  consul
docker vault
Docker + Consul + Vault
Stars: ✭ 34 (-38.18%)
Mutual labels:  consul
verify-service-provider
👑 ☑️ The easiest way to connect to GOV.UK Verify
Stars: ✭ 15 (-72.73%)
Mutual labels:  dropwizard
kotlin-dropwizard
Getting Started with Dropwizard and Kotlin
Stars: ✭ 43 (-21.82%)
Mutual labels:  dropwizard
service-mesh-labs
Lab scenarios for learning how to service mesh.
Stars: ✭ 22 (-60%)
Mutual labels:  consul
meshery-operator
The service mesh operator.
Stars: ✭ 41 (-25.45%)
Mutual labels:  consul

Dropwizard Consul Bundle

Build Status Maven Central GitHub license Become a Patron

A bundle for using Consul in Dropwizard applications. Features:

  • Integrated client-side load balancer based on Ribbon
  • Dropwizard health check that monitors reachablility of Consul
  • The Dropwizard service is registered as a Consul service with a Consul-side health check querying the Dropwizard health check
  • Ability to resolve configuration properties from Consul's KV store
  • Admin task to toggle Consul's maintenance mode

Dependency Info

<dependency>
    <groupId>com.smoketurner.dropwizard</groupId>
    <artifactId>consul-core</artifactId>
    <version>2.0.7-1</version>
</dependency>
<dependency>
    <groupId>com.smoketurner.dropwizard</groupId>
    <artifactId>consul-ribbon</artifactId>
    <version>2.0.7-1</version>
</dependency>

Usage

Add a ConsulBundle to your Application class.

@Override
public void initialize(Bootstrap<MyConfiguration> bootstrap) {
    // ...
    bootstrap.addBundle(new ConsulBundle<MyConfiguration>(getName()) {
        @Override
        public ConsulFactory getConsulFactory(MyConfiguration configuration) {
            return configuration.getConsulFactory();
        }
    });
}

The bundle also includes a ConsulSubsitutor to retrieve configuration values from the Consul KV store. You can define settings in your YAML configuration file:

template: ${helloworld/template:-Hello, %s!}
defaultName: ${helloworld/defaultName:-Stranger}

The setting with the path helloworld/template will be looked up in the KV store and will be replaced in the configuration file when the application is started. You can specify a default value after the :-. This currently does not support dynamically updating values in a running Dropwizard application.

Configuration

For configuring the Consul connection, there is a ConsulFactory:

consul:
  # Optional properties
  # endpoint for consul (defaults to localhost:8500)
  endpoint: localhost:8500
  # service port
  servicePort: 8080
  # check interval frequency
  checkInterval: 1 second

Example Application

This bundle includes a modified version of the HelloWorldApplication from Dropwizard's Getting Started documentation.

You can execute this application by first starting Consul on your local machine then running:

mvn clean package
java -jar consul-example/target/consul-example-2.0.7-4-SNAPSHOT.jar server consul-example/hello-world.yml

This will start the application on port 8080 (admin port 8180). This application demonstrations the following Consul integration points:

  • The application is registered as a service with Consul (with the service port set to the applicationConnectors port in the configuration file.
  • The application will lookup any variables in the configuration file from Consul upon startup (it defaults to connecting to a Consul agent running on localhost:8500 for this functionality)
  • The application exposes an additional HTTP endpoint for querying Consul for available healthy services:
curl -X GET localhost:8080/consul/hello-world -i
HTTP/1.1 200 OK
Date: Mon, 25 Jan 2016 03:42:10 GMT
Content-Type: application/json
Vary: Accept-Encoding
Content-Length: 870

[
    {
        "Node": {
            "Node": "mac",
            "Address": "192.168.1.100",
            "Datacenter": "dc1",
            "TaggedAddresses": {
                "wan": "192.168.1.100",
                "lan": "192.168.1.100"
            },
            "Meta": {
                "consul-network-segment": ""
            }
        },
        "Service": {
            "ID": "test123",
            "Service": "hello-world",
            "EnableTagOverride": false,
            "Tags": [],
            "Address": "",
            "Meta": {
                "scheme": "http"
            },
            "Port": 8080,
            "Weights": {
                "Passing": 1,
                "Warning": 1
            }
        },
        "Checks": [
            {
                "Node": "mac",
                "CheckID": "serfHealth",
                "Name": "Serf Health Status",
                "Status": "passing",
                "Notes": "",
                "Output": "Agent alive and reachable",
                "ServiceID": "",
                "ServiceName": "",
                "ServiceTags": []
            },
            {
                "Node": "mac",
                "CheckID": "service:test123",
                "Name": "Service 'hello-world' check",
                "Status": "passing",
                "Notes": "",
                "Output": "HTTP GET http:\/\/127.0.0.1:8180\/healthcheck: 200 OK Output: {\"consul\":{\"healthy\":true},\"deadlocks\":{\"healthy\":true}}",
                "ServiceID": "test123",
                "ServiceName": "hello-world",
                "ServiceTags": []
            }
        ]
    }
]
  • The application will periodically checkin with Consul every second to notify the service check that it is still alive
  • Upon shutdown, the application will deregister itself from Consul

Credits

This bundle was inspired by an older bundle (Dropwizard 0.6.2) that Chris Gray created at https://github.com/chrisgray/dropwizard-consul. I also incorporated the configuration provider changes from https://github.com/remmelt/dropwizard-consul-config-provider

Support

Please file bug reports and feature requests in GitHub issues.

License

Copyright (c) 2020 Smoke Turner, LLC

This library is licensed under the Apache License, Version 2.0.

See http://www.apache.org/licenses/LICENSE-2.0.html or the LICENSE file in this repository for the full license text.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].