Rename SuccessAutoAck to AckOnSuccess

This commit is contained in:
Asim Aslam 2019-01-28 08:18:02 +00:00 committed by Vasiliy Tolstov
parent 6eb8ae50d5
commit 31d9c7f289
2 changed files with 8 additions and 8 deletions

View File

@ -34,9 +34,9 @@ func SubscribeContext(ctx context.Context) broker.SubscribeOption {
return setSubscribeOption(subscribeContextKey{}, ctx) return setSubscribeOption(subscribeContextKey{}, ctx)
} }
type successAutoAckKey struct{} type ackSuccessKey struct{}
// SuccessAutoAck allow to AutoAck messages when handler returns without error // AckOnSuccess allow to AutoAck messages when handler returns without error
func SuccessAutoAck() broker.SubscribeOption { func AckOnSuccess() broker.SubscribeOption {
return setSubscribeOption(successAutoAckKey{}, true) return setSubscribeOption(ackSuccessKey{}, true)
} }

View File

@ -179,7 +179,7 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
if n.conn == nil { if n.conn == nil {
return nil, errors.New("not connected") return nil, errors.New("not connected")
} }
var successAutoAck bool var ackSuccess bool
opt := broker.SubscribeOptions{ opt := broker.SubscribeOptions{
AutoAck: true, AutoAck: true,
@ -208,9 +208,9 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
stanOpts = append(stanOpts, subOpts...) stanOpts = append(stanOpts, subOpts...)
} }
if bval, ok := ctx.Value(successAutoAckKey{}).(bool); ok && bval { if bval, ok := ctx.Value(ackSuccessKey{}).(bool); ok && bval {
stanOpts = append(stanOpts, stan.SetManualAckMode()) stanOpts = append(stanOpts, stan.SetManualAckMode())
successAutoAck = true ackSuccess = true
} }
bopts := stan.DefaultSubscriptionOptions bopts := stan.DefaultSubscriptionOptions
@ -233,7 +233,7 @@ func (n *stanBroker) Subscribe(topic string, handler broker.Handler, opts ...bro
// execute the handler // execute the handler
err := handler(&publication{m: &m, msg: msg, t: msg.Subject}) err := handler(&publication{m: &m, msg: msg, t: msg.Subject})
// if there's no error and success auto ack is enabled ack it // if there's no error and success auto ack is enabled ack it
if err == nil && successAutoAck { if err == nil && ackSuccess {
msg.Ack() msg.Ack()
} }
} }