This repository contains an Apache Flink application for real-time sales analytics built using Docker Compose to orchestrate the necessary infrastructure components, including Apache Flink, Elasticsearch, and Postgres. The application processes financial transaction data from Kafka, performs aggregations, and stores the results in both Postgres and Elasticsearch for further analysis.
- Docker
- Docker Compose
- Clone this repository.
- Navigate to the repository directory.
- Run
docker-compose up
to start the required services (Apache Flink, Elasticsearch, Postgres). - The Sales Transaction Generator
main.py
helps to generate the sales transactions into Kafka.
- Ensure all Docker containers are up and running.
- Run the FlinkCommerce application provided in this repository to perform real-time analytics on financial transactions.
The DataStreamJob
class within the FlinkCommerce
package serves as the main entry point for the Flink application. The application consumes financial transaction data from Kafka, performs various transformations, and stores aggregated results in both Postgres and Elasticsearch.
- Sets up the Flink execution environment.
- Connects to Kafka as a source for financial transaction data.
- Processes, transforms, and performs aggregations on transaction data streams.
- Stores transaction data and aggregated results in tables (
transactions
,sales_per_category
,sales_per_day
,sales_per_month
).
- Stores transaction data for further analysis.
DataStreamJob.java
: Contains the Flink application logic, including Kafka source setup, stream processing, transformations, and sinks for Postgres and Elasticsearch.Deserializer
,Dto
, andutils
packages: Include necessary classes and utilities for deserialization, data transfer objects, and JSON conversion.
- Kafka settings (bootstrap servers, topic, group ID) are configured within the Kafka source setup.
- Postgres connection details (URL, username, password) are defined in the
jdbcUrl
,username
, andpassword
variables.
- The application includes sink operations for Postgres using JDBC to create tables (
transactions
,sales_per_category
,sales_per_day
,sales_per_month
) and perform insert/update operations. - Additionally, it includes an Elasticsearch sink to index transaction data for further analysis.