Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 77 additions & 0 deletions .github/workflows/build-main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build Main Snapshot
permissions:
contents: read
on:
push:
branches:
- main
workflow_dispatch:

jobs:
build:
strategy:
matrix:
tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
TARGET_COMPATIBILITY: ${{ matrix.tc }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
steps:
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: current
- name: Setup GO
uses: actions/setup-go@v5
with:
go-version: stable
- name: Install Nats Server
run: |
pkill -9 nats-server 2>/dev/null || true
mkdir -p ~/.local/bin
cd $GITHUB_WORKSPACE
git clone https://github.com/nats-io/nats-server.git
cd nats-server
go build -o ~/.local/bin/nats-server
nats-server -v
- name: Check out code
uses: actions/checkout@v4
- name: Build and Test
run: chmod +x gradlew && ./gradlew clean test jacocoTestReport
- name: Verify Javadoc
run: ./gradlew javadoc
- name: Send coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
parallel: true
flag-name: tc${{ matrix.tc }}
- name: Publish Snapshot
run: ./gradlew -i publishToSonatype
- name: Clean up
if: always()
run: pkill -9 nats-server 2>/dev/null || true

coveralls-finish:
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./core
steps:
- name: Coveralls Finish
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
carryforward: "tc17"
68 changes: 68 additions & 0 deletions .github/workflows/build-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
name: Build Pull Request
permissions:
contents: read
on:
pull_request:
types: [opened, synchronize, reopened]

jobs:
build:
strategy:
matrix:
tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: ${{ github.event_name }}
TARGET_COMPATIBILITY: ${{ matrix.tc }}
steps:
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: current
- name: Setup GO
uses: actions/setup-go@v5
with:
go-version: stable
- name: Install Nats Server
run: |
pkill -9 nats-server 2>/dev/null || true
mkdir -p ~/.local/bin
cd $GITHUB_WORKSPACE
git clone https://github.com/nats-io/nats-server.git
cd nats-server
go build -o ~/.local/bin/nats-server
nats-server -v
- name: Check out code
uses: actions/checkout@v4
- name: Build and Test
run: chmod +x gradlew && ./gradlew clean test jacocoTestReport
- name: Verify Javadoc
run: ./gradlew javadoc
- name: Send coverage to Coveralls
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.COVERALLS_REPO_TOKEN }}
parallel: true
flag-name: tc${{ matrix.tc }}
- name: Clean up
if: always()
run: pkill -9 nats-server 2>/dev/null || true

coveralls-finish:
needs: build
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./core
steps:
- name: Coveralls Finish
uses: coverallsapp/github-action@v2
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
parallel-finished: true
carryforward: "tc17"
37 changes: 37 additions & 0 deletions .github/workflows/build-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Build Publish Release
permissions:
contents: read
on:
release:
branches:
- main
types: [released]

jobs:
build:
strategy:
matrix:
tc: [ 8, 17, 21, 25 ]
runs-on: ubuntu-latest
env:
BUILD_EVENT: "release"
TARGET_COMPATIBILITY: ${{ matrix.tc }}
OSSRH_USERNAME: ${{ secrets.OSSRH_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.OSSRH_TOKEN }}
SIGNING_KEY_ID: ${{ secrets.SIGNING_KEY_ID }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
SIGNING_PASSWORD: ${{ secrets.SIGNING_PASSWORD }}
steps:
- name: Set up JDK
uses: actions/setup-java@v5
with:
java-version: 25
distribution: 'temurin'
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v5
with:
gradle-version: current
- name: Check out code
uses: actions/checkout@v4
- name: Build, Sign and Publish Release
run: chmod +x gradlew && ./gradlew clean compileJava publishToSonatype closeAndReleaseSonatypeStagingRepository
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ dependencies {
implementation 'io.nats:jnats:2.25.1'
implementation 'org.jspecify:jspecify:1.0.0'

testImplementation 'io.nats:jnats-server-runner:3.0.2'
testImplementation 'org.junit.jupiter:junit-jupiter:5.7.0'

testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/nats/client/impl/ApConnection.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.nats.client.impl;

import io.nats.client.Connection;
import io.nats.client.Options;
import org.jspecify.annotations.NonNull;

import java.io.IOException;

public class ApConnection extends NatsConnection {
public static Connection connect(Options options) throws IOException, InterruptedException {
return createConnection(options, true);
}

public static Connection createConnection(Options options, boolean reconnectOnConnect) throws IOException, InterruptedException {
ApConnection conn = new ApConnection(options);
conn.connect(reconnectOnConnect);
return conn;
}

ApConnection(@NonNull Options options) {
super(options);
}
}
Binary file added src/main/javadoc/images/favicon.ico
Binary file not shown.
Binary file added src/main/javadoc/images/large-logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions src/main/javadoc/overview.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<!--
Copyright 2020-2026 The NATS Authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at:
//
http://www.apache.org/licenses/LICENSE-2.0
//
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<html>
<head></head>
<body>
<a>Java Core for implementing of NATS NKEYS utility providers.</a>
<p><img src="large-logo.png" alt="nats logo"></p>

<p>NATS Server is a simple, high performance open source messaging system for cloud native applications, IoT messaging, and microservices architectures.
This Java API opens the server to Java applications. The API is performant, supporting millions of messages a second, and easy to use.
</p>

<p>The library is the interface for packages used to create and use NKEYS in Java code.</p>

<p><em>This package is implemented with Java 8 features.</em></p>

</body>
</html>
30 changes: 30 additions & 0 deletions src/test/java/io/ResourceUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io;

import java.io.File;
import java.nio.file.Files;
import java.util.List;

@SuppressWarnings("DataFlowIssue")
public abstract class ResourceUtils {
public static List<String> resourceAsLines(String fileName) {
try {
ClassLoader classLoader = ResourceUtils.class.getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
return Files.readAllLines(file.toPath());
}
catch (Exception e) {
throw new RuntimeException(e);
}
}

public static byte[] resourceAsBytes(String fileName) {
try {
ClassLoader classLoader = ResourceUtils.class.getClassLoader();
File file = new File(classLoader.getResource(fileName).getFile());
return Files.readAllBytes(file.toPath());
}
catch (Exception e) {
throw new RuntimeException(e);
}
}
}
53 changes: 53 additions & 0 deletions src/test/java/io/nats/client/ConnectTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.nats.client;

import io.nats.NatsRunnerUtils;
import io.nats.NatsServerRunner;
import io.nats.client.api.ServerInfo;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;

import java.io.IOException;
import java.util.logging.Level;

import static io.nats.client.utils.ConnectionUtils.managedConnect;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ConnectTests {
static NatsServerRunner RUNNER;
static int RUNNER_PORT;

@BeforeAll
static void beforeAll() throws IOException {
NatsRunnerUtils.setDefaultOutputLevel(Level.SEVERE);
RUNNER = NatsServerRunner.builder().build();
RUNNER_PORT = RUNNER.getPort();
}

@AfterAll
static void afterAll() throws IOException {
try {
RUNNER.shutdown();
}
catch (InterruptedException e) {
// ignore, shutting down anyway
}
}

private static Options.Builder getOptionsBuilder() {
return Options.builder().server(NatsRunnerUtils.getNatsLocalhostUri(RUNNER_PORT));
}

private static Options getOptions() {
return getOptionsBuilder().build();
}

@Test
public void testConnection() throws Exception {
Options options = getOptions();
try (Connection apc = managedConnect(options)) {
ServerInfo info = apc.getServerInfo();
assertEquals(RUNNER_PORT, info.getPort());
}
}
}
Loading
Loading