44 "cloud.google.com/go/pubsub"
55 "context"
66 "github.com/common-go/mq"
7- "github.com/sirupsen/logrus"
87)
98
109type Consumer struct {
@@ -19,11 +18,20 @@ func NewConsumer(client *pubsub.Client, subscriptionId string, c SubscriptionCon
1918}
2019
2120func NewConsumerByConfig (ctx context.Context , c ConsumerConfig , ackOnConsume bool ) (* Consumer , error ) {
22- client , err := NewPubSubClient (ctx , c .Client .ProjectId , c .Client .KeyFilename )
23- if err != nil {
24- return nil , err
21+ if c .Retry .Retry1 <= 0 {
22+ client , err := NewPubSubClient (ctx , c .Client .ProjectId , c .Client .KeyFilename )
23+ if err != nil {
24+ return nil , err
25+ }
26+ return NewConsumer (client , c .SubscriptionId , c .SubscriptionConfig , ackOnConsume ), nil
27+ } else {
28+ durations := DurationsFromValue (c .Retry , "Retry" , 9 )
29+ client , err := NewPubSubClientWithRetries (ctx , c .Client .ProjectId , c .Client .KeyFilename , durations )
30+ if err != nil {
31+ return nil , err
32+ }
33+ return NewConsumer (client , c .SubscriptionId , c .SubscriptionConfig , ackOnConsume ), nil
2534 }
26- return NewConsumer (client , c .SubscriptionId , c .SubscriptionConfig , ackOnConsume ), nil
2735}
2836
2937func ConfigureSubscription (subscription * pubsub.Subscription , c SubscriptionConfig ) * pubsub.Subscription {
@@ -38,9 +46,6 @@ func ConfigureSubscription(subscription *pubsub.Subscription, c SubscriptionConf
3846
3947func (c * Consumer ) Consume (ctx context.Context , caller mq.ConsumerCaller ) {
4048 er1 := c .Subscription .Receive (ctx , func (ctx2 context.Context , m * pubsub.Message ) {
41- if logrus .IsLevelEnabled (logrus .DebugLevel ) {
42- logrus .Debugf ("Received message: %s" , m .Data )
43- }
4449 message := mq.Message {
4550 Id : m .ID ,
4651 Data : m .Data ,
0 commit comments