|
| 1 | +// Consumer is Felice's primary entrance point for receiving messages |
| 2 | +// from a Kafka cluster. |
| 3 | +// |
| 4 | +// There is no special construction function for the Consumer |
| 5 | +// structure as all of its public members are optional, and we shall |
| 6 | +// discuss them below. Thus you construct a Consumer by the normal Go |
| 7 | +// means: |
| 8 | +// |
| 9 | +// c := felice.Consumer{} |
| 10 | +// |
| 11 | +// Once you've constructed a consumer you must add message handlers to |
| 12 | +// it. This is done by calling the Consumer.Handle method. Each time |
| 13 | +// you call Handle you'll pass a topic name and a type that implements |
| 14 | +// the handler.Handler interface. Their can only ever be one handler |
| 15 | +// associated with a topic so, if you call Handle multiple times with |
| 16 | +// the same topic, they will update the handler registered for the |
| 17 | +// topic, and only the final one will count. A typical call to Handle |
| 18 | +// looks like this: |
| 19 | +// |
| 20 | +// c.Handle("testmsg", handler.HandlerFunc(func(m *message.Message) error { |
| 21 | +// // Do something of your choice here! |
| 22 | +// return nil // .. or return an actual error. |
| 23 | +// })) |
| 24 | +// |
| 25 | +// Once you've registered all your handlers you may call |
| 26 | +// Consumer.Serve. Serve requires a client ID and a slice of strings, |
| 27 | +// each of which is the address of a Kafka broker to attempt to |
| 28 | +// communicate with. Serve will start a go routine for each partition |
| 29 | +// to consume messages and pass them to their per-topic |
| 30 | +// handlers. Serve itself will block until Consumer.Stop is called. |
| 31 | +// When Serve terminates it will return an error, which will be nil |
| 32 | +// under normal circumstances. |
| 33 | +// |
| 34 | +// Note that any calls to Consumer.Handle after |
| 35 | +// Consumer.Serve has been called will have no effect. |
| 36 | +// |
| 37 | +// Tweaking the consumer |
| 38 | +// -------------------------- |
| 39 | +// The first public member is the RetryInterval, a time.Duration that |
| 40 | +// controls how long the Felice consumer will wait before trying to |
| 41 | +// consume a message from Kafka that failed the first time around. |
| 42 | +// The default value if 1 second. |
| 43 | +// |
| 44 | +// The second public member is Metrics. Metrics stores a type that |
| 45 | +// implements the felice.MetricsReporter interface. If you provide an |
| 46 | +// implementation, then it's Report function will be called every time |
| 47 | +// a message is successfully handled. The Report function will |
| 48 | +// receive a copy of the message.Message that was handled, along with |
| 49 | +// a map[string]string containing metrics about the handling of the |
| 50 | +// message. Currently we pass the following metrics: "attempts" (the |
| 51 | +// number of attempts it took before the message was handled); |
| 52 | +// "msgOffset" (the marked offset for the message on the topic); and |
| 53 | +// "remainingOffset" (the difference between the high water mark and |
| 54 | +// the current offset). |
| 55 | +package consumer |
0 commit comments