|
8 | 8 | // |
9 | 9 | // ConsumePartition example: |
10 | 10 | // |
11 | | -// ctx := ppsarama.NewContext(context.Background(), broker) |
12 | | -// pc, _ := consumer.ConsumePartition(topic, partition, offset) |
13 | | -// for msg := range pc.Messages() { |
14 | | -// ppsarama.ConsumeMessageContext(processMessage, ctx, msg) |
15 | | -// } |
| 11 | +// ctx := ppsarama.NewContext(context.Background(), broker) |
| 12 | +// pc, _ := consumer.ConsumePartition(topic, partition, offset) |
| 13 | +// for msg := range pc.Messages() { |
| 14 | +// ppsarama.ConsumeMessageContext(processMessage, ctx, msg) |
| 15 | +// } |
16 | 16 | // |
17 | 17 | // ConsumerGroupHandler example: |
18 | 18 | // |
19 | | -// func (h exampleConsumerGroupHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error { |
20 | | -// ctx := sess.Context() |
21 | | -// for msg := range claim.Messages() { |
22 | | -// _ = ppsarama.ConsumeMessageContext(process, ctx, msg) |
23 | | -// } |
| 19 | +// func (h exampleConsumerGroupHandler) ConsumeClaim(sess sarama.ConsumerGroupSession, claim sarama.ConsumerGroupClaim) error { |
| 20 | +// ctx := sess.Context() |
| 21 | +// for msg := range claim.Messages() { |
| 22 | +// _ = ppsarama.ConsumeMessageContext(process, ctx, msg) |
| 23 | +// } |
24 | 24 | // |
25 | 25 | // ConsumeMessageContext passes a context added pinpoint.Tracer to HandlerContextFunc. |
26 | 26 | // In HandlerContextFunc, this tracer can be obtained by using the pinpoint.FromContext function. |
27 | 27 | // |
28 | | -// func process(ctx context.Context, msg *sarama.ConsumerMessage) error { |
29 | | -// tracer := pinpoint.FromContext(ctx) |
30 | | -// defer tracer.NewSpanEvent("process").EndSpanEvent() |
| 28 | +// func process(ctx context.Context, msg *sarama.ConsumerMessage) error { |
| 29 | +// tracer := pinpoint.FromContext(ctx) |
| 30 | +// defer tracer.NewSpanEvent("process").EndSpanEvent() |
31 | 31 | // |
32 | | -// fmt.Printf("Message topic:%q partition:%d offset:%d\n", msg.Topic, msg.Partition, msg.Offset) |
| 32 | +// fmt.Printf("Message topic:%q partition:%d offset:%d\n", msg.Topic, msg.Partition, msg.Offset) |
33 | 33 | // |
34 | 34 | // To instrument a Kafka producer, use NewSyncProducer or NewAsyncProducer. |
35 | 35 | // |
|
39 | 39 | // It is necessary to pass the context containing the pinpoint.Tracer |
40 | 40 | // to sarama.SyncProducer (or sarama.AsyncProducer) using WithContext function. |
41 | 41 | // |
42 | | -// ppsarama.WithContext(pinpoint.NewContext(context.Background(), tracer), producer) |
43 | | -// partition, offset, err := producer.SendMessage(msg) |
| 42 | +// ppsarama.WithContext(pinpoint.NewContext(context.Background(), tracer), producer) |
| 43 | +// partition, offset, err := producer.SendMessage(msg) |
| 44 | +// |
| 45 | +// The WithContext function() function is not thread-safe, so use the SendMessageContext function() if you have a data trace. |
| 46 | +// |
| 47 | +// partition, offset, err := producer.SendMessageContext(r.Context(), msg) |
44 | 48 | package ppsarama |
45 | 49 |
|
46 | 50 | import ( |
|
0 commit comments