Learn how to build a React app that emits data to a Confluent topic, uses Tinybird to query data and publish APIs, and integrate those APIs into a React app for user-facing analytics.
- Python 3.8 (only if you use the data generator)
- Node.js
Follow these instructions to deploy the working version of this application.
First, create a free Tinybird account. Then create a new Workspace when prompted. You can name it whatever you want.
git clone https://github.com/tinybirdco/demo-user-facing-analytics-confluent.git
cd demo-user-facing-analytics-confluent
cd app
npm install
Note: You can use any Kafka technology, including Apache Kafka, Confluent Cloud, Redpanda, etc. with minimal changes.
If you haven't done so, sign up for a Confluent Cloud account. Then create a cluster. Once you've created a cluster, create a topic called game-events
. Once you've created a topic, create a key/secret pair to allow you to produce events to your new topic.
In addition, add the following to your .env.local
:
CONFLUENT_CLIENT_ID='<your cluster id>'
CONFLUENT_BROKER_URL='<your boostrap server url>'
CONFLUENT_API_KEY='<your confluent key>'
CONFLUENT_API_SECRET='<your confluent secret>'
cd tinybird
python -m venv .venv
source .e/bin/activate
pip install tinybird-cli
Copy your User Admin Token from the Tinybird UI. Your user admin token is the token with the format admin .
From the /tinybird
directory, run the following command:
export TB_TOKEN=<your user admin token>
tb auth
⚠️ Your token and workspace details will be stored in a .tinyb file. If you intend to push this to a public repository, add the.tinyb
to your.gitignore
.
Run the following command to connect your Tinybird Workspace to your Redpanda cluster.
cd tinybird
tb connection create kafka --bootstrap-servers <your confluent boostrap server> --key <your confluent key> --secret <your confluent secret> --connection-name confluent
Note: You can also do this from the Tinybird UI.
Run the following command to push Tinybird resources to the Tinybird server.
cd tinybird
tb push --force
Open your env.local
and add the following:
TINYBIRD_HOST=<your tinybird host>>
TINYBIRD_TOKEN=<the read_endpoints token from your Workspace>
Note you can copy the read_endpoints
token from the Tinybird CLI with tb token copy read_endpoints
.
This app uses a proxy to handle requests to Confluent and to store Tinybird tokens. Run the proxy server from the /services
directory:
node confluent-proxy.js
If you visit http://localhost:3001
you'll see a message that the microservice is running.
Run the application!
npm run dev
Open it at http://localhost:3000
and play the game. Have fun!
If you find any issues or have suggestions for improvements, please submit an issue or a pull request.
This code is available under the MIT license. See the LICENSE file for more details.
• Community Slack • Tinybird Docs •