Code Monkey home page Code Monkey logo

innogames / flink-real-time-crm Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 1.0 1.24 MB

Demo Flink and Kafka project to show how to react on tracking events in real-time and trigger offer for customer engagement based on campaign configurations. The project also utilizes the Broadcast State Pattern in order to update the rules (campaigns) at runtime without restarting the project, using a dedicated, low-frequency, Kafka topic.

License: Apache License 2.0

Makefile 0.57% Java 99.43%
apacheflink apachekafka flink flink-examples flink-stream-processing flink-streaming java kafka stream-processing

flink-real-time-crm's Introduction

Real-time Customer Engagement in Gaming Using Kafka and Flink

Description

Demo Flink project to show how to react on interaction events in real-time and trigger CRM campaigns for customer engagement based on campaign configurations.

The project also utilizes the Broadcast State Pattern in order to update the rules (campaigns) at runtime without restarting the project, using a dedicated, low-frequency, Kafka topic.

Business Logic

Customer Engagement Campaigns

Each customer engagement campaign runs for a specific product (game) and can have a start and end date. Additionally, a campaign can be enabled and disabled and has a unique ID.

The key element of a campaign is the filter. The filter is a JavaScript function that is executed for each event and must return a boolean value. With this filter, we can define the conditions that must be met in order to trigger the campaign based on an event.

Campaigns can be configured by simply writing the JSON representation to the crm-campaigns Kafka topic.

Trigger Campaigns

Interaction events are written as JSON to the events-valid Kafka topic. For each event, the Flink Application will evaluate all active campaigns and check if the filter matches. If that is the case, a trigger is written to the crm-triggers Kafka topic, indicating that the user is eligible to receive the offer connected to the campaign.

Please refer to the local execution example to get a better understanding of how the system works.

Local Execution

Requirements:

Configuration

Default configuration is defined in src/main/resources/config.json. You can override it by creating a custom config file and pass the path as a parameter named config when running the Flink job.

Start Kafka

Just run the following command in the project dir to start ZooKeeper and Kafka as defined in docker-compose.yml:

docker-compose up -d

Create topics

We are using kcat to interact with Kafka. We start the producer and exit (CTRL+D) again to just create the necessary topics:

kcat -b localhost:9093 -t events-valid -P
kcat -b localhost:9093 -t crm-campaigns -P
kcat -b localhost:9093 -t crm-triggers -P

Then use kcat to list topics:

kcat -b localhost:9093 -L | grep topic

The output should include the three topics above:

Metadata for all topics (from broker 1: localhost:9093/1):
 4 topics:
  topic "crm-triggers" with 1 partitions:
  topic "events-valid" with 1 partitions:
  topic "crm-campaigns" with 1 partitions:
  topic "__consumer_offsets" with 50 partitions:

Run Flink job

Run com.innogames.analytics.rtcrm.App and use kcat to create a campaign, send and event and check the trigger:

Open Flink Web UI

Open http://localhost:8081/ to see the Flink Web UI.

Create campaign

kcat -b localhost:9093 -t crm-campaigns -P
{"campaign_id":4711,"enabled":true,"game":"foe","event_name":"fight","start_date":"2023-09-01T10:00:00.00Z","end_date":"2023-12-01T10:00:00.00Z","filter":"function(event) { return event.getData().get('result') === 'loss' }"}

Send event

kcat -b localhost:9093 -t events-valid -P
{"schema_version":"2023110110010101","event_id":"7a8d0614-4e8e-4464-b439-36e31441a040","system_type":"game","system_name":"foe-backend","game":"foe","market":"de","player_id":12345,"event_type":"progress","event_name":"fight","event_scope":"user","created_at":"2023-11-20T11:00:00.00Z","received_at":"2023-11-20T11:00:02.00Z","hostname":"foe-backend-1.ig.com","context":{},"data":{"result":"loss"}}

Consume trigger

kcat -b localhost:9093 -t crm-triggers -C -o beginning -u

Demo UI

Demo UI

When Kafka and Flink are running, you can also use the dedicated Demo UI project to interact with the system via a web frontend.

flink-real-time-crm's People

Contributors

dreis2211 avatar vojay-dev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

codingkrishna

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.