diff --git a/README.MD b/README.MD index 5a255eb..73a5077 100644 --- a/README.MD +++ b/README.MD @@ -14,13 +14,26 @@ For Maven: np.com.madanpokharel.embed nats-embedded - 2.0.0 + 2.1.0 test ``` -For Gradle: +For Gradle(Groovy Style): ``` groovy -testCompile group: 'np.com.madanpokharel.embed', name: 'nats-embedded', version: '1.1.0' +testCompile group: 'np.com.madanpokharel.embed', name: 'nats-embedded', version: '2.1.0' +``` + +For Gradle +```kotlin +implementation("np.com.madanpokharel.embed:nats-embedded:2.1.0") +``` +For Bazel +``` +maven_jar( + name = "nats-embedded", + artifact = "np.com.madanpokharel.embed:nats-embedded:2.1.0", + sha1 = "0235584434668a4dfbb9b7a0211cf3c9642e99bd", +) ``` #### Example @@ -31,7 +44,7 @@ Start nats server with defined port 7656. EmbeddedNatsConfig config = new EmbeddedNatsConfig.Builder() .withNatsServerConfig( new NatsServerConfig.Builder() - .withServerType(ServerType.NATS) + .withServerType(ServerType.NATS) //Can be omitted, default is Nats .withPort(7656) .withNatsVersion(NatsVersion.LATEST) .build() @@ -133,5 +146,21 @@ EmbeddedNatsConfig config = new EmbeddedNatsConfig.Builder() .build(); ``` +Using custom nats configuration file +```java +new NatsServerConfig.Builder() + .withConfigurationFile("custom-config-file.conf") + .build() +``` +Enabling JetStream +```java + new NatsServerConfig.Builder() + .withEnableJetStream() //without store location + .build() + +new NatsServerConfig.Builder() + .withEnableJetStream("target") //with store location + .build() +``` ### Dependency This library using component from [flapdoodle-oss](https://github.com/flapdoodle-oss) diff --git a/pom.xml b/pom.xml index 67e255a..d98bf88 100644 --- a/pom.xml +++ b/pom.xml @@ -58,7 +58,7 @@ np.com.madanpokharel.embed nats-embedded - 2.0.0-SNAPSHOT + 2.1.0 jar diff --git a/src/main/java/np/com/madanpokharel/embed/nats/NatsServerConfig.java b/src/main/java/np/com/madanpokharel/embed/nats/NatsServerConfig.java index d0d59ad..10d881b 100644 --- a/src/main/java/np/com/madanpokharel/embed/nats/NatsServerConfig.java +++ b/src/main/java/np/com/madanpokharel/embed/nats/NatsServerConfig.java @@ -29,7 +29,6 @@ *

NatsServerConfig class.

