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
37 changes: 24 additions & 13 deletions src/main/java/io/nats/service/Endpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
* </p>
*/
public class Endpoint implements JsonSerializable {
private static final String DEFAULT_QGROUP = "q";
public static final String DEFAULT_QGROUP = "q";

private final String name;
private final String subject;
Expand All @@ -49,7 +49,7 @@ public class Endpoint implements JsonSerializable {
* @param name the name
*/
public Endpoint(String name) {
this(name, null, null, null, true);
this(name, null, DEFAULT_QGROUP, null, true);
}

/**
Expand All @@ -58,7 +58,7 @@ public Endpoint(String name) {
* @param metadata the metadata
*/
public Endpoint(String name, Map<String, String> metadata) {
this(name, null, null, metadata, true);
this(name, null, DEFAULT_QGROUP, metadata, true);
}

/**
Expand All @@ -67,7 +67,7 @@ public Endpoint(String name, Map<String, String> metadata) {
* @param subject the subject
*/
public Endpoint(String name, String subject) {
this(name, subject, null, null, true);
this(name, subject, DEFAULT_QGROUP, null, true);
}

/**
Expand All @@ -77,7 +77,7 @@ public Endpoint(String name, String subject) {
* @param metadata the metadata
*/
public Endpoint(String name, String subject, Map<String, String> metadata) {
this(name, subject, null, metadata, true);
this(name, subject, DEFAULT_QGROUP, metadata, true);
}

/**
Expand All @@ -101,12 +101,7 @@ public Endpoint(String name, String subject, String queueGroup, Map<String, Stri
else {
this.subject = Validator.validateSubjectTerm(subject, "Endpoint Subject", false);
}
if (queueGroup == null) {
this.queueGroup = DEFAULT_QGROUP;
}
else {
this.queueGroup = Validator.validateSubjectTerm(queueGroup, "Endpoint Queue Group", true);
}
this.queueGroup = queueGroup == null ? null : Validator.validateSubjectTerm(queueGroup, "Endpoint Queue Group", true);
}
else {
this.name = name;
Expand Down Expand Up @@ -202,10 +197,15 @@ public Builder() {}
* @return the Endpoint.Builder
*/
public Builder endpoint(Endpoint endpoint) {
return name(endpoint.getName())
name(endpoint.getName())
.subject(endpoint.getSubject())
.queueGroup(endpoint.getQueueGroup())
.metadata(endpoint.getMetadata());

if (endpoint.queueGroup == null) {
return noQueueGroup();
}

return queueGroup(endpoint.getQueueGroup());
}

/**
Expand All @@ -220,6 +220,8 @@ public Builder name(String name) {

/**
* Set the queueGroup for the Endpoint, overriding the system default queue group
* Setting to null sets the group to the default qgroup, {@value #DEFAULT_QGROUP}. If you
* do not want a queue group, use {@link #noQueueGroup() noQueueGroup()}
* @param queueGroup the queueGroup
* @return the Endpoint.Builder
*/
Expand All @@ -228,6 +230,15 @@ public Builder queueGroup(String queueGroup) {
return this;
}

/**
* Set to not use a queueGroup for this endpoint
* @return the Endpoint.Builder
*/
public Builder noQueueGroup() {
this.queueGroup = null;
return this;
}

/**
* Set the subject for the Endpoint, replacing any subject already set.
* @param subject the subject
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/io/nats/service/EndpointContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,12 @@ class EndpointContext {

void start() {
if (sub == null) {
sub = qGroup == null
? dispatcher.subscribe(se.getSubject(), this::onMessage)
: dispatcher.subscribe(se.getSubject(), qGroup, this::onMessage);
if (qGroup == null) {
dispatcher.subscribe(se.getSubject(), this::onMessage);
}
else {
dispatcher.subscribe(se.getSubject(), qGroup, this::onMessage);
}
started = DateTimeUtils.gmtNow();
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/nats/service/ServiceEndpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ public class ServiceEndpoint {
private final Dispatcher dispatcher;
private final Supplier<JsonValue> statsDataSupplier;

private ServiceEndpoint(Builder b, Endpoint e) {
private ServiceEndpoint(Builder b, Endpoint endpoint) {
this.group = b.group;
this.endpoint = e;
this.endpoint = endpoint;
this.handler = b.handler;
this.dispatcher = b.dispatcher;
this.statsDataSupplier = b.statsDataSupplier;
Expand Down
Loading
Loading