Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions dq/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type (
Consume func(body []byte)

Consumer interface {
Consume(consume Consume)
Consume(consume Consume) *service.ServiceGroup
}

consumerCluster struct {
Expand All @@ -42,7 +42,7 @@ func NewConsumer(c DqConf) Consumer {
}
}

func (c *consumerCluster) Consume(consume Consume) {
func (c *consumerCluster) Consume(consume Consume) *service.ServiceGroup {
guardedConsume := func(body []byte) {
key := hash.Md5Hex(body)
body, ok := c.unwrap(body)
Expand All @@ -66,7 +66,8 @@ func (c *consumerCluster) Consume(consume Consume) {
consume: guardedConsume,
})
}
group.Start()

return group
}

func (c *consumerCluster) unwrap(body []byte) ([]byte, bool) {
Expand Down
5 changes: 4 additions & 1 deletion example/dq/consumer/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func main() {
Type: redis.NodeType,
},
})
consumer.Consume(func(body []byte) {
group := consumer.Consume(func(body []byte) {
fmt.Println(string(body))
})

defer group.Stop()
group.Start()
}