dont create consumer if existed
This commit is contained in:
parent
3fe4271f1b
commit
8446b578c2
|
@ -14,10 +14,17 @@ func (js JetStream) GetConsumerInfo(stream, name string) (*nats.ConsumerInfo, er
|
||||||
|
|
||||||
// AddConsumer ...
|
// AddConsumer ...
|
||||||
func (js JetStream) AddConsumer(stream, subject, name string) error {
|
func (js JetStream) AddConsumer(stream, subject, name string) error {
|
||||||
|
// Get consumer first, return if existed
|
||||||
|
consumer, err := js.GetConsumerInfo(stream, name)
|
||||||
|
if consumer != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Generate channel name
|
||||||
channel := combineStreamAndSubjectName(stream, subject)
|
channel := combineStreamAndSubjectName(stream, subject)
|
||||||
|
|
||||||
// Add
|
// Add
|
||||||
_, err := js.instance.AddConsumer(stream, &nats.ConsumerConfig{
|
_, err = js.instance.AddConsumer(stream, &nats.ConsumerConfig{
|
||||||
Durable: name,
|
Durable: name,
|
||||||
AckPolicy: nats.AckExplicitPolicy,
|
AckPolicy: nats.AckExplicitPolicy,
|
||||||
FilterSubject: channel,
|
FilterSubject: channel,
|
||||||
|
|
Loading…
Reference in New Issue