propagate context and SuccessAutoAck option other brokers
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
c5fc37933f
commit
6c04d1a29b
11
stan.go
11
stan.go
@ -176,6 +176,9 @@ func (n *stanBroker) Publish(topic string, msg *broker.Message, opts ...broker.P
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...broker.SubscribeOption) (broker.Subscriber, error) {
|
||||||
|
if n.conn == nil {
|
||||||
|
return nil, errors.New("not connected")
|
||||||
|
}
|
||||||
var successAutoAck bool
|
var successAutoAck bool
|
||||||
|
|
||||||
opt := broker.SubscribeOptions{
|
opt := broker.SubscribeOptions{
|
||||||
@ -197,7 +200,7 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
|
|||||||
}
|
}
|
||||||
|
|
||||||
var stanOpts []stan.SubscriptionOption
|
var stanOpts []stan.SubscriptionOption
|
||||||
if opt.AutoAck {
|
if !opt.AutoAck {
|
||||||
stanOpts = append(stanOpts, stan.SetManualAckMode())
|
stanOpts = append(stanOpts, stan.SetManualAckMode())
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -217,6 +220,8 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
opt.AutoAck = !bopts.ManualAcks
|
||||||
|
|
||||||
fn := func(msg *stan.Msg) {
|
fn := func(msg *stan.Msg) {
|
||||||
var m broker.Message
|
var m broker.Message
|
||||||
var err error
|
var err error
|
||||||
@ -224,7 +229,9 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
err = handler(&publication{m: &m, msg: msg, t: msg.Subject})
|
err = handler(&publication{m: &m, msg: msg, t: msg.Subject})
|
||||||
if err == nil && successAutoAck && bopts.ManualAcks {
|
if err == nil && successAutoAck && !opt.AutoAck {
|
||||||
|
msg.Ack()
|
||||||
|
} else if err != nil && opt.AutoAck {
|
||||||
msg.Ack()
|
msg.Ack()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user