simple-kafka

command
v0.0.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2020 License: BSD-3-Clause Imports: 12 Imported by: 0

README

Kafka trigger based simple rules action usage

This example demonstrates usage of kafka trigger with rules action. Consider system related to order identification and processing, kafka trigger will listen to a topic where order information is available, based on price and order category gift coupons can be issued to the customer.

Setup

  1. Get rules repo.
go get -u github.com/project-flogo/rules/... 
  1. Install kafka.

Usage

Get the repo and in this example main.go, functions.go both are available. We can directly build and run the app or create flogo rule app and run it.

Run kafka and zookeeper

Open a terminal and navigate to kafka home.

cd $KAFKA_HOME
#run zookeeper
bin/zookeeper-server-start.sh config/zookeeper.properties

Open another terminal.

cd $KAFKA_HOME
#run kafka server
bin/kafka-server-start.sh config/server.properties
Create topic

Open terminal and create topic which is given in kafka trigger. Here orderinfo is topic name used in trigger.

cd $KAFKA_HOME
bin/kafka-topics.sh --create --bootstrap-server localhost:9092 --replication-factor 1 --partitions 1 --topic orderinfo

Direct build and run
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/simple-kafka
go build
./simple-kafka

OR

Create app using flogo cli
cd $GOPATH/src/github.com/project-flogo/rules/examples/flogo/simple-kafka
flogo create -f flogo.json simpleKafkaRulesApp
cp functions.go simpleKafkaRulesApp/src
cd simpleKafkaRulesApp
flogo build
./bin/simpleKafkaRulesApp
Send the data over kafka producer

Open terminal send order information through kafka producer.

cd $KAFKA_HOME
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic orderinfo
>{"type":"grocery","totalPrice":"2001.0"}

Expected output in rules terminal.

Rule fired: [groceryCheckRule]
Congratulations you are eligible for Rs. 500 gift coupon

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL