Last active
September 24, 2018 17:12
-
-
Save briansorahan/0e6fac07a3076a83e36d80ae55ec48d3 to your computer and use it in GitHub Desktop.
Testing github.com/segmentio/kafka-go CreateTopics method.
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
package main | |
import ( | |
"fmt" | |
"io" | |
"log" | |
"os" | |
"github.com/pkg/errors" | |
sk "github.com/segmentio/kafka-go" | |
) | |
func main() { | |
if len(os.Args) < 2 { | |
fmt.Fprintln(os.Stderr, errors.Errorf("expected usage: %s BROKER", os.Args[0]).Error()) | |
} | |
conn, err := sk.Dial("tcp", os.Args[1]) | |
if err != nil { | |
log.Fatal(errors.Wrap(err, "connecting to broker")) | |
} | |
err = conn.CreateTopics(sk.TopicConfig{ | |
Topic: "topic-name-redacted", | |
}) | |
if ske, ok := err.(sk.Error); ok { | |
fmt.Printf("error description %s\n", ske.Description()) | |
fmt.Printf("error title %s\n", ske.Title()) | |
fmt.Printf("error is temporary: %#v\n", ske.Temporary()) | |
fmt.Printf("error is timeout: %#v\n", ske.Timeout()) | |
} | |
if err == io.EOF { | |
fmt.Printf("got io.EOF\n") | |
} | |
if err := errors.Wrap(err, "creating topics"); err != nil { | |
log.Fatal(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment