Skip to content

Commit

Permalink
feat: switch to manual ack
Browse files Browse the repository at this point in the history
  • Loading branch information
alexec committed Jun 10, 2021
1 parent 8820485 commit 4cd5e8b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
1 change: 1 addition & 0 deletions runner/sidecar/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func (h *handler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.Co
// noop
} else {
sess.MarkMessage(m, "")
sess.Commit()
}
}
return nil
Expand Down
13 changes: 7 additions & 6 deletions runner/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ func connectSources(ctx context.Context, toMain func([]byte) error) error {
}
subs, ok := o["subscriptions"]
if !ok {
return 0, fmt.Errorf("no \"suscriptions\" field found in the monitoring endpoint response")
return 0, fmt.Errorf("no suscriptions field found in the monitoring endpoint response")
}
maxLastSent := float64(0)
for _, i := range subs.([]interface{}) {
Expand All @@ -440,8 +440,12 @@ func connectSources(ctx context.Context, toMain func([]byte) error) error {

// https://docs.nats.io/developing-with-nats-streaming/queues
queueName := fmt.Sprintf("%s-%s-source-%s", pipelineName, stepName, sourceName)
if sub, err := sc.QueueSubscribe(x.Subject, queueName, func(m *stan.Msg) {
_ = f(m.Data) // TODO we should decide what to do with errors here, currently we ignore them
if sub, err := sc.QueueSubscribe(x.Subject, queueName, func(msg *stan.Msg) {
if err := f(msg.Data); err != nil {
if err := msg.Ack(); err != nil {
logger.Error(err, "failed to ack message", "msg", msg)
}
}
}, stan.DurableName(queueName)); err != nil {
return fmt.Errorf("failed to subscribe: %w", err)
} else {
Expand All @@ -468,9 +472,6 @@ func connectSources(ctx context.Context, toMain func([]byte) error) error {
if err != nil {
return err
}
config.Consumer.Return.Errors = true
config.Consumer.Offsets.Initial = sarama.OffsetNewest
config.Consumer.Offsets.AutoCommit.Enable = false
client, err := sarama.NewClient(x.Brokers, config) // I am not giving any configuration
if err != nil {
return err
Expand Down

0 comments on commit 4cd5e8b

Please sign in to comment.