Skip to content

Commit 22e10a6

Browse files
committed
1.0-RC1
1 parent 722efe7 commit 22e10a6

File tree

4 files changed

+147
-46
lines changed

4 files changed

+147
-46
lines changed

README.md

Lines changed: 87 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# hazelcast-consul-discovery-spi
22

3-
Provides a Consul based discovery strategy for Hazlecast 3.6-EA+ enabled applications.
3+
Provides a Consul based discovery strategy for Hazlecast 3.6-RC1+ enabled applications.
44
This 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.
55

66
* [Status](#status)
7+
* [Releases](#releases)
78
* [Requirements](#requirements)
9+
* [Maven/Gradle install](#mavengradle)
810
* [Features](#features)
9-
* [Build/Usage](#usage)
11+
* [Usage](#usage)
12+
* [Build from source](#building)
1013
* [Unit tests](#tests)
1114
* [Related Info](#related)
1215
* [Todo](#todo)
@@ -17,14 +20,68 @@ This is an easy to configure plug-and-play Hazlecast DiscoveryStrategy that will
1720

1821
## <a id="status"></a>Status
1922

20-
This is beta code.
23+
This is beta code, tested against Hazelcast 3.6-EA and 3.6-RC1
24+
25+
## <a id="releases"></a>Releases
26+
27+
* [1.0-RC1](https://github.com/bitsofinfo/hazelcast-consul-discovery-spi/releases/tag/1.0-RC1): Tested against Hazelcast 3.6-EA and 3.6-RC1
2128

2229
## <a id="requirements"></a>Requirements
2330

2431
* Java 6+
25-
* [Hazelcast 3.6-EA+](https://hazelcast.org/)
32+
* [Hazelcast 3.6-RC1+](https://hazelcast.org/)
2633
* [Consul](https://consul.io/)
2734

35+
## <a id="mavengradle"></a>Maven/Gradle
36+
37+
To use this discovery strategy in your Maven or Gradle project use the dependency samples below.
38+
39+
### Gradle:
40+
41+
```
42+
repositories {
43+
jcenter()
44+
}
45+
46+
dependencies {
47+
compile 'org.bitsofinfo:hazelcast-consul-discovery-spi:1.0-RC1'
48+
49+
// include your preferred javax.ws.rs-api implementation
50+
// (for the OrbitzWorldwide/consul-client dependency)
51+
// for example below:
52+
compile 'org.apache.cxf:cxf-rt-rs-client:3.0.3'
53+
compile 'org.apache.cxf:cxf-rt-transports-http-hc:3.0.3'
54+
}
55+
```
56+
57+
### Maven:
58+
59+
```
60+
<dependencies>
61+
<dependency>
62+
<groupId>org.bitsofinfo</groupId>
63+
<artifactId>hazelcast-consul-discovery-spi</artifactId>
64+
<version>1.0-RC1</version>
65+
</dependency>
66+
67+
<!-- include your preferred javax.ws.rs-api
68+
(for the https://github.com/OrbitzWorldwide/consul-client dependency)
69+
implementation - see gradle example above
70+
-->
71+
</dependencies>
72+
73+
<repositories>
74+
<repository>
75+
<snapshots>
76+
<enabled>false</enabled>
77+
</snapshots>
78+
<id>central</id>
79+
<name>bintray</name>
80+
<url>http://jcenter.bintray.com</url>
81+
</repository>
82+
</repositories>
83+
```
84+
2885
## <a id="features"></a>Features
2986

3087

@@ -40,24 +97,16 @@ This is beta code.
4097
* Control which IP is published as the service-address with Consul
4198
* Configurable discovery delay
4299
* Automatic Consul de-registration of instance via ShutdownHook
100+
101+
102+
## <a id="usage"></a>Usage
43103

44-
## <a id="usage"></a>Build & Usage
104+
* 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.
45105

46106
* Have Consul running and available somewhere on your network, start it such as:
47107
```
48108
consul agent -server -bootstrap-expect 1 -data-dir /tmp/consul -config-dir /path/to/consul.d/ -ui-dir /path/to/consul-web-ui
49109
```
50-
* From the root of this project, build a Jar : `./gradlew assemble`
51-
52-
* Include the built jar artifact located at `build/libs/hazelcast-consul-discovery-spi-1.0.0.jar` in your hazelcast project
53-
54-
* 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):
55-
56-
```
57-
compile group: 'com.orbitz.consul', name: 'consul-client', version:'0.9.12'
58-
compile group: 'org.apache.cxf', name:'cxf-rt-rs-client', version:'3.0.3'
59-
compile group: 'org.apache.cxf', name:'cxf-rt-transports-http-hc', version:'3.0.3'
60-
```
61110

62111
* 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.
63112

@@ -139,6 +188,20 @@ compile group: 'org.apache.cxf', name:'cxf-rt-transports-http-hc', version:'3.0.
139188
]
140189
```
141190

191+
## <a id="building"></a>Building from source
192+
193+
* From the root of this project, build a Jar : `./gradlew assemble`
194+
195+
* Include the built jar artifact located at `build/libs/hazelcast-consul-discovery-spi-[VERSION].jar` in your hazelcast project
196+
197+
* 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):
198+
199+
```
200+
compile group: 'com.orbitz.consul', name: 'consul-client', version:'0.9.16'
201+
compile group: 'org.apache.cxf', name:'cxf-rt-rs-client', version:'3.0.3'
202+
compile group: 'org.apache.cxf', name:'cxf-rt-transports-http-hc', version:'3.0.3'
203+
```
204+
142205
## Consul UI example
143206

144207
Showing [LocalDiscoveryNodeRegistrator](src/main/java/org/bitsofinfo/hazelcast/discovery/consul/LocalDiscoveryNodeRegistrator.java) configured hazelcast services with health-checks
@@ -148,19 +211,18 @@ Showing [LocalDiscoveryNodeRegistrator](src/main/java/org/bitsofinfo/hazelcast/d
148211
## <a id="tests"></a>Unit-tests
149212

150213
It may also help you to understand the functionality by checking out and running the unit-tests
151-
located at [src/test/java](src/test/java). Be sure to read the comments as some of the tests require
152-
you to setup your local Consul and edit certain files.
214+
located at [src/test/java](src/test/java). **BE SURE TO READ** the comments in the test source files
215+
as some of the tests require you to setup your local Consul and edit certain files.
153216

154217
## <a id="related"></a>Related info
155218

156219
* https://www.consul.io
157-
* http://docs.hazelcast.org/docs/3.6-EA/manual/html-single/index.html#discovery-spi
220+
* http://docs.hazelcast.org/docs/3.6-RC1/manual/html-single/index.html#discovery-spi
158221
* **Etcd** version of this: https://github.com/bitsofinfo/hazelcast-etcd-discovery-spi
159222

160223
## <a id="todo"></a>Todo
161224

162225
* Ensure all configuration tweakable via `-D` system properties
163-
* Add support to force registered IP and PORT (for certain containerized scenarios)
164226

165227
## <a id="notes"></a> Notes
166228

@@ -171,7 +233,7 @@ that would need to automatically register themselves with Consul for higher leve
171233

172234
If you are deploying your Hazelcast application as a Docker container, one helpful tip is that you will want to avoid hardwired
173235
configuration in the hazelcast XML config, but rather have your Docker container take startup arguments that would be translated
174-
to `-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-EA/manual/html-single/index.html#using-variables](http://docs.hazelcast.org/docs/3.6-EA/manual/html-single/index.html#using-variables)
236+
to `-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-RC1/manual/html-single/index.html#using-variables](http://docs.hazelcast.org/docs/3.6-RC1/manual/html-single/index.html#using-variables)
175237

176238
Specifically 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.
177239

@@ -195,12 +257,6 @@ See this [Docker issue for related info](https://github.com/docker/docker/issues
195257
]]></property>
196258
```
197259

198-
### Prior hazelcast versions
199-
For versions of Hazelcast **prior to 3.6** you may want to look at these projects which seem to provide older implementations of Consul based discovery:
200-
201-
* https://github.com/decoomanj/hazelcast-consul
202-
* https://github.com/decoomanj/hazelcast-consul-spi
203-
204260
### Consul health-check notes
205261

206262
You should see this in your Consul agent monitor when the health-check scripts are running:
@@ -214,11 +270,11 @@ You should see this in your Consul agent monitor when the health-check scripts a
214270
You will 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.
215271
```
216272
Nov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.SocketAcceptorThread
217-
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-EA] Accepting socket connection from /192.168.0.208:53495
273+
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-RC1] Accepting socket connection from /192.168.0.208:53495
218274
Nov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.TcpIpConnectionManager
219-
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-EA] Established socket connection between /192.168.0.208:5701 and /192.168.0.208:53495
275+
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-RC1] Established socket connection between /192.168.0.208:5701 and /192.168.0.208:53495
220276
Nov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.nonblocking.NonBlockingSocketWriter
221-
WARNING: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-EA] SocketWriter is not set, creating SocketWriter with CLUSTER protocol!
277+
WARNING: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-RC1] SocketWriter is not set, creating SocketWriter with CLUSTER protocol!
222278
Nov 20, 2015 6:57:50 PM com.hazelcast.nio.tcp.TcpIpConnection
223-
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-EA] Connection [/192.168.0.208:53495] lost. Reason: java.io.EOFException[Could not read protocol type!]
279+
INFO: [192.168.0.208]:5701 [hazelcast-consul-discovery] [3.6-RC1] Connection [/192.168.0.208:53495] lost. Reason: java.io.EOFException[Could not read protocol type!]
224280
```

build.gradle

Lines changed: 55 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,69 @@
1+
buildscript {
2+
repositories {
3+
jcenter()
4+
}
5+
}
16

2-
apply plugin: 'java'
7+
plugins {
8+
id "com.jfrog.bintray" version "1.5"
9+
}
310

411
group = 'org.bitsofinfo'
5-
version = '1.0.0'
612

7-
description = """hazelcast-consul-discovery-spi"""
13+
allprojects {
14+
repositories {
15+
jcenter()
16+
}
17+
apply plugin: 'maven'
18+
apply plugin: 'maven-publish'
19+
apply plugin: 'java'
20+
}
821

922
sourceCompatibility = 1.6
1023
targetCompatibility = 1.6
1124

12-
repositories {
13-
jcenter()
14-
}
15-
1625
dependencies {
1726

18-
compile group: 'com.hazelcast', name: 'hazelcast', version:'3.6-EA'
19-
compile group: 'com.orbitz.consul', name: 'consul-client', version:'0.9.12'
20-
21-
compile 'org.apache.cxf:cxf-rt-rs-client:3.0.3'
22-
compile 'org.apache.cxf:cxf-rt-transports-http-hc:3.0.3'
27+
compile group: 'com.hazelcast', name: 'hazelcast', version:'3.6-RC1'
28+
compile group: 'com.orbitz.consul', name: 'consul-client', version:'0.9.16'
2329

30+
// for consul-client
31+
testCompile 'org.apache.cxf:cxf-rt-rs-client:3.0.3'
32+
testCompile 'org.apache.cxf:cxf-rt-transports-http-hc:3.0.3'
2433
testCompile 'junit:junit:4.12'
2534

2635
}
36+
37+
bintray {
38+
user = project.hasProperty('bintrayUser') ? project.property('bintrayUser') : System.getenv('bintrayUser')
39+
key = project.hasProperty('bintrayApiKey') ? project.property('bintrayApiKey') : System.getenv('bintrayApiKey')
40+
publications = ['hazelcastConsulDiscoverySpi']
41+
pkg {
42+
repo = 'maven'
43+
name = 'hazelcast-consul-discovery-spi'
44+
licenses = ['Apache-2.0']
45+
vcsUrl = 'https://github.com/bitsofinfo/hazelcast-consul-discovery-spi'
46+
publicDownloadNumbers = true
47+
version {
48+
name = project.property('version')
49+
desc = project.property('version') + " : " + project.property('description')
50+
released = new Date()
51+
vcsTag = project.property('version')
52+
}
53+
}
54+
}
55+
56+
publishing {
57+
publications {
58+
hazelcastConsulDiscoverySpi(MavenPublication) {
59+
from components.java
60+
groupId 'org.bitsofinfo.hazelcast'
61+
artifactId 'hazelcast-consul-discovery-spi'
62+
version project.property('version')
63+
}
64+
}
65+
}
66+
67+
68+
69+

gradle.properties

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
version=1.0-RC1
2+
description=hazelcast-consul-discovery-spi - Consul based discovery strategy SPI for Hazelcast enabled applications

src/main/java/org/bitsofinfo/hazelcast/discovery/consul/BaseRegistrator.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@
2929
* which are available to all derivative classes
3030
*
3131
* - healthCheckScript: can be anything you want Consul to do to determine health.
32-
* Variables #MYIP/#MYPORT will be replaced
33-
* @see https://www.consul.io/docs/agent/checks.html
32+
* Variables #MYIP/#MYPORT will be replaced. https://www.consul.io/docs/agent/checks.html
3433
*
3534
* - healthCheckScriptIntervalSeconds: self explanatory
36-
*
35+
*
36+
*
3737
* @author bitsofinfo
3838
*
3939
*/

0 commit comments

Comments
 (0)