Skip to content

Commit 22fecc2

Browse files
authored
Merge pull request #277 from nats-io/2.6.6
2.6.6
2 parents 3db47bd + 47b5be7 commit 22fecc2

File tree

27 files changed

+268
-356
lines changed

27 files changed

+268
-356
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11

22
# Change Log
33

4+
## Version 2.6.6
5+
6+
* [FIXED] - #274 - Added a check to prevent double event notification
7+
* [CHANGED] - #276 - Updated TLS certs to match go client
8+
* [FIXED] - #275 - Updated connect to randomize with the same code as reconnect
9+
410
## Version 2.6.2, 2.6.3, 2.6.4 & 2.6.5
511

612
* [FIXED] - problem with jars being built with jdk 11

README.md

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ The java-nats client is provided in a single jar file, with a single external de
5252

5353
### Downloading the Jar
5454

55-
You can download the latest jar at [https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.5/jnats-2.6.5.jar](https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.5/jnats-2.6.5.jar).
55+
You can download the latest jar at [https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.6/jnats-2.6.6.jar](https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.6/jnats-2.6.6.jar).
5656

57-
The examples are available at [https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.5/jnats-2.6.5-examples.jar](https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.5/jnats-2.6.5-examples.jar).
57+
The examples are available at [https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.6/jnats-2.6.6-examples.jar](https://search.maven.org/remotecontent?filepath=io/nats/jnats/2.6.6/jnats-2.6.6-examples.jar).
5858

5959
To use NKeys, you will need the ed25519 library, which can be downloaded at [https://repo1.maven.org/maven2/net/i2p/crypto/eddsa/0.3.0/eddsa-0.3.0.jar](https://repo1.maven.org/maven2/net/i2p/crypto/eddsa/0.3.0/eddsa-0.3.0.jar).
6060

@@ -64,7 +64,7 @@ The NATS client is available in the Maven central repository, and can be importe
6464

6565
```groovy
6666
dependencies {
67-
implementation 'io.nats:jnats:2.6.5'
67+
implementation 'io.nats:jnats:2.6.6'
6868
}
6969
```
7070

@@ -90,7 +90,7 @@ The NATS client is available on the Maven central repository, and can be importe
9090
<dependency>
9191
<groupId>io.nats</groupId>
9292
<artifactId>jnats</artifactId>
93-
<version>2.6.5</version>
93+
<version>2.6.6</version>
9494
</dependency>
9595
```
9696

@@ -226,15 +226,15 @@ NATS supports TLS 1.2. The server can be configured to verify client certificate
226226
1. The Java library allows the use of the tls:// protocol in its urls. This setting expects a default SSLContext to be set. You can set this default context using System properties, or in code. For example, you could run the publish example using:
227227

228228
```bash
229-
java -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=src/test/resources/cacerts -Djavax.net.ssl.trustStorePassword=password io.nats.examples.NatsPub tls://localhost:4443 test "hello world"
229+
java -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=src/test/resources/truststore.jks -Djavax.net.ssl.trustStorePassword=password io.nats.examples.NatsPub tls://localhost:4443 test "hello world"
230230
```
231231

232232
where the following properties are being set:
233233

234234
```bash
235235
-Djavax.net.ssl.keyStore=src/test/resources/keystore.jks
236236
-Djavax.net.ssl.keyStorePassword=password
237-
-Djavax.net.ssl.trustStore=src/test/resources/cacerts
237+
-Djavax.net.ssl.trustStore=src/test/resources/truststore.jks
238238
-Djavax.net.ssl.trustStorePassword=password
239239
```
240240

@@ -401,6 +401,20 @@ which will create a folder called `build/reports/jacoco` containing the file `in
401401

402402
Many of the tests run nats-server on a custom port. If nats-server is in your path they should just work, but in cases where it is not, or an IDE running tests has issues with the path you can specify the nats-server location with the environment variable `nats_-_server_path`.
403403

404+
## TLS Certs
405+
406+
The raw TLS test certs are in [src/test/resources/certs](src/test/resources/certs) and come from the [nats.go](https://github.com/nats-io/nats.go) repository. However, the java client also needs a keystore and truststore.jks files for creating a context. These can be created using:
407+
408+
```bash
409+
> cd src/test/resources
410+
> keytool -keystore truststore.jks -alias CARoot -import -file certs/ca.pem -storepass password -noprompt -storetype pkcs12
411+
> cat certs/client-key.pem certs/client-cert.pem > combined.pem
412+
> openssl pkcs12 -export -in combined.pem -out cert.p12
413+
> keytool -importkeystore -srckeystore cert.p12 -srcstoretype pkcs12 -deststoretype pkcs12 -destkeystore keystore.jks
414+
> keytool -keystore keystore.jks -alias CARoot -import -file certs/ca.pem -storepass password -noprompt
415+
> rm cert.p12 combined.pem
416+
```
417+
404418
## License
405419

406420
Unless otherwise noted, the NATS source files are distributed

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ plugins {
1616
// Be sure to update Nats.java with the latest version, the change log and the package-info.java
1717
def versionMajor = 2
1818
def versionMinor = 6
19-
def versionPatch = 5
19+
def versionPatch = 6
2020
def versionModifier = ""
21-
def jarVersion = "2.6.5"
21+
def jarVersion = "2.6.6"
2222
def branch = System.getenv("TRAVIS_BRANCH");
2323
def tag = System.getenv("TRAVIS_TAG");
2424
def useSigning = "master".equals(branch) || (!"".equals(tag) && tag.equals(branch)) // tag will be the branch on a tag event for travis

src/examples/java/io/nats/examples/autobench/NatsAutoBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public static void main(String args[]) {
9494
* jar plus the flag. For example, to run after building locally and using the test cert files:
9595
* java -cp ./build/libs/jnats-2.5.1-SNAPSHOT-examples.jar:./build/libs/jnats-2.5.1-SNAPSHOT-fat.jar:<path to conscrypt.jar> \
9696
* -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks -Djavax.net.ssl.keyStorePassword=password \
97-
* -Djavax.net.ssl.trustStore=src/test/resources/cacerts -Djavax.net.ssl.trustStorePassword=password \
97+
* -Djavax.net.ssl.trustStore=src/test/resources/truststore.jks -Djavax.net.ssl.trustStorePassword=password \
9898
* io.nats.examples.autobench.NatsAutoBench tls://localhost:4443 med conscrypt
9999
*/
100100
if (conscrypt) {

src/examples/java/io/nats/examples/benchmark/NatsBench.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public void slowConsumerDetected(Connection conn, Consumer consumer) {
135135
* ./build/libs/jnats-2.5.1-SNAPSHOT-examples.jar:./build/libs/jnats-2.5.1-SNAPSHOT-fat.jar:<path
136136
* to conscrypt.jar> \ -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks
137137
* -Djavax.net.ssl.keyStorePassword=password \
138-
* -Djavax.net.ssl.trustStore=src/test/resources/cacerts
138+
* -Djavax.net.ssl.trustStore=src/test/resources/truststore.jks
139139
* -Djavax.net.ssl.trustStorePassword=password \
140140
* io.nats.examples.autobench.NatsAutoBench tls://localhost:4443 med conscrypt
141141
*/

src/examples/java/io/nats/examples/examples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ To see how queues split messages, run the `NatsQSub` in multiple windows and the
3030
A set of sample certificates are provided in the repo for testing. These use the highly secure password `password`. To run with the full client and trust default keystore you can use command line arguments to set System properties.
3131

3232
```bash
33-
java -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=src/test/resources/cacerts -Djavax.net.ssl.trustStorePassword=password io.nats.examples.NatsPub tls://localhost:4443 test "hello world"
33+
java -Djavax.net.ssl.keyStore=src/test/resources/keystore.jks -Djavax.net.ssl.keyStorePassword=password -Djavax.net.ssl.trustStore=src/test/resources/truststore.jks -Djavax.net.ssl.trustStorePassword=password io.nats.examples.NatsPub tls://localhost:4443 test "hello world"
3434
```
3535

3636
To run with the completely unverified client:

src/main/java/io/nats/client/Nats.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public class Nats {
7272
/**
7373
* Current version of the library - {@value #CLIENT_VERSION}
7474
*/
75-
public static final String CLIENT_VERSION = "2.6.5";
75+
public static final String CLIENT_VERSION = "2.6.6";
7676

7777
/**
7878
* Current language of the library - {@value #CLIENT_LANGUAGE}

src/main/java/io/nats/client/impl/NatsConnection.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ void connect(boolean reconnectOnConnect) throws InterruptedException, IOExceptio
192192

193193
timeTrace(trace, "starting connect loop");
194194

195-
for (String serverURI : getServers()) {
195+
Collection<String> serversToTry = buildServerList();
196+
for (String serverURI : serversToTry) {
196197
if (isClosed()) {
197198
break;
198199
}
@@ -262,7 +263,7 @@ void reconnect() throws InterruptedException {
262263
boolean doubleAuthError = false;
263264

264265
while (!isConnected() && !isClosed() && !this.isClosing()) {
265-
Collection<String> serversToTry = buildReconnectList();
266+
Collection<String> serversToTry = buildServerList();
266267

267268
for (String server : serversToTry) {
268269
if (isClosed()) {
@@ -1509,7 +1510,7 @@ void updateStatus(Status newStatus) {
15091510

15101511
statusLock.lock();
15111512
try {
1512-
if (oldStatus == Status.CLOSED) {
1513+
if (oldStatus == Status.CLOSED || newStatus == oldStatus) {
15131514
return;
15141515
}
15151516
this.status = newStatus;
@@ -1623,7 +1624,7 @@ void waitForReconnectTimeout() {
16231624
this.reconnectWaiter.complete(Boolean.TRUE);
16241625
}
16251626

1626-
Collection<String> buildReconnectList() {
1627+
Collection<String> buildServerList() {
16271628
ArrayList<String> reconnectList = new ArrayList<>();
16281629

16291630
reconnectList.addAll(getServers());

src/test/java/io/nats/client/AuthTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ public void testUserPassInURLWithFallback() throws Exception {
217217
NatsTestServer ts2 = new NatsTestServer(customArgs2, false)) {
218218
// See config file for user/pass
219219
Options options = new Options.Builder().server("nats://stephen:password@localhost:" + ts1.getPort())
220-
.server("nats://localhost:" + ts2.getPort())
220+
.server("nats://localhost:" + ts2.getPort()).noRandomize()
221221
.userInfo("alberto".toCharArray(), "casadecampo".toCharArray()).maxReconnects(4).noRandomize()
222222
.connectionListener(handler).pingInterval(Duration.ofMillis(100)).build();
223223
Connection nc = Nats.connect(options);
@@ -556,7 +556,7 @@ public void testReconnectWithAuth() throws Exception {
556556
try (NatsTestServer ts = new NatsTestServer("src/test/resources/operator.conf", false);
557557
NatsTestServer ts2 = new NatsTestServer("src/test/resources/operator.conf", false)) {
558558
Options options = new Options.Builder().servers(new String[] { ts.getURI(), ts2.getURI() })
559-
.maxReconnects(-1).authHandler(Nats.credentials("src/test/resources/jwt_nkey/user.creds")).build();
559+
.noRandomize().maxReconnects(-1).authHandler(Nats.credentials("src/test/resources/jwt_nkey/user.creds")).build();
560560
Connection nc = Nats.connect(options);
561561
try {
562562
assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
@@ -591,7 +591,7 @@ public void testCloseOnReconnectWithSameError() throws Exception {
591591
try (NatsTestServer ts = new NatsTestServer("src/test/resources/operator_noacct.conf", false);
592592
NatsTestServer ts2 = new NatsTestServer("src/test/resources/operator.conf", false)) {
593593
Options options = new Options.Builder().servers(new String[] { ts.getURI(), ts2.getURI() })
594-
.maxReconnects(-1).connectionTimeout(Duration.ofSeconds(2))
594+
.maxReconnects(-1).connectionTimeout(Duration.ofSeconds(2)).noRandomize()
595595
.authHandler(Nats.credentials("src/test/resources/jwt_nkey/user.creds")).build();
596596
Connection nc = Nats.connect(options);
597597
try {
@@ -625,7 +625,7 @@ public void testThatAuthErrorIsCleared() throws Exception {
625625
// Connect should fail on ts1
626626
try (NatsTestServer ts = new NatsTestServer("src/test/resources/operator_noacct.conf", false);
627627
NatsTestServer ts2 = new NatsTestServer("src/test/resources/operator.conf", false)) {
628-
Options options = new Options.Builder().servers(new String[] { ts.getURI(), ts2.getURI() })
628+
Options options = new Options.Builder().servers(new String[] { ts.getURI(), ts2.getURI() }).noRandomize()
629629
.maxReconnects(-1).connectionTimeout(Duration.ofSeconds(5)).reconnectWait(Duration.ofSeconds(1)) // wait a tad to allow restarts
630630
.authHandler(Nats.credentials("src/test/resources/jwt_nkey/user.creds")).build();
631631
Connection nc = Nats.connect(options);
@@ -696,6 +696,7 @@ public void testReconnectAfterExpiration() throws Exception {
696696
Options options = new Options.Builder().
697697
servers(new String[] {ts.getURI(), ts2.getURI()}).
698698
maxReconnects(-1).
699+
noRandomize().
699700
authHandler(Nats.credentials("src/test/resources/jwt_nkey/user.creds")).
700701
build();
701702
Connection nc = Nats.connect(options);

src/test/java/io/nats/client/ConnectTests.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,68 @@ public void testConnectWithCommas() throws IOException, InterruptedException {
204204
}
205205
}
206206

207+
@Test
208+
public void testConnectRandomize() throws IOException, InterruptedException {
209+
try (NatsTestServer ts1 = new NatsTestServer(false)) {
210+
try (NatsTestServer ts2 = new NatsTestServer(false)) {
211+
int one = 0;
212+
int two = 0;
213+
214+
// should get at least 1 for each
215+
for (int i=0; i < 10; i++) {
216+
Connection nc = Nats.connect(ts1.getURI() + "," + ts2.getURI());
217+
try {
218+
assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
219+
220+
if (nc.getConnectedUrl().equals(ts1.getURI())) {
221+
one++;
222+
} else {
223+
two++;
224+
}
225+
} finally {
226+
nc.close();
227+
assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
228+
}
229+
}
230+
231+
assertTrue("randomly got one", one > 0);
232+
assertTrue("randomly got two", two > 0);
233+
}
234+
}
235+
}
236+
237+
@Test
238+
public void testConnectNoRandomize() throws IOException, InterruptedException {
239+
try (NatsTestServer ts1 = new NatsTestServer(false)) {
240+
try (NatsTestServer ts2 = new NatsTestServer(false)) {
241+
int one = 0;
242+
int two = 0;
243+
244+
// should get at least 1 for each
245+
for (int i=0; i < 10; i++) {
246+
String[] servers = {ts1.getURI(), ts2.getURI()};
247+
Options options = new Options.Builder().noRandomize().servers(servers).build();
248+
Connection nc = Nats.connect(options);
249+
try {
250+
assertTrue("Connected Status", Connection.Status.CONNECTED == nc.getStatus());
251+
252+
if (nc.getConnectedUrl().equals(ts1.getURI())) {
253+
one++;
254+
} else {
255+
two++;
256+
}
257+
} finally {
258+
nc.close();
259+
assertTrue("Closed Status", Connection.Status.CLOSED == nc.getStatus());
260+
}
261+
}
262+
263+
assertTrue("always got one", one == 10);
264+
assertTrue("never got two", two == 0);
265+
}
266+
}
267+
}
268+
207269
@Test(expected=IOException.class)
208270
public void testFailWithMissingLineFeedAfterInfo() throws IOException, InterruptedException {
209271
Connection nc = null;

0 commit comments

Comments
 (0)