Connecting Kafka to Goflow
This recipe will combine a Kafka consumer with a Goflow pipeline. As our consumer receives messages from Kafka, it will run strings.ToUpper()
on them and then print the results. These naturally pair as Goflow is designed to operate on an incoming stream, which is exactly what Kafka provides us.
Getting ready
Refer to the Getting ready section of the Using Kafka with Sarama recipe.
How to do it...
These steps cover writing and running your application:
- From your terminal/console application, create the
chapter11/kafkaflow
directory and navigate to it. - Copy tests from https://github.com/agtorre/go-cookbook/tree/master/chapter11/kafkaflow or use this as an exercise to write some of your own.
- Ensure that Kafka is up and running on
localhost:9092
. - Create a file called
components.go
with the following content:
package kafkaflow import ( "fmt" "strings" flow "github.com/trustmaster/goflow" ) // Upper upper...