Skip to content

Commit

Permalink
Add command topic max consumers. (streamnative/pulsarctl#246) (#355)
Browse files Browse the repository at this point in the history
Add command topic max number of consumers:

* pulsarctl topics get-max-consumers [topic]
* pulsarctl topics set-max-consumers [topic] -c [max]
* pulsarctl topics remove-max-consumers [topic]
  • Loading branch information
limingnihao authored and tisonkun committed Aug 16, 2023
1 parent 9daf4ab commit 8690a14
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions pulsaradmin/pkg/pulsar/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ type Topics interface {

// RemoveMaxProducers Remove max number of producers for a topic
RemoveMaxProducers(utils.TopicName) error

// GetMaxConsumers Get max number of consumers for a topic
GetMaxConsumers(utils.TopicName) (int, error)

// SetMaxConsumers Set max number of consumers for a topic
SetMaxConsumers(utils.TopicName, int) error

// RemoveMaxConsumers Remove max number of consumers for a topic
RemoveMaxConsumers(utils.TopicName) error
}

type topics struct {
Expand Down Expand Up @@ -361,3 +370,22 @@ func (t *topics) RemoveMaxProducers(topic utils.TopicName) error {
err := t.pulsar.Client.Delete(endpoint)
return err
}

func (t *topics) GetMaxConsumers(topic utils.TopicName) (int, error) {
var maxConsumers int
endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "maxConsumers")
err := t.pulsar.Client.Get(endpoint, &maxConsumers)
return maxConsumers, err
}

func (t *topics) SetMaxConsumers(topic utils.TopicName, maxConsumers int) error {
endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "maxConsumers")
err := t.pulsar.Client.Post(endpoint, &maxConsumers)
return err
}

func (t *topics) RemoveMaxConsumers(topic utils.TopicName) error {
endpoint := t.pulsar.endpoint(t.basePath, topic.GetRestPath(), "maxConsumers")
err := t.pulsar.Client.Delete(endpoint)
return err
}

0 comments on commit 8690a14

Please sign in to comment.