You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Case 1: send sarama.ProducerMessage type message, supports multiple messages
85
-
msg:= testData[0].(*sarama.ProducerMessage) // testData is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/producer_test.go#L18
85
+
msg:= testData[0].(*sarama.ProducerMessage) // testData is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/producer_test.go#L19
86
86
err = p.SendMessage(msg, msg)
87
87
if err != nil {
88
88
fmt.Println(err)
@@ -112,6 +112,7 @@ package main
112
112
import (
113
113
"fmt"
114
114
"time"
115
+
"context"
115
116
"github.com/IBM/sarama"
116
117
"github.com/go-dev-frame/sponge/pkg/kafka"
117
118
)
@@ -130,11 +131,11 @@ func main() {
130
131
defer cg.Close()
131
132
132
133
// Case 1: consume default handle message
133
-
go cg.Consume(context.Background(), []string{testTopic}, handleMsgFn) // handleMsgFn is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L19
134
+
go cg.ConsumeLoop(context.Background(), []string{testTopic}, handleMsgFn) // handleMsgFn is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L19
134
135
135
136
// Case 2: consume custom handle message
136
-
go cg.ConsumeCustom(context.Background(), []string{testTopic}, &myConsumerGroupHandler{ // myConsumerGroupHandler is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L26
137
-
autoCommitEnable: cg.autoCommitEnable,
137
+
go cg.ConsumeCustomLoop(context.Background(), []string{testTopic}, &myConsumerGroupHandler{ // myConsumerGroupHandler is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L26
138
+
autoCommitEnable: true,
138
139
})
139
140
140
141
<-time.After(time.Minute) // wait exit
@@ -150,9 +151,10 @@ package main
150
151
151
152
import (
152
153
"fmt"
154
+
"time"
155
+
"context"
153
156
"github.com/IBM/sarama"
154
157
"github.com/go-dev-frame/sponge/pkg/kafka"
155
-
"time"
156
158
)
157
159
158
160
funcmain() {
@@ -167,7 +169,7 @@ func main() {
167
169
defer c.Close()
168
170
169
171
// Case 1: consume one partition
170
-
go c.ConsumePartition(context.Background(), testTopic, 0, sarama.OffsetNewest, handleMsgFn) //// handleMsgFn is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L19
172
+
go c.ConsumePartition(context.Background(), testTopic, 0, sarama.OffsetNewest, handleMsgFn) // handleMsgFn is https://github.com/go-dev-frame/sponge/blob/main/pkg/kafka/consumer_test.go#L19
0 commit comments