* * @author Madan Pokharel - * */ public final class NatsServerConfig implements ExecutableProcessConfig { @@ -51,8 +50,12 @@ public final class NatsServerConfig implements ExecutableProcessConfig { * @param serverType a {@link np.com.madanpokharel.embed.nats.ServerType} object. * @param configParams a {@link java.util.Map} object. */ - public NatsServerConfig(Version version, int port, String host, - String clusterId, ServerType serverType, Map configParams) { + public NatsServerConfig(Version version, + int port, + String host, + String clusterId, + ServerType serverType, + Map configParams) { this.version = version; this.port = port; this.host = host; @@ -84,9 +87,9 @@ public Version version() { @Override public SupportConfig supportConfig() { return SupportConfig.builder().name("nats-streaming-server") - .supportUrl("https://github.com/madansp/nats-embedded") - .messageOnException((clazz, e) -> e.getMessage()) - .build(); + .supportUrl("https://github.com/madansp/nats-embedded") + .messageOnException((clazz, e) -> e.getMessage()) + .build(); } @Override @@ -113,12 +116,12 @@ List getConfigList() { configMap.add(clusterId); } - if (!configMap.isEmpty()) { - params.forEach((k, v) -> { - configMap.add(k); + params.forEach((k, v) -> { + configMap.add(k); + if (!v.isEmpty()) { configMap.add(v); - }); - } + } + }); return configMap; } @@ -212,8 +215,27 @@ public Builder withConfigParam(String param, String value) { return this; } + public Builder withEnableJetStream(String storeDir) { + configParams.put("-js", ""); + configParams.put("-sd", storeDir); + return this; + } + + public Builder withEnableJetStream() { + configParams.put("-js", ""); + return this; + } + + public Builder withConfigurationFile(String filePath) { + configParams.put("-c", filePath); + return this; + } + + public NatsServerConfig build() { - Objects.requireNonNull(serverType, "server type cannot be null"); + if (serverType == null) { + serverType = ServerType.NATS; + } if (Objects.isNull(version)) { if (serverType == ServerType.NATS) { diff --git a/src/main/java/np/com/madanpokharel/embed/nats/NatsStreamingVersion.java b/src/main/java/np/com/madanpokharel/embed/nats/NatsStreamingVersion.java index a05270b..caeb141 100644 --- a/src/main/java/np/com/madanpokharel/embed/nats/NatsStreamingVersion.java +++ b/src/main/java/np/com/madanpokharel/embed/nats/NatsStreamingVersion.java @@ -27,7 +27,98 @@ public class NatsStreamingVersion implements Version { /** * Constant LATEST */ - public static final NatsStreamingVersion LATEST = new NatsStreamingVersion("v0.17.0"); + public static final NatsStreamingVersion LATEST = new NatsStreamingVersion("v0.24.6"); + + /** + * Constant V0_24_6 + */ + public static final NatsStreamingVersion V0_24_6 = new NatsStreamingVersion("v0.24.6"); + + /** + * Constant V0_24_5 + */ + public static final NatsStreamingVersion V0_24_5 = new NatsStreamingVersion("v0.24.5"); + + /** + * Constant V0_24_4 + */ + public static final NatsStreamingVersion V0_24_4 = new NatsStreamingVersion("v0.24.4"); + + /** + * Constant V0_24_3 + */ + public static final NatsStreamingVersion V0_24_3 = new NatsStreamingVersion("v0.24.3"); + + /** + * Constant V0_24_2 + */ + public static final NatsStreamingVersion V0_24_2 = new NatsStreamingVersion("v0.24.2"); + + /** + * Constant V0_24_1 + */ + public static final NatsStreamingVersion V0_24_1 = new NatsStreamingVersion("v0.24.1"); + + /** + * Constant V0_24_0 + */ + public static final NatsStreamingVersion V0_24_0 = new NatsStreamingVersion("v0.24.0"); + + /** + * Constant V0_23_2 + */ + public static final NatsStreamingVersion V0_23_2 = new NatsStreamingVersion("v0.23.2"); + + /** + * Constant V0_23_1 + */ + public static final NatsStreamingVersion V0_23_1 = new NatsStreamingVersion("v0.23.1"); + + /** + * Constant V0_23_0 + */ + public static final NatsStreamingVersion V0_23_0 = new NatsStreamingVersion("v0.23.0"); + + /** + * Constant V0_22_1 + */ + public static final NatsStreamingVersion V0_22_1 = new NatsStreamingVersion("v0.21.1"); + + /** + * Constant V0_22_0 + */ + public static final NatsStreamingVersion V0_22_0 = new NatsStreamingVersion("v0.22.0"); + + /** + * Constant V0_21_2 + */ + public static final NatsStreamingVersion V0_21_2 = new NatsStreamingVersion("v0.21.2"); + + /** + * Constant V0_21_1 + */ + public static final NatsStreamingVersion V0_21_1 = new NatsStreamingVersion("v0.21.1"); + + /** + * Constant V0_21_0 + */ + public static final NatsStreamingVersion V0_21_0 = new NatsStreamingVersion("v0.21.0"); + + /** + * Constant V0_20_0 + */ + public static final NatsStreamingVersion V0_20_0 = new NatsStreamingVersion("v0.20.0"); + + /** + * Constant V0_19_0 + */ + public static final NatsStreamingVersion V0_19_0 = new NatsStreamingVersion("v0.19.0"); + + /** + * Constant V0_18_0 + */ + public static final NatsStreamingVersion V0_18_0 = new NatsStreamingVersion("v0.18.0"); + /** * Constant V0_17_0 diff --git a/src/main/java/np/com/madanpokharel/embed/nats/NatsVersion.java b/src/main/java/np/com/madanpokharel/embed/nats/NatsVersion.java index 302e88c..276d405 100644 --- a/src/main/java/np/com/madanpokharel/embed/nats/NatsVersion.java +++ b/src/main/java/np/com/madanpokharel/embed/nats/NatsVersion.java @@ -27,7 +27,177 @@ public class NatsVersion implements Version { /** * Constant LATEST */ - public static final NatsVersion LATEST = new NatsVersion("v2.1.6"); + public static final NatsVersion LATEST = new NatsVersion("v2.8.4"); + + /** + * Constant V2_8_4 + */ + public static final NatsVersion V2_8_4 = new NatsVersion("v2.8.4"); + + /** + * Constant V2_8_3 + */ + public static final NatsVersion V2_8_3 = new NatsVersion("v2.8.3"); + + /** + * Constant V2_8_2 + */ + public static final NatsVersion V2_8_2 = new NatsVersion("v2.8.2"); + + /** + * Constant V2_8_1 + */ + public static final NatsVersion V2_8_1 = new NatsVersion("v2.8.1"); + + /** + * Constant V2_8_0 + */ + public static final NatsVersion V2_8_0 = new NatsVersion("v2.8.0"); + + /** + * Constant V2_7_4 + */ + public static final NatsVersion V2_7_4 = new NatsVersion("v2.7.4"); + + /** + * Constant V2_7_3 + */ + public static final NatsVersion V2_7_3 = new NatsVersion("v2.7.3"); + + /** + * Constant V2_7_2 + */ + public static final NatsVersion V2_7_2 = new NatsVersion("v2.7.2"); + + /** + * Constant V2_7_1 + */ + public static final NatsVersion V2_7_1 = new NatsVersion("v2.7.1"); + + /** + * Constant V2_7_0 + */ + public static final NatsVersion V2_7_0 = new NatsVersion("v2.7.0"); + + /** + * Constant V2_6_6 + */ + public static final NatsVersion V2_6_6 = new NatsVersion("v2.6.6"); + + /** + * Constant V2_6_5 + */ + public static final NatsVersion V2_6_5 = new NatsVersion("v2.6.5"); + + /** + * Constant V2_6_4 + */ + public static final NatsVersion V2_6_4 = new NatsVersion("v2.6.4"); + + /** + * Constant V2_6_3 + */ + public static final NatsVersion V2_6_3 = new NatsVersion("v2.6.3"); + + /** + * Constant V2_6_2 + */ + public static final NatsVersion V2_6_2 = new NatsVersion("v2.6.2"); + + /** + * Constant V2_6_1 + */ + public static final NatsVersion V2_6_1 = new NatsVersion("v2.6.1"); + + /** + * Constant V2_6_0 + */ + public static final NatsVersion V2_6_0 = new NatsVersion("v2.6.0"); + + /** + * Constant V2_5_0 + */ + public static final NatsVersion V2_5_0 = new NatsVersion("v2.5.0"); + + /** + * Constant V2_4_0 + */ + public static final NatsVersion V2_4_0 = new NatsVersion("v2.4.0"); + + /** + * Constant V2_3_4 + */ + public static final NatsVersion V2_3_4 = new NatsVersion("v2.3.4"); + + /** + * Constant V2_3_3 + */ + public static final NatsVersion V2_3_3 = new NatsVersion("v2.3.3"); + + /** + * Constant V2_3_2 + */ + public static final NatsVersion V2_3_2 = new NatsVersion("v2.3.2"); + + /** + * Constant V2_3_1 + */ + public static final NatsVersion V2_3_1 = new NatsVersion("v2.3.1"); + + /** + * Constant V2_3_0 + */ + public static final NatsVersion V2_3_0 = new NatsVersion("v2.3.0"); + + /** + * Constant V2_2_6 + */ + public static final NatsVersion V2_2_6 = new NatsVersion("v2.2.6"); + + /** + * Constant V2_2_5 + */ + public static final NatsVersion V2_2_5 = new NatsVersion("v2.2.5"); + + /** + * Constant V2_2_4 + */ + public static final NatsVersion V2_2_4 = new NatsVersion("v2.2.4"); + + /** + * Constant V2_2_3 + */ + public static final NatsVersion V2_2_3 = new NatsVersion("v2.2.3"); + + /** + * Constant V2_2_2 + */ + public static final NatsVersion V2_2_2 = new NatsVersion("v2.2.2"); + + /** + * Constant V2_2_1 + */ + public static final NatsVersion V2_2_1 = new NatsVersion("v2.2.1"); + + /** + * Constant V2_2_0 + */ + public static final NatsVersion V2_2_0 = new NatsVersion("v2.2.0"); + + /** + * Constant V2_1_9 + */ + public static final NatsVersion V2_1_9 = new NatsVersion("v2.1.9"); + + /** + * Constant V2_1_8 + */ + public static final NatsVersion V2_1_8 = new NatsVersion("v2.1.8"); + + /** + * Constant V2_1_7 + */ + public static final NatsVersion V2_1_7 = new NatsVersion("v2.1.7"); /** * Constant V2_1_6 diff --git a/src/test/java/np/com/madanpokharel/embed/nats/EmbeddedNatsTest.java b/src/test/java/np/com/madanpokharel/embed/nats/EmbeddedNatsTest.java index 2df15bd..cdeb8d7 100644 --- a/src/test/java/np/com/madanpokharel/embed/nats/EmbeddedNatsTest.java +++ b/src/test/java/np/com/madanpokharel/embed/nats/EmbeddedNatsTest.java @@ -35,8 +35,8 @@ public void testNatsWithServerConfig() throws Exception { EmbeddedNatsConfig config = new EmbeddedNatsConfig.Builder() .withNatsServerConfig( new NatsServerConfig.Builder() - .withServerType(ServerType.NATS) .withPort(port) + .withEnableJetStream() .withNatsVersion(NatsVersion.LATEST) .build() )