Skip to content

Commit

Permalink
ordered consumer config setting changes (#762)
Browse files Browse the repository at this point in the history
  • Loading branch information
scottf authored Oct 5, 2022
1 parent 1c235d3 commit 721801e
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 7 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,12 @@ When creating the subscription, there are some restrictions for the consumer con

You can however set the deliver policy which will be used to start the subscription.

### Subscription Creation Checks
### Client Error Messages

Subscription creation has many checks to make sure that a valid, operable subscription can be made.
`SO` group are validations that can occur when building push or pull subscribe options.
`SUB` group are validations that occur when creating a subscription.
In addition to some generic validation messages for values in builders, there are also additional grouped and numbered client error messages:
* Subscription building and creation
* Consumer creation
* Object Store operations

| Name | Group | Code | Description |
|----------------------------------------------|-------|-------|-----------------------------------------------------------------------------------------------------|
Expand All @@ -577,6 +578,8 @@ Subscription creation has many checks to make sure that a valid, operable subscr
| JsSoOrderedRequiresAckPolicyNone | SO | 90108 | Ordered consumer requires Ack Policy None. |
| JsSoOrderedRequiresMaxDeliver | SO | 90109 | Max deliver is limited to 1 with an ordered consumer. |
| JsSoNameMismatch | SO | 90110 | Builder name must match the consumer configuration name if both are provided. |
| JsSoOrderedMemStorageNotSuppliedOrTrue | SO | 90111 | Mem Storage must be true if supplied. |
| JsSoOrderedReplicasNotSuppliedOrOne | SO | 90112 | Replicas must be 1 if supplied. |
| JsSubPullCantHaveDeliverGroup | SUB | 90001 | Pull subscriptions can't have a deliver group. |
| JsSubPullCantHaveDeliverSubject | SUB | 90002 | Pull subscriptions can't have a deliver subject. |
| JsSubPushCantHaveMaxPullWaiting | SUB | 90003 | Push subscriptions cannot supply max pull waiting. |
Expand All @@ -597,6 +600,8 @@ Subscription creation has many checks to make sure that a valid, operable subscr
| JsSubOrderedNotAllowOnQueues | SUB | 90018 | Ordered consumer not allowed on queues. |
| JsSubPushCantHaveMaxBatch | SUB | 90019 | Push subscriptions cannot supply max batch. |
| JsSubPushCantHaveMaxBytes | SUB | 90020 | Push subscriptions cannot supply max bytes. |
| JsConsumerCreate290NotAvailable | CON | 90301 | Name field not valid when v2.9.0 consumer create api is not available. |
| JsConsumerNameDurableMismatch | CON | 90302 | Name must match durable if both are supplied. |
| OsObjectNotFound | OS | 90201 | The object was not found. |
| OsObjectIsDeleted | OS | 90202 | The object is deleted. |
| OsObjectAlreadyExists | OS | 90203 | An object with that name already exists. |
Expand All @@ -606,8 +611,6 @@ Subscription creation has many checks to make sure that a valid, operable subscr
| OsGetSizeMismatch | OS | 90207 | Total size does not match meta data. |
| OsGetLinkToBucket | OS | 90208 | Cannot get object, it is a link to a bucket. |
| OsLinkNotAllowOnPut | OS | 90209 | Link not allowed in metadata when putting an object. |
| JsConsumerCreate290NotAvailable | CON | 90301 | Name field not valid when v2.9.0 consumer create api is not available. |
| JsConsumerNameDurableMismatch | CON | 90302 | Name must match durable if both are supplied. |

### Message Acknowledgements

Expand Down
8 changes: 8 additions & 0 deletions src/main/java/io/nats/client/SubscribeOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ protected SubscribeOptions(Builder builder, boolean isPull, boolean isOrdered, S
if (builder.cc.getMaxDeliver() > 1) {
throw JsSoOrderedRequiresMaxDeliver.instance();
}
if (builder.cc.memStorageWasSet() && !builder.cc.isMemStorage()) {
throw JsSoOrderedMemStorageNotSuppliedOrTrue.instance();
}
if (builder.cc.numReplicasWasSet() && builder.cc.getNumReplicas() != 1) {
throw JsSoOrderedReplicasNotSuppliedOrOne.instance();
}
Duration ccHb = builder.cc.getIdleHeartbeat();
if (ccHb != null && ccHb.toMillis() > hb) {
hb = ccHb.toMillis();
Expand All @@ -84,6 +90,8 @@ protected SubscribeOptions(Builder builder, boolean isPull, boolean isOrdered, S
.flowControl(hb)
.ackWait(Duration.ofHours(22))
.name(name)
.memStorage(true)
.numReplicas(1)
.build();
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,10 @@ public class NatsJetStreamClientError {
public static final NatsJetStreamClientError JsSoOrderedNotAllowedWithDurable = new NatsJetStreamClientError(SO, 90106, "Durable is not allowed with an ordered consumer.");
public static final NatsJetStreamClientError JsSoOrderedNotAllowedWithDeliverSubject = new NatsJetStreamClientError(SO, 90107, "Deliver subject is not allowed with an ordered consumer.");
public static final NatsJetStreamClientError JsSoOrderedRequiresAckPolicyNone = new NatsJetStreamClientError(SO, 90108, "Ordered consumer requires Ack Policy None.");
public static final NatsJetStreamClientError JsSoOrderedRequiresMaxDeliver = new NatsJetStreamClientError(SO, 90109, "Max deliver is limited to 1 with an ordered consumer.");
public static final NatsJetStreamClientError JsSoOrderedRequiresMaxDeliver = new NatsJetStreamClientError(SO, 90109, "Max Deliver is limited to 1 with an ordered consumer.");
public static final NatsJetStreamClientError JsSoNameMismatch = new NatsJetStreamClientError(SO, 90110, "Builder name must match the consumer configuration name if both are provided.");
public static final NatsJetStreamClientError JsSoOrderedMemStorageNotSuppliedOrTrue = new NatsJetStreamClientError(SO, 90111, "Mem Storage must be true if supplied.");
public static final NatsJetStreamClientError JsSoOrderedReplicasNotSuppliedOrOne = new NatsJetStreamClientError(SO, 90112, "Replicas must be 1 if supplied.");

public static final NatsJetStreamClientError OsObjectNotFound = new NatsJetStreamClientError(OS, 90201, "The object was not found.");
public static final NatsJetStreamClientError OsObjectIsDeleted = new NatsJetStreamClientError(OS, 90202, "The object is deleted.");
Expand Down
18 changes: 18 additions & 0 deletions src/test/java/io/nats/client/SubscribeOptionsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -317,5 +317,23 @@ public void testOrderedCreation() {
ccHb = ConsumerConfiguration.builder().idleHeartbeat(DEFAULT_ORDERED_HEARTBEAT + 1).build();
pso = PushSubscribeOptions.builder().configuration(ccHb).ordered(true).build();
assertEquals(DEFAULT_ORDERED_HEARTBEAT + 1, pso.getConsumerConfiguration().getIdleHeartbeat().toMillis());

// okay if you set it to true
ConsumerConfiguration cc = ConsumerConfiguration.builder().memStorage(true).build();
PushSubscribeOptions.builder().configuration(cc).ordered(true).build();

// okay if you set it to 1
cc = ConsumerConfiguration.builder().numReplicas(1).build();
PushSubscribeOptions.builder().configuration(cc).ordered(true).build();

// not okay if you set it to false
ConsumerConfiguration ccMs = ConsumerConfiguration.builder().memStorage(false).build();
assertClientError(JsSoOrderedMemStorageNotSuppliedOrTrue,
() -> PushSubscribeOptions.builder().configuration(ccMs).ordered(true).build());

// not okay if you set it to something other than 1
ConsumerConfiguration ccR = ConsumerConfiguration.builder().numReplicas(3).build();
assertClientError(JsSoOrderedReplicasNotSuppliedOrOne,
() -> PushSubscribeOptions.builder().configuration(ccR).ordered(true).build());
}
}

0 comments on commit 721801e

Please sign in to comment.