1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// workId := "1"
// consumerGroup := "consumer"
// nameSrvAddr := "127.0.0.1:9876"
c, err := rocketmq.NewPushConsumer(
consumer.WithInstance(workId),
consumer.WithGroupName(consumerGroup),
consumer.WithNsResolver(primitive.NewPassthroughResolver([]string{nameSrvAddr})),
)
if err != nil {
panic(err)
}
err = c.Subscribe(topic, consumer.MessageSelector{}, func(ctx context.Context,
messages ...*primitive.MessageExt) (consumer.ConsumeResult, error) {
for _, msg := range messages {
_ = msg
}
return consumer.ConsumeSuccess, nil
})
if err != nil {
panic(err)
}
err = c.Start()
if err != nil {
panic(err)
}
<-ctx.Done()
err = c.Shutdown()
if err != nil {
panic(err)
}
|