mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 10:10:42 -07:00
allow max consumers to be set
Signed-off-by: R.I.Pienaar <rip@devco.net>
This commit is contained in:
@@ -796,10 +796,8 @@ func (jsa *jsAccount) checkLimits(config *StreamConfig) error {
|
||||
return fmt.Errorf("replicas setting of %d not allowed", config.Replicas)
|
||||
}
|
||||
// Check MaxConsumers
|
||||
if config.MaxConsumers > 0 && config.MaxConsumers > jsa.limits.MaxConsumers {
|
||||
if config.MaxConsumers > 0 && jsa.limits.MaxConsumers > 0 && config.MaxConsumers > jsa.limits.MaxConsumers {
|
||||
return fmt.Errorf("maximum consumers exceeds account limit")
|
||||
} else {
|
||||
config.MaxConsumers = jsa.limits.MaxConsumers
|
||||
}
|
||||
// Check storage, memory or disk.
|
||||
if config.MaxBytes > 0 {
|
||||
|
||||
@@ -699,6 +699,34 @@ func TestJetStreamAddStreamBadSubjects(t *testing.T) {
|
||||
expectAPIErr(server.StreamConfig{Name: "MyStream", Subjects: []string{".>"}})
|
||||
}
|
||||
|
||||
func TestJetStreamAddStreamMaxConsumers(t *testing.T) {
|
||||
s := RunBasicJetStreamServer()
|
||||
defer s.Shutdown()
|
||||
|
||||
if config := s.JetStreamConfig(); config != nil {
|
||||
defer os.RemoveAll(config.StoreDir)
|
||||
}
|
||||
|
||||
nc := clientConnectToServer(t, s)
|
||||
defer nc.Close()
|
||||
|
||||
cfg := &server.StreamConfig{
|
||||
Name: "MAXC",
|
||||
Subjects: []string{"in.maxc.>"},
|
||||
MaxConsumers: 1,
|
||||
}
|
||||
|
||||
acc := s.GlobalAccount()
|
||||
mset, err := acc.AddStream(cfg)
|
||||
if err != nil {
|
||||
t.Fatalf("Unexpected error adding stream: %v", err)
|
||||
}
|
||||
|
||||
if mset.Config().MaxConsumers != 1 {
|
||||
t.Fatalf("Expected 1 MaxConsumers, got %d", mset.Config().MaxConsumers)
|
||||
}
|
||||
}
|
||||
|
||||
func TestJetStreamAddStreamOverlappingSubjects(t *testing.T) {
|
||||
mconfig := &server.StreamConfig{
|
||||
Name: "ok",
|
||||
|
||||
Reference in New Issue
Block a user