{"id":13682465,"url":"https://github.com/bitsofinfo/hazelcast-consul-discovery-spi","last_synced_at":"2025-04-13T06:31:58.773Z","repository":{"id":55544533,"uuid":"46591357","full_name":"bitsofinfo/hazelcast-consul-discovery-spi","owner":"bitsofinfo","description":"Consul based discovery strategy SPI for Hazelcast enabled applications","archived":false,"fork":false,"pushed_at":"2022-09-07T14:56:00.000Z","size":1003,"stargazers_count":47,"open_issues_count":5,"forks_count":22,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-03-26T23:04:31.293Z","etag":null,"topics":["consul","hazelcast","service-discovery"],"latest_commit_sha":null,"homepage":"https://bitsofinfo.wordpress.com/2015/11/20/hazelcast-discovery-with-consul/","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bitsofinfo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-11-20T22:57:35.000Z","updated_at":"2022-11-08T02:24:01.000Z","dependencies_parsed_at":"2022-08-15T02:50:59.298Z","dependency_job_id":null,"html_url":"https://github.com/bitsofinfo/hazelcast-consul-discovery-spi","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fhazelcast-consul-discovery-spi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fhazelcast-consul-discovery-spi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fhazelcast-consul-discovery-spi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bitsofinfo%2Fhazelcast-consul-discovery-spi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bitsofinfo","download_url":"https://codeload.github.com/bitsofinfo/hazelcast-consul-discovery-spi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248674658,"owners_count":21143760,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consul","hazelcast","service-discovery"],"created_at":"2024-08-02T13:01:46.398Z","updated_at":"2025-04-13T06:31:58.723Z","avatar_url":"https://github.com/bitsofinfo.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"# hazelcast-consul-discovery-spi\n\n[![Build Status](https://travis-ci.org/bitsofinfo/hazelcast-consul-discovery-spi.svg?branch=master)](https://travis-ci.org/bitsofinfo/hazelcast-consul-discovery-spi)\n\nProvides a Consul based discovery strategy for Hazlecast 3.6+ enabled applications.\nThis is an easy to configure plug-and-play Hazlecast DiscoveryStrategy that will optionally register each of your Hazelcast instances with Consul and enable Hazelcast nodes to dynamically discover one another via Consul. \n\nSee \"releases\" below for important compatibility details with different version of Hazelcast.\n\n* [Status](#status)\n* [Releases](#releases)\n* [Requirements](#requirements)\n* [Maven/Gradle install](#mavengradle)\n* [Features](#features)\n* [Usage](#usage)\n* [Build from source](#building)\n* [Unit tests](#tests)\n* [Related Info](#related)\n* [Todo](#todo)\n* [Notes](#notes)\n* [Docker info](#docker)\n* [Consul ACL issues?](#consul)\n\n![Diagram of hazelcast consul discovery strategy](/docs/diag.png \"Diagram2\")\n\n## \u003ca id=\"status\"\u003e\u003c/a\u003eStatus\n\nThis is release candidate code, tested against Hazelcast 3.6-EA+ through 3.9.x and 4.x stable releases, as well as Consul 0.7.x up to 1.0.x.\n\n**IMPORTANT:**: Do not rely on JCenter/Bintray anymore! Update your gradle/maven dependencies to use Maven Central: https://search.maven.org/search?q=g:org.bitsofinfo\n\n## \u003ca id=\"releases\"\u003e\u003c/a\u003eReleases\n\n\n### Hazelcast compatibility\n\n* For Hazelcast \u003e= 4.0 you should use [2.0-RC1+](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/2.0-RC1)\n  \n* For Hazelcast \u003c= 3.x you should use [1.0-RC9 or below](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC9)\n\n\n### Release history\n\n* MASTER - in progress, this README refers to what is in the master tag. Switch to relevant RELEASE tag above to see that versions README\n\n* **2.0-RC1-20210205**: Same as 2.0-RC1 but made compliant for Maven Central due to JCenter/Bintray closure. \n\n* [2.0-RC1](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/2.0-RC1): PR #33 #34 Compat updates for Hazelcast 4.x thanks @amrsamii. **REQUIRES HAZELCAST 4.x+, will not work with Hazelcast \u003c= 3.x**\n\n* **1.0-RC9-20210205**: Same as 1.0-RC9 but made compliant for Maven Central due to JCenter/Bintray closure. Also explicity defined hazelcast dependency 3.10.4\n\n* [1.0-RC9](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC9): PR #28 #29 (consul health script fixes) for #27\n\n* [1.0-RC8](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC8): Tweaks for Consul 0.8+ (health check sample script change). consul-client upgrade to 0.17.1; build.gradle HZ `3.+` dependency. Address post Consul 0.8 ACL notes (in README) for [#26]\n\n* [1.0-RC7](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC7): consul-client 0.13.12; Fix [#17] with PR https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/pull/18\n\n* [1.0-RC6](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC6): Fix [#12], consul-client 0.13.2 upgrade, fix base64 Java 8 issue. Tested against Hazelcast 3.6-EA+ through 3.7+ Stable releases\n\n* [1.0-RC5](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC5): Upgrade to latest consul-client [#11](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/issues/11) Tested against Hazelcast 3.6-EA+ through 3.6.4+ Stable releases\n\n* [1.0-RC4](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC4): Adds support for TCP/HTTP checks [#3](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/issues/3) Tested against Hazelcast 3.6-EA+ through 3.6 Stable releases\n\n* [1.0-RC3](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC3): Adds support for TLS [#2](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/issues/2) and Consul ACLs [#4](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/issues/4) Tested against Hazelcast 3.6-EA+ through 3.6 Stable releases\n\n* [1.0-RC2](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC2): Tested against Hazelcast 3.6-EA+ through 3.6 Stable releases\n\n* [1.0-RC1](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC1): Tested against Hazelcast 3.6-EA+ through 3.6-RC1 Stable releases\n\n## \u003ca id=\"requirements\"\u003e\u003c/a\u003eRequirements\n\n* Java 6+\n* [Hazelcast 3.6+](https://hazelcast.org/)\n* [Consul](https://consul.io/)\n\n## \u003ca id=\"mavengradle\"\u003e\u003c/a\u003eMaven/Gradle\n\nTo use this discovery strategy in your Maven or Gradle project use the dependency samples below.\n\n### Gradle:\n\n```\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n\tcompile 'org.bitsofinfo:hazelcast-consul-discovery-spi:2.0-RC1-20210205'\n\n    // include your preferred javax.ws.rs-api implementation\n    // (for the OrbitzWorldwide/consul-client dependency)\n    // for example below:\n    compile 'org.apache.cxf:cxf-rt-rs-client:3.0.3'\n    compile 'org.apache.cxf:cxf-rt-transports-http-hc:3.0.3'\n}\n```\n\n### Maven:\n\n```\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003eorg.bitsofinfo\u003c/groupId\u003e\n        \u003cartifactId\u003ehazelcast-consul-discovery-spi\u003c/artifactId\u003e\n        \u003cversion\u003e2.0-RC1-20210205\u003c/version\u003e\n    \u003c/dependency\u003e\n\n    \u003c!-- include your preferred javax.ws.rs-api\n         (for the https://github.com/OrbitzWorldwide/consul-client dependency)\n         implementation - see gradle example above\n    --\u003e\n\u003c/dependencies\u003e\n```\n\n## \u003ca id=\"features\"\u003e\u003c/a\u003eFeatures\n\n\n* Supports two modes of operation:\n\t* **Read-write**: peer discovery and registration of a hazelcast instance without a local Consul agent (self registration)\n\t* **Read-only**: peer discovery only with an existing Consul agent setup (no registration by the strategy itself)\n\n* If you don't want to use the built in Consul registration, just specify the `DoNothingRegistrator` (see below) in your hazelcast discovery-strategy XML config. This will require you to run your own Consul agent that defines the hazelcast service.\n\n* If using self-registration, either `LocalDiscoveryNodeRegistrator` or `ExplicitIpPortRegistrator` which additionally support:\n    * Automatic registration of the hazelcast instance with Consul\n    * Custom Consul health-check script/interval to validate Hazelcast instance healthly\n    * Control which IP is published as the service-address with Consul\n    * Configurable discovery delay\n    * Automatic Consul de-registration of instance via ShutdownHook\n\n\n## \u003ca id=\"usage\"\u003e\u003c/a\u003eUsage\n\n* Ensure your project has the `hazelcast-consul-discovery-spi` artifact dependency declared in your maven pom or gradle build file as described above. Or build the jar yourself and ensure the jar is in your project's classpath.\n\n* Have Consul running and available somewhere on your network, start it such as:\n```\nconsul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -config-dir /path/to/consul.d/ -ui-dir /path/to/consul-web-ui [-enable-script-checks]\n```\n\n* Configure your hazelcast.xml configuration file to use the `ConsulDiscoveryStrategy` (similar to the below): [See hazelcast-consul-discovery-spi-example.xml](src/main/resources/hazelcast-consul-discovery-spi-example.xml) for a full example with documentation of options.\n\n* Launch your hazelcast instances, configured with the Consul discovery-strategy similar to the below: [see ManualRunner.java](src/test/java/org/bitsofinfo/hazelcast/discovery/consul/ManualRunner.java) example.\n\n```\n\u003cnetwork\u003e\n  \u003cport auto-increment=\"true\"\u003e5701\u003c/port\u003e\n\n  \u003cjoin\u003e\n    \u003cmulticast enabled=\"false\"/\u003e\n    \u003caws enabled=\"false\"/\u003e\n    \u003ctcp-ip enabled=\"false\" /\u003e\n\n     \u003cdiscovery-strategies\u003e\n       \u003cdiscovery-strategy enabled=\"true\"\n           class=\"org.bitsofinfo.hazelcast.discovery.consul.ConsulDiscoveryStrategy\"\u003e\n\n         \u003cproperties\u003e\n              \u003cproperty name=\"consul-host\"\u003elocalhost\u003c/property\u003e\n              \u003cproperty name=\"consul-port\"\u003e8500\u003c/property\u003e\n              \u003cproperty name=\"consul-service-name\"\u003ehz-discovery-test-cluster\u003c/property\u003e\n              \u003cproperty name=\"consul-healthy-only\"\u003etrue\u003c/property\u003e\n              \u003cproperty name=\"consul-service-tags\"\u003ehazelcast, test1\u003c/property\u003e\n              \u003cproperty name=\"consul-discovery-delay-ms\"\u003e10000\u003c/property\u003e\n\n              \u003cproperty name=\"consul-acl-token\"\u003e\u003c/property\u003e\n              \u003cproperty name=\"consul-ssl-enabled\"\u003efalse\u003c/property\u003e\n              \u003cproperty name=\"consul-ssl-server-cert-file-path\"\u003e\u003c/property\u003e\n              \u003cproperty name=\"consul-ssl-server-cert-base64\"\u003e\u003c/property\u003e\n              \u003cproperty name=\"consul-ssl-server-hostname-verify\"\u003etrue\u003c/property\u003e\n\n              \u003cproperty name=\"consul-registrator\"\u003eorg.bitsofinfo.hazelcast.discovery.consul.LocalDiscoveryNodeRegistrator\u003c/property\u003e\n              \u003cproperty name=\"consul-registrator-config\"\u003e\u003c![CDATA[\n    \t\t\t\t\t{\n    \t\t\t\t\t  \"preferPublicAddress\":false,\n    \t\t\t\t\t  \"healthCheckProvider\":\"org.bitsofinfo.hazelcast.discovery.consul.ScriptHealthCheckBuilder\",\n    \t\t\t\t\t  \"healthCheckScript\":\"nc -z #MYIP #MYPORT\",\n    \t\t\t\t\t  \"healthCheckScriptIntervalSeconds\":30,\n    \t\t\t\t\t}\n                  ]]\u003e\u003c/property\u003e\n        \u003c/properties\u003e\n      \u003c/discovery-strategy\u003e\n    \u003c/discovery-strategies\u003e\n\n  \u003c/join\u003e\n\u003c/network\u003e\n```\n* The above example uses a script health check, so don't forget to enable it in consul (see [Consul checks definition](https://www.consul.io/docs/agent/checks.html)).\nYou can also make use of a simple network TCP check, substituting the healthChek properties about with the following:\n\n```\n                \"healthCheckProvider\":\"org.bitsofinfo.hazelcast.discovery.consul.TcpHealthCheckBuilder\",\n                \"healthCheckTcp\":\"#MYIP:#MYPORT\",\n                \"healthCheckTcpIntervalSeconds\":30\n```\n\n* An you can also use the HTTP healthcheck that Hazelcast provides, don't forget to set Hazelcast property 'hazelcast.http.healthcheck.enabled' to true. (see Hazelcast's [Simple HTTP based healthcheck implementation](https://github.com/hazelcast/hazelcast/pull/9284)), substituting the healthChek properties about with the following:\n\n```\n \u003cproperty name=\"hazelcast.http.healthcheck.enabled\"\u003etrue\u003c/property\u003e\n ...\n                \"healthCheckProvider\":\"org.bitsofinfo.hazelcast.discovery.consul.HttpHealthCheckBuilder\",\n                \"healthCheckHttp\":\"http://#MYIP:#MYPORT/hazelcast/health\",\n                \"healthCheckHttpIntervalSeconds\":30,\n```\n\n* Once nodes are joined you can query Consul to see the auto-registration of hazelcast instances works, the service-id's generated etc\n\n`curl http://localhost:8500/v1/catalog/services`\n\n```\n{\n  \"consul\":[],\n  \"hz-discovery-test-cluster\":[\"hazelcast\",\"test1\"],\n  \"web\":[\"rails\"]\n}\n```\n\n`curl http://localhost:8500/v1/catalog/service/hz-discovery-test-cluster`\n\n```\n[\n  {\n    \"Node\":\"myhost1\",\n    \"Address\":\"192.168.0.208\",\n    \"ServiceID\":\"hz-discovery-test-cluster-192.168.0.208-192.168.0.208-5701\",\n    \"ServiceName\":\"hz-discovery-test-cluster\",\n    \"ServiceTags\":[\n      \"hazelcast\",\n      \"test1\"\n    ],\n    \"ServiceAddress\":\"192.168.0.208\",\n    \"ServicePort\":5701\n  },\n  {\n    \"Node\":\"myhost1\",\n    \"Address\":\"192.168.0.208\",\n    \"ServiceID\":\"hz-discovery-test-cluster-192.168.0.208-192.168.0.208-5702\",\n    \"ServiceName\":\"hz-discovery-test-cluster\",\n    \"ServiceTags\":[\n      \"hazelcast\",\n      \"test1\"\n    ],\n    \"ServiceAddress\":\"192.168.0.208\",\n    \"ServicePort\":5702\n  }\n]\n```\n\n## \u003ca id=\"building\"\u003e\u003c/a\u003eBuilding from source\n\n* From the root of this project, build a Jar : `./gradlew assemble`\n\n* Include the built jar artifact located at `build/libs/hazelcast-consul-discovery-spi-[VERSION].jar` in your hazelcast project\n\n* If not already present in your hazelcast application's Maven (pom.xml) or Gradle (build.gradle) dependencies section; ensure that these dependencies are present (versions may vary as appropriate):\n\n```\ncompile group: 'com.orbitz.consul', name: 'consul-client', version:'1.2.3'\ncompile group: 'org.apache.cxf', name:'cxf-rt-rs-client', version:'3.0.3'\ncompile group: 'org.apache.cxf', name:'cxf-rt-transports-http-hc', version:'3.0.3'\n```\n\n## Consul UI example\n\nShowing [LocalDiscoveryNodeRegistrator](src/main/java/org/bitsofinfo/hazelcast/discovery/consul/LocalDiscoveryNodeRegistrator.java) configured hazelcast services with health-checks\n\n![Diagram of consul ui](/docs/consul_ui.png \"Diagram1\")\n\n## \u003ca id=\"tests\"\u003e\u003c/a\u003eUnit-tests\n\nIt may also help you to understand the functionality by checking out and running the unit-tests\nlocated at [src/test/java](src/test/java). **BE SURE TO READ** the comments in the test source files\nas some of the tests require you to setup your local Consul and edit certain files.\n\nFrom the command line you can run `TestExplicitIpPortRegistrator` and `TestLocalDiscoveryNodeRegistrator` unit-tests by invoking the `runTests` task using `gradlew` that runs both tests and displays the result on the console.\n\n```\n$ ./gradlew runTests\n```\n\nThe task above will display output indicating the test has started and whether the test has passed or failed.\n\n###### Sample output for passing test:\n```\norg.bitsofinfo.hazelcast.discovery.consul.TestExplicitIpPortRegistrator \u003e testExplicitIpPortRegistrator STARTED\n\norg.bitsofinfo.hazelcast.discovery.consul.TestExplicitIpPortRegistrator \u003e testExplicitIpPortRegistrator PASSED\n```\n\n###### Sample output for failing test:\n```\norg.bitsofinfo.hazelcast.discovery.consul.TestDoNothingRegistrator \u003e testDoNothingRegistrator STARTED\n\norg.bitsofinfo.hazelcast.discovery.consul.TestDoNothingRegistrator \u003e testDoNothingRegistrator FAILED\n    java.lang.AssertionError at TestDoNothingRegistrator.java:85\n```\n\nTo run individual unit-test, use the `unitTest.single` argument to provide the unit-test you would like to run. The command below runs the unit test for `TestDoNothingRegistrator`\n\n```\n$ ./gradlew -DunitTest.single=TestDoNothingRegistrator unitTest\n```\n\n##### Note on running `TestDoNothingRegistrator` unit-test\nThe `TestDoNothingRegistrator` unit-test should be run separately using the `unitTest.single` argument as demonstrated above as it requires you to register a service with your local consul with 5 nodes/instances. Please **CAREFULLY READ** the comments in `TestDoNothingRegistrator.java` to see how this test should be run.\n\n##### Passing optional parameters to unit-tests\nThe following parameters can be passed with the `-D` option when invoking the tests\n```\n-DconsulPort=(some port)\n-DconsulHost=(some host)\n-DconsulAclToken=(some ACL token if the server requires it)\n-DconsulSslEnabled=(true | false)\n-DconsulSslServerCertFilePath=(/path/to/ca.cert)\n-DconsulSslServerCertBase64=(base64 encoded cert string)\n-DconsulSslServerHostnameVerify=(false|True)\n-DconsulHealthCheckProvider=(org.bitsofinfo.hazelcast.discovery.consul.ScriptHealthCheckBuilder | org.bitsofinfo.hazelcast.discovery.consul.HttpHealthCheckBuilder)\n\n```\n\n## \u003ca id=\"related\"\u003e\u003c/a\u003eRelated info\n\n* https://www.consul.io\n* http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#discovery-spi\n* https://www.consul.io/docs/guides/acl.html#complete-acl-coverage-in-consul-0-8\n* **Swarm** version of this: https://github.com/bitsofinfo/hazelcast-docker-swarm-discovery-spi \n* **Etcd** version of this: https://github.com/bitsofinfo/hazelcast-etcd-discovery-spi\n\n## \u003ca id=\"todo\"\u003e\u003c/a\u003eTodo\n\n* Ensure all configuration tweakable via `-D` system properties\n\n## \u003ca id=\"notes\"\u003e\u003c/a\u003e Notes\n\n### \u003ca id=\"docker\"\u003e\u003c/a\u003eContainerization (Docker) notes\n\nThis library may also be helpful to you: [docker-discovery-registrator-consul](https://github.com/bitsofinfo/docker-discovery-registrator-consul)\n\nOne of the main drivers for coding this module was for Hazelcast applications that were deployed as Docker containers\nthat would need to automatically register themselves with Consul for higher level cluster orchestration of the cluster.\n\nIf you are deploying your Hazelcast application as a Docker container, one helpful tip is that you will want to avoid hardwired\nconfiguration in the hazelcast XML config, but rather have your Docker container take startup arguments that would be translated\nto `-D` system properties on startup. Convienently Hazelcast can consume these JVM system properties and replace variable placeholders in the XML config. See this documentation for examples: [http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#using-variables](http://docs.hazelcast.org/docs/3.6/manual/html-single/index.html#using-variables)\n\nSpecifically when using this discovery strategy and Docker, it may be useful for you to use the [ExplicitIpPortRegistrator](src/main/java/org/bitsofinfo/hazelcast/discovery/consul/ExplicitIpPortRegistrator.java) `ConsulRegistrator` **instead** of the *LocalDiscoveryNodeRegistrator* as the latter relies on hazelcast to determine its IP/PORT and this may end up being the local container IP, and not the Docker host IP, leading to a situation where a unreachable IP/PORT combination is published to Consul.\n\n**Example:** excerpt from [explicitIpPortRegistrator-example.xml](src/main/resources/explicitIpPortRegistrator-example.xml)\n\nStart your hazelcast app such as with the below, this would assume that hazelcast is actually reachable via this configuration\nvia your Docker host and the port mappings that were specified on `docker run`. (i.e. the IP below would be your docker host/port that is mapped to the actual hazelcast app container and port it exposes for hazelcast).\n\n* This library may also be helpful to you: [docker-discovery-registrator-consul](https://github.com/bitsofinfo/docker-discovery-registrator-consul) \n\n* Also see: https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/issues/20 for info on how to do this.\n\nSee this [Docker issue for related info](https://github.com/docker/docker/issues/3778) on detecting mapped ports/ip from **within** a container\n\n`java -jar myHzApp.jar -DregisterWithIpAddress=\u003cdockerHostIp\u003e -DregisterWithPort=\u003cmappedContainerPortOnDockerHost\u003e .... `\n\n```\n\u003cproperty name=\"consul-registrator-config\"\u003e\u003c![CDATA[\n      {\n        \"registerWithIpAddress\":\"${registerWithIpAddress}\",\n        \"registerWithPort\":${registerWithPort},\n        \"healthCheckScript\":\"nc -z #MYIP #MYPORT\",\n        \"healthCheckScriptIntervalSeconds\":30\n      }\n  ]]\u003e\u003c/property\u003e\n```\nUntil hazelcast fixes the numerous issues around interfaces/binding etc, you may be better off just running your hz app in a docker swarm and use: https://github.com/bitsofinfo/hazelcast-docker-swarm-discovery-spi  for peer to peer hazelcast cluster discovery.\n\n### Consul health-check notes\n\nDepending on the health check script you are using: (`nc -z #MYIP #MYPORT` OR  `/bin/sh exec 6\u003c\u003e/dev/tcp/#MYIP/#MYPORT || (exit 3)`  should see something like in your Consul agent monitor when the health-check scripts are running:\n```\n\u003e consul monitor --log-level trace\n\n2015/11/20 11:21:39 [DEBUG] agent: check 'service:hz-discovery-test-cluster-192.168.0.208-192.168.0.208-5701' script 'exec 6\u003c\u003e/dev/tcp/192.168.0.208/5701 || (exit 3)' output:\n2015/11/20 11:21:39 [DEBUG] agent: Check 'service:hz-discovery-test-cluster-192.168.0.208-192.168.0.208-5701' is passing\n```\n\nDepending on the version of Hazelcast you are using, you may see something like these warnings logged when the health-check script interrogates the hazelcast port and does nothing. You are free to monitor the services any way you wish, or not at all by omitting the `healthCheckScript` JSON property; see [See hazelcast-consul-discovery-spi-example.xml](src/main/resources/hazelcast-consul-discovery-spi-example.xml) for an example.\n\n```\nDec 13, 2017 10:25:40 AM com.hazelcast.nio.tcp.TcpIpConnection\nINFO: [172.20.10.2]:5702 [hazelcast-consul-discovery-spi] [3.9.1] Connection[id=3, /172.20.10.2:5702-\u003e/172.20.10.2:57436, endpoint=null, alive=false, type=NONE] closed. Reason: Connection closed by the other side\n\nDec 13, 2017 10:25:40 AM com.hazelcast.nio.tcp.TcpIpConnection\nINFO: [172.20.10.2]:5702 [hazelcast-consul-discovery-spi] [3.9.1] Connection[id=3, /172.20.10.2:5702-\u003e/172.20.10.2:57436, endpoint=null, alive=false, type=NONE] closed. Reason: Connection closed by the other side\n```\n\nOR\n\n```\nNov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.SocketAcceptorThread\nINFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6] Accepting socket connection from /192.168.0.208:53495\nNov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.TcpIpConnectionManager\nINFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6] Established socket connection between /192.168.0.208:5701 and /192.168.0.208:53495\nNov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketWriter\nWARNING: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6] SocketWriter is not set, creating SocketWriter with CLUSTER protocol!\nNov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.TcpIpConnection\nINFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6] Connection [/192.168.0.208:53495] lost. Reason: java.io.EOFException[Could not read protocol type!]\n```\n\n### \u003ca id=\"consul\"\u003e\u003c/a\u003eConsul ACL issues\n\nThis library was originally developed prior to Consul 0.8, as of 0.8+, changes to the ACL system were made which may require you to grant\nadditional access if your target consul is in default deny mode\n\nSee: \n\n* https://www.consul.io/docs/guides/acl.html#complete-acl-coverage-in-consul-0-8\n* https://www.consul.io/docs/guides/acl.html#bootstrapping-acls\n\nFor examples: For the unit tests to work, create a new `client` token w/ the following policy, then assign the token to the `consul-acl-token` setting for this SPI's XML config:\n\n```\nservice \"\" { policy = \"write\" },\nnode \"\" { policy = \"write\" },\nagent \"\" { policy = \"read\" }\n```\n\nNOTE! The above sample is just that (a simple sample), in production you may want to re-evaluate and lock down further as needed. \n\n\n## push\n\n```\n./gradlew -PbintrayUser= -PbintrayApiKey= bintray \n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fhazelcast-consul-discovery-spi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbitsofinfo%2Fhazelcast-consul-discovery-spi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbitsofinfo%2Fhazelcast-consul-discovery-spi/lists"}