Skip to content

Commit a4cdb9e

Browse files
Add error handling for SubscribeTopics function call
This commit adds error handling to the main function in consumer_example.go file. Specifically, it checks for errors returned by the SubscribeTopics function call and exits the program with an error message if the subscription fails. This ensures robustness and graceful handling of errors during topic subscription.
1 parent f0d709f commit a4cdb9e

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

examples/consumer_example/consumer_example.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ func main() {
7070

7171
err = c.SubscribeTopics(topics, nil)
7272

73+
if err != nil {
74+
fmt.Fprintf(os.Stderr, "Failed to subscribe to topics: %v\n", err)
75+
os.Exit(1)
76+
}
77+
7378
run := true
7479

7580
for run {

0 commit comments

Comments
 (0)