nats-io/nats-architecture-and-design

Support consumer pause

ripienaar opened this issue ยท 7 comments

Overview

In 2.11 consumers can be paused using the API and optionally started paused.

Clients should at the very least support the added fields to config and state for consumers, but might be handy to also add some utilities.

Initial server issue nats-io/nats-server#4966

NOTE This is not merged at the moment, hold until merged. Also review the PR or schemas rather than the Issue for latest implementation detail

Clients and Tools

Other Tasks

  • docs.nats.io updated @bruth
  • Update ADR to Implemented
  • Update client features spreadsheet

Client authors please update with your progress. If you open issues in your own repositories as a result of this request, please link them to this one by pasting the issue URL in a comment or main issue description.

The PR has been merged: nats-io/nats-server#5066

Schemas PR, which is probably the best source of information how to implement the feature:
https://github.com/nats-io/jsm.go/pull/522/files

Request and response schemas:

// io.nats.jetstream.api.v1.consumer_pause_request
type JSApiConsumerPauseRequest struct {
	PauseUntil time.Time `json:"pause_until,omitempty"`
}

// io.nats.jetstream.api.v1.consumer_pause_response
type JSApiConsumerPauseResponse struct {
	JSApiResponse
	Paused         bool          `json:"paused"`
	PauseUntil     time.Time     `json:"pause_until"`
	PauseRemaining time.Duration `json:"pause_remaining,omitempty"`
}

Consumer info includes 2 new fields:

Paused bool json:"paused,omitempty"
PauseRemaining time.Duration json:"pause_remaining,omitempty"
The paused state and time time would need to be persisted to the raft layer such that server restarts would not unpause paused consumers. This is done using the consumer configuration that has a new value:

PauseUntil time.Time json:"pause_until,omitempty"

.NET.v2 client: nats-io/nats.net.v2#432

levb commented

โ˜๏ธ All of these contributions are so cool to see ๐Ÿ˜„