-
Notifications
You must be signed in to change notification settings - Fork 159
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement Consumers Pause #1093
Changes from all commits
d47ded2
030fced
3aacf01
a0a756c
aadebce
68b6121
da6f584
1b3a97e
0af0276
838c440
e107259
b7a59d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2024 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package io.nats.client.api; | ||
|
||
import io.nats.client.support.JsonSerializable; | ||
import io.nats.client.support.JsonUtils; | ||
import java.time.ZonedDateTime; | ||
|
||
import static io.nats.client.support.ApiConstants.CONFIG; | ||
import static io.nats.client.support.ApiConstants.PAUSE_UNTIL; | ||
import static io.nats.client.support.ApiConstants.STREAM_NAME; | ||
import static io.nats.client.support.JsonUtils.addField; | ||
import static io.nats.client.support.JsonUtils.beginJson; | ||
import static io.nats.client.support.JsonUtils.endJson; | ||
|
||
/** | ||
* Object used to make a request to pause a consumer. Used Internally | ||
*/ | ||
public class ConsumerPauseRequest implements JsonSerializable { | ||
private final ZonedDateTime pauseUntil; | ||
|
||
public ConsumerPauseRequest(ZonedDateTime pauseUntil) { | ||
this.pauseUntil = pauseUntil; | ||
} | ||
|
||
@Override | ||
public String toJson() { | ||
StringBuilder sb = beginJson(); | ||
|
||
addField(sb, PAUSE_UNTIL, pauseUntil); | ||
|
||
return endJson(sb).toString(); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test for this, otherwise coverage goes down. Usually I just assign it and do something like contains("true"). Or just remove it since someone could call toJson There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have removed it |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
// Copyright 2024 The NATS Authors | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at: | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package io.nats.client.api; | ||
|
||
import io.nats.client.Message; | ||
import java.time.Duration; | ||
import java.time.ZonedDateTime; | ||
|
||
import static io.nats.client.support.ApiConstants.PAUSED; | ||
import static io.nats.client.support.ApiConstants.PAUSE_REMAINING; | ||
import static io.nats.client.support.ApiConstants.PAUSE_UNTIL; | ||
import static io.nats.client.support.JsonValueUtils.readBoolean; | ||
import static io.nats.client.support.JsonValueUtils.readDate; | ||
import static io.nats.client.support.JsonValueUtils.readLong; | ||
import static io.nats.client.support.JsonValueUtils.readNanos; | ||
|
||
public class ConsumerPauseResponse extends ApiResponse<ConsumerPauseResponse> { | ||
|
||
private final boolean paused; | ||
private final ZonedDateTime pauseUntil; | ||
private final Duration pauseRemaining; | ||
|
||
public ConsumerPauseResponse(Message msg) { | ||
super(msg); | ||
paused = readBoolean(jv, PAUSED); | ||
pauseUntil = readDate(jv, PAUSE_UNTIL); | ||
pauseRemaining = readNanos(jv, PAUSE_REMAINING); | ||
} | ||
|
||
/** | ||
* Returns true if the consumer was paused | ||
* @return whether the consumer is paused | ||
*/ | ||
public boolean isPaused() { | ||
return paused; | ||
} | ||
|
||
/** | ||
* Returns the time until the consumer is paused | ||
* @return pause until time | ||
*/ | ||
public ZonedDateTime getPauseUntil() { | ||
return pauseUntil; | ||
} | ||
|
||
/** | ||
* Returns how much time is remaining for this consumer to be paused | ||
* @return remaining paused time | ||
*/ | ||
public Duration getPauseRemaining() { | ||
return pauseRemaining; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should be two api here, one that does not take pauseUntil, since it is not required.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean having three methods in the end:
pauseConsumer(streamName, consumerName, pauseUntil)
pauseConsumer(streamName, consumerName)
resumeConsumer(streamName, consumerName)
When not sending a
pauseUntil
, the consumer does not get paused and should be equivalent to callingresumeConsumer
instead. SopauseConsumer
is used to pause a consumer until the set date, andresumeConsumer
resumes it. Could you explain why you'd expect two api here?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I thought no pauseUntil meant pause until resume. So just ignore this comment.