Skip to content

Commit ee5668a

Browse files
authored
Merge pull request #13 from YunaBraska/release
Release Former-commit-id: 4217442
2 parents 50afb8f + 63909fe commit ee5668a

11 files changed

Lines changed: 570 additions & 568 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Embedded [Nats streaming server](https://github.com/nats-io/nats-streaming-serve
1313

1414
### Usage
1515
* One annotation to setup the powerful [Nats streaming server](https://github.com/nats-io/nats-streaming-server)
16-
```
16+
```java
1717
@SpringBootTest
1818
@RunWith(SpringRunner.class)
1919
@EnableNatsServer(port = 4222, natsServerConfig = {"user:admin", "password:admin"})

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<groupId>berlin.yuna</groupId>
1414
<artifactId>nats-streaming-server-embedded</artifactId>
15-
<version>0.2.0</version>
15+
<version>0.2.1</version>
1616
<packaging>jar</packaging>
1717

1818
<name>${project.artifactId}</name>
@@ -56,6 +56,12 @@
5656
<version>2.8.5</version>
5757
<scope>test</scope>
5858
</dependency>
59+
<dependency>
60+
<groupId>berlin.yuna</groupId>
61+
<artifactId>config-metadata-generator</artifactId>
62+
<version>0.2.0</version>
63+
<scope>test</scope>
64+
</dependency>
5965
</dependencies>
6066

6167
<scm>

src/main/java/berlin/yuna/natsserver/annotation/EnableNatsServerContextCustomizer.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,7 @@ public void customizeContext(ConfigurableApplicationContext context, MergedConte
5454
try {
5555
natsServerBean.start();
5656
} catch (Exception e) {
57-
throw new IllegalArgumentException("Failed to initialise " + EnableNatsServer.class.getSimpleName(), e);
58-
// LOG.error("Failed to initialise [{}]", EnableNatsServer.class.getSimpleName(), e);
57+
throw new IllegalArgumentException("Failed to initialise " + EnableNatsServer.class.getSimpleName(), e);
5958
}
6059

6160
beanFactory.initializeBean(natsServerBean, NatsServer.BEAN_NAME);

src/main/java/berlin/yuna/natsserver/config/NatsServerConfig.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ public enum NatsServerConfig {
99
STORE("MEMORY", "[STRING] Store type: MEMORY|FILE (default: MEMORY)"),
1010
DIR(null, "[STRING] For FILE store type, this is the root directory"),
1111
MAX_CHANNELS("0", "[INT] Max number of channels (0 for unlimited)"),
12-
MAX_SUBS("0", "[INT] Max number of subscriptions per channel (0 for unlimited)"),
13-
MAX_MSGS("0", "[INT] Max number of messages per channel (0 for unlimited)"),
14-
MAX_BYTES("0", "[SIZE] Max messages total size per channel (0 for unlimited)"),
12+
MAX_SUBS(0, "[INT] Max number of subscriptions per channel (0 for unlimited)"),
13+
MAX_MSGS(0, "[INT] Max number of messages per channel (0 for unlimited)"),
14+
MAX_BYTES(0L, "[SIZE] Max messages total size per channel (0 for unlimited)"),
1515
MAX_AGE("0s", "[DURATION] Max duration a message can be stored (\"0s\" for unlimited)"),
1616
MAX_INACTIVITY("0", "[DURATION] Max inactivity (no new message, no subscription) after which a channel can be garbage collected (0 for unlimited)"),
1717
NATS_SERVER(null, "[STRING] Connect to this external NATS Server URL (embedded otherwise)"),
@@ -51,7 +51,7 @@ public enum NatsServerConfig {
5151

5252
//Streaming Server SQL Store Options
5353
SQL_DRIVER(null, "[STRING] Name of the SQL Driver (\"mysql\" or \"postgres\")"),
54-
SQL_DATA_SOURCE(null, "[STRING] Datasource used when opening an SQL connection to the database"),
54+
SQL_SOURCE(null, "[STRING] Datasource used when opening an SQL connection to the database"),
5555
SQL_NO_CACHING(null, "[BOOL] Enable/Disable caching for improved performance"),
5656
SQL_MAX_OPEN_CONNS(null, "[INT] Maximum number of opened connections to the database"),
5757

@@ -62,49 +62,50 @@ public enum NatsServerConfig {
6262
TLS_CLIENT_CACERT(null, "-[STRING] Client certificate CA for the streaming server"),
6363

6464
//Streaming Server Logging Options
65-
STAN_DEBUG("false", "[BOOL] Enable STAN debugging output"),
66-
STAN_TRACE("false", "[BOOL] Trace the raw STAN protocol"),
65+
STAN_DEBUG(false, "[BOOL] Enable STAN debugging output"),
66+
STAN_TRACE(false, "[BOOL] Trace the raw STAN protocol"),
6767

6868
//NATS Server Options
6969
ADDR("0.0.0.0", "[STRING] Bind to host address (default: 0.0.0.0)"),
70-
PORT("4222", "[INT] Use port for clients (default: 4222)"),
70+
PORT(4222, "[INT] Use port for clients (default: 4222)"),
7171
PID(null, "[STRING] File to store PID"),
7272
HTTP_PORT(null, "[INT] Use port for http monitoring"),
7373
HTTPS_PORT(null, "[INT] Use port for https monitoring"),
7474
CONFIG(null, "[STRING] Configuration file"),
7575

7676
//NATS Server Logging Options
7777
LOG(null, "[STRING] File to redirect log output"),
78-
LOGTIME("true", "[BOOL] Timestamp log entries (default: true)"),
78+
LOGTIME(true, "[BOOL] Timestamp log entries (default: true)"),
7979
SYSLOG(null, "[STRING] Enable syslog as log method"),
8080
REMOTE_SYSLOG(null, "[STRING] Syslog server addr (udp://localhost:514)"),
81-
DEBUG("false", "[BOOL] Enable debugging output"),
82-
TRACE("false", "[BOOL] Trace the raw protocol"),
81+
DEBUG(false, "[BOOL] Enable debugging output"),
82+
TRACE(false, "[BOOL] Trace the raw protocol"),
8383

8484
//NATS Server Authorization Options
8585
USER(null, "[STRING] User required for connections"),
8686
PASS(null, "[STRING] Password required for connections"),
8787
AUTH(null, "[STRING] Authorization token required for connections"),
8888

8989
//TLS Options
90-
TLS("false", "[BOOL] Enable TLS, do not verify clients (default: false)"),
90+
TLS(false, "[BOOL] Enable TLS, do not verify clients (default: false)"),
9191
TLSCERT(null, "[STRING] Server certificate file"),
92+
TLSKEY(null, "[STRING] Private key for server certificate"),
9293
TLSVERIFY(null, "[BOOL] Enable TLS, verify client certificates"),
9394
TLSCACERT(null, "[STRING] Client certificate CA for verification"),
9495

9596
//NATS Clustering Options
9697
ROUTES(null, "[STRING] Routes to solicit and connect"),
9798
CLUSTER(null, "[STRING] Cluster URL for solicited routes");
9899

99-
private final String defaultValue;
100+
private final Object defaultValue;
100101
private final String description;
101102

102-
NatsServerConfig(String defaultValue, String description) {
103+
NatsServerConfig(Object defaultValue, String description) {
103104
this.defaultValue = defaultValue;
104105
this.description = description;
105106
}
106107

107-
public String getDefaultValue() {
108+
public Object getDefaultValue() {
108109
return defaultValue;
109110
}
110111

src/main/java/berlin/yuna/natsserver/logic/NatsServer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ public void start() throws IOException {
128128
throw new BindException("Address already in use [" + getPort() + "]");
129129
}
130130

131-
Path natsServerPath = getNatsServerPath();
131+
Path natsServerPath = getNatsServerPath(OPERATING_SYSTEM);
132132
LOG.info("Starting [{}] port [{}] version [{}-{}]", BEAN_NAME, getPort(), NATS_SERVER_VERSION, OPERATING_SYSTEM);
133133

134134
String command = prepareCommand(natsServerPath);
@@ -192,12 +192,12 @@ public void destroy() {
192192
*
193193
* @return Resource/{SIMPLE_CLASS_NAME}/{NATS_SERVER_VERSION}/{OPERATING_SYSTEM}/{SIMPLE_CLASS_NAME}
194194
*/
195-
private Path getNatsServerPath() {
195+
Path getNatsServerPath(OperatingSystem operatingSystem) {
196196
StringBuilder relativeResource = new StringBuilder();
197197
relativeResource.append(BEAN_NAME.toLowerCase()).append(File.separator);
198198
relativeResource.append(NATS_SERVER_VERSION).append(File.separator);
199-
relativeResource.append(OPERATING_SYSTEM.toString().toLowerCase()).append(File.separator);
200-
relativeResource.append(BEAN_NAME.toLowerCase()).append((OPERATING_SYSTEM == WINDOWS ? ".exe" : ""));
199+
relativeResource.append(operatingSystem.toString().toLowerCase()).append(File.separator);
200+
relativeResource.append(BEAN_NAME.toLowerCase()).append((operatingSystem == WINDOWS ? ".exe" : ""));
201201
return copyResourceFile(relativeResource.toString());
202202
}
203203

@@ -246,7 +246,7 @@ private Map<NatsServerConfig, String> getDefaultConfig() {
246246
Map<NatsServerConfig, String> defaultConfig = new HashMap<>();
247247
for (NatsServerConfig natsServerConfig : NatsServerConfig.values()) {
248248
if (natsServerConfig.getDefaultValue() != null) {
249-
defaultConfig.put(natsServerConfig, natsServerConfig.getDefaultValue());
249+
defaultConfig.put(natsServerConfig, natsServerConfig.getDefaultValue().toString());
250250
}
251251
}
252252
return defaultConfig;

src/main/java/berlin/yuna/natsserver/util/SystemUtil.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public static OperatingSystem getOsType() {
5858

5959
public static Process executeCommand(String command) throws IOException {
6060
ProcessBuilder builder = new ProcessBuilder();
61-
builder.command(getCommandByOsType(command));
61+
builder.command(getCommandByOsType(command));
6262
return builder.start();
6363
}
6464

0 commit comments

Comments
 (0)