This repository has been archived by the owner on Jun 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from heetch/bootstap-documentation
Bootstrap documentation
- Loading branch information
Showing
11 changed files
with
212 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Consumer is Felice's primary entrance point for receiving messages | ||
// from a Kafka cluster. | ||
// | ||
// There is no special construction function for the Consumer | ||
// structure as all of its public members are optional, and we shall | ||
// discuss them below. Thus you construct a Consumer by the normal Go | ||
// means: | ||
// | ||
// c := felice.Consumer{} | ||
// | ||
// Once you've constructed a consumer you must add message handlers to | ||
// it. This is done by calling the Consumer.Handle method. Each time | ||
// you call Handle you'll pass a topic name and a type that implements | ||
// the handler.Handler interface. Their can only ever be one handler | ||
// associated with a topic so, if you call Handle multiple times with | ||
// the same topic, they will update the handler registered for the | ||
// topic, and only the final one will count. A typical call to Handle | ||
// looks like this: | ||
// | ||
// c.Handle("testmsg", handler.HandlerFunc(func(m *message.Message) error { | ||
// // Do something of your choice here! | ||
// return nil // .. or return an actual error. | ||
// })) | ||
// | ||
// Once you've registered all your handlers you may call | ||
// Consumer.Serve. Serve requires a client ID and a slice of strings, | ||
// each of which is the address of a Kafka broker to attempt to | ||
// communicate with. Serve will start a go routine for each partition | ||
// to consume messages and pass them to their per-topic | ||
// handlers. Serve itself will block until Consumer.Stop is called. | ||
// When Serve terminates it will return an error, which will be nil | ||
// under normal circumstances. | ||
// | ||
// Note that any calls to Consumer.Handle after | ||
// Consumer.Serve has been called will have no effect. | ||
// | ||
// Tweaking the consumer | ||
// -------------------------- | ||
// The first public member is the RetryInterval, a time.Duration that | ||
// controls how long the Felice consumer will wait before trying to | ||
// consume a message from Kafka that failed the first time around. | ||
// The default value if 1 second. | ||
// | ||
// The second public member is Metrics. Metrics stores a type that | ||
// implements the felice.MetricsReporter interface. If you provide an | ||
// implementation, then it's Report function will be called every time | ||
// a message is successfully handled. The Report function will | ||
// receive a copy of the message.Message that was handled, along with | ||
// a map[string]string containing metrics about the handling of the | ||
// message. Currently we pass the following metrics: "attempts" (the | ||
// number of attempts it took before the message was handled); | ||
// "msgOffset" (the marked offset for the message on the topic); and | ||
// "remainingOffset" (the difference between the high water mark and | ||
// the current offset). | ||
package consumer |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// The handler package defines the mechanisms by which a received | ||
// message can be handled, and how handlers themselves can be managed. | ||
// The most obvious way to use the handler package is via the consumer | ||
// package, but this isn't an absolute requirement. We do however | ||
// require that the messages handled are felice's message.Message | ||
// type. | ||
// | ||
// The Handler interface defines the signature for all felice | ||
// Handlers. There are two common ways to comply with this interface. | ||
// The first is simply to create a type with the HandleMessage | ||
// function: | ||
// | ||
// type MyFooHandler struct { } | ||
// | ||
// func (mfh MyFooHandler) HandleMessage(msg *message.Message) error { | ||
// fmt.Printf("%+v", *msg) | ||
// } | ||
// | ||
// This approach has the advantage of not actually requiring you to | ||
// import the handler package when defining handlers for use with the | ||
// consumer.Consumer. | ||
// | ||
// The second approach is to cast a function to the HandlerFunc type | ||
// defined in this package: | ||
// | ||
// h := handler.HandlerFunc(func(msg *message.Message) error { | ||
// fmt.Printf("%+v", *msg) | ||
// }) | ||
// | ||
// Handlers can also be managed in Collections. The Collection struct | ||
// will allow exactly one handler to be associated with each topic, | ||
// and will, on demand return a list of all topics for which a handler | ||
// has been registered. For example: | ||
// | ||
// col := handler.Collection{} | ||
// | ||
// col.Set("my-topic", handler.HandlerFunc(func(msg *message.Message) error) { | ||
// fmt.Printf("Got message on my-topic: %+v", *msg) | ||
// return nil | ||
// }) | ||
// | ||
// col.Set("your-topic", handler.HandlerFunc(func(msg *message.Message) error) { | ||
// fmt.Printf("Got message on your-topic: %+v", msg) | ||
// return nil | ||
// }) | ||
// | ||
// yourHandler, ok := col.Get("your-topic") | ||
// if !ok { | ||
// fmt.Println("Couldn't find a handler for your-topic") | ||
// } | ||
// | ||
// for _, t := range col.Topics { | ||
// fmt.Printf("We have a handler for: %s", t) | ||
// } | ||
// | ||
package handler |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// The message package contains the Message type. When using | ||
// the felice Producer, Message will be the type you send. | ||
// When using the felice Consumer, you will register handlers that | ||
// receive the Message type. | ||
// | ||
// You can create a new Message by calling New: | ||
// | ||
// msg := New("my-topic", "simple string message") | ||
// | ||
// The value passed as the 2nd argument can be any Go type that can be | ||
// marshalled with encoding/json. Two default headers are added to | ||
// all Messages: | ||
// | ||
// - Message-Id : a universally unique ID for the message | ||
// - Produced-At : the current time in the UTC timezone. | ||
// | ||
// New can also be passed zero, one or many additional Options. An | ||
// Option is a function that receives a pointer to the Message and can | ||
// modify it directly prior to it being returned by New. Two | ||
// predefined Options exists in felice: Header and Key. | ||
// | ||
// For example, if you want to create a Message with a custom header | ||
// field you could request it as follows: | ||
// | ||
// msg := New("my-topic", "cold potatoes ain't hot!", Header("subject", "potatoes")) | ||
// | ||
package message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters