diff --git a/src/main/java/io/nats/client/api/MessageBatchGetRequest.java b/src/main/java/io/nats/client/api/MessageBatchGetRequest.java index 3be679f43..860497b2d 100644 --- a/src/main/java/io/nats/client/api/MessageBatchGetRequest.java +++ b/src/main/java/io/nats/client/api/MessageBatchGetRequest.java @@ -31,7 +31,6 @@ */ public class MessageBatchGetRequest implements JsonSerializable { - private final Duration timeout; private final int batch; private final int maxBytes; private final long sequence; @@ -42,7 +41,6 @@ public class MessageBatchGetRequest implements JsonSerializable { private final ZonedDateTime upToTime; MessageBatchGetRequest(Builder b) { - this.timeout = b.timeout; this.batch = b.batch; this.maxBytes = b.maxBytes; this.sequence = b.sequence; @@ -53,15 +51,6 @@ public class MessageBatchGetRequest implements JsonSerializable { this.upToTime = b.upToTime; } - /** - * Timeout used for the request. - * - * @return Duration - */ - public Duration getTimeout() { - return timeout; - } - /** * Maximum amount of messages to be returned for this request. * @@ -178,7 +167,6 @@ public static Builder builder(MessageBatchGetRequest req) { *
{@code MessageBatchGetRequest.builder().build()} will create a default {@link MessageBatchGetRequest}. */ public static class Builder { - private Duration timeout = Duration.ofSeconds(5); private int batch = -1; private int maxBytes = -1; private long sequence = -1; @@ -201,7 +189,6 @@ public Builder() { */ public Builder(MessageBatchGetRequest req) { if (req != null) { - this.timeout = req.timeout; this.batch = req.batch; this.maxBytes = req.maxBytes; this.sequence = req.sequence; @@ -213,18 +200,6 @@ public Builder(MessageBatchGetRequest req) { } } - /** - * Set the timeout used for the request. - * - * @param timeout the timeout - * @return Builder - */ - public Builder timeout(Duration timeout) { - validateDurationRequired(timeout); - this.timeout = timeout; - return this; - } - /** * Set the maximum amount of messages to be returned for this request. * diff --git a/src/main/java/io/nats/client/impl/NatsJetStreamManagement.java b/src/main/java/io/nats/client/impl/NatsJetStreamManagement.java index b5f69aee0..21ecf8a98 100644 --- a/src/main/java/io/nats/client/impl/NatsJetStreamManagement.java +++ b/src/main/java/io/nats/client/impl/NatsJetStreamManagement.java @@ -389,9 +389,9 @@ public void _requestMessageBatch(String streamName, MessageBatchGetRequest messa String requestSubject = prependPrefix(String.format(JSAPI_DIRECT_GET, streamName)); conn.publish(requestSubject, replyTo, messageBatchGetRequest.serialize()); - long start = System.currentTimeMillis(); - long maxTimeMillis = messageBatchGetRequest.getTimeout().toMillis(); + long maxTimeMillis = getTimeout().toMillis(); long timeLeft = maxTimeMillis; + long start = System.currentTimeMillis(); while (true) { Message msg = sub.nextMessage(timeLeft); if (msg == null) { diff --git a/src/test/java/io/nats/client/impl/JetStreamManagementTests.java b/src/test/java/io/nats/client/impl/JetStreamManagementTests.java index e05f21434..757b79f2d 100644 --- a/src/test/java/io/nats/client/impl/JetStreamManagementTests.java +++ b/src/test/java/io/nats/client/impl/JetStreamManagementTests.java @@ -1729,16 +1729,11 @@ public void testBatchDirectGetMultiLast() throws Exception { @Test public void testBatchDirectGetBuilder() { - // Default timeout - assertEquals(Duration.ofSeconds(5), MessageBatchGetRequest.builder().build().getTimeout()); - // Request options. MessageBatchGetRequest requestOptions = MessageBatchGetRequest.builder() - .timeout(Duration.ofSeconds(1)) .maxBytes(1234) .batch(2) .build(); - assertEquals(Duration.ofSeconds(1), requestOptions.getTimeout()); assertEquals(1234, requestOptions.getMaxBytes()); assertEquals(2, requestOptions.getBatch()); assertEquals("{\"batch\":2,\"max_bytes\":1234}", requestOptions.toJson());