Kafka Setup
Create an Upstash Kafka cluster and a topic as explained here.Project Setup
We will use C3 (create-cloudflare-cli) command-line tool to create our application. You can open a new terminal window and run C3 using the prompt below.create-cloudflare
package, and lead you through setup. C3 will also install Wrangler in projects by default, which helps us testing and deploying the application.
The Code
You can update thesrc/index.ts
file with the code below:
Configure Credentials
There are two methods for setting up the credentials for Upstash Kafka client. The recommended way is to use Cloudflare Upstash Integration. Alternatively, you can add the credentials manually.Using the Cloudflare Integration
Access to the Cloudflare Dashboard and login with the same account that you’ve used while setting up the Worker application. Then, navigate to Workers & Pages > Overview section on the sidebar. Here, you’ll find your application listed.


Setting up Manually
Navigate to Upstash Console and copy/paste yourUPSTASH_KAFKA_REST_URL
, UPSTASH_KAFKA_REST_USERNAME
and UPSTASH_KAFKA_REST_PASSWORD
credentials to your wrangler.toml
as below.
Test and Deploy
You can test the function locally withnpx wrangler dev
Deploy your function to Cloudflare with npx wrangler deploy
Once the deployment is done, the endpoint of the function will be provided to you.
You can check if logs are collected in Kafka by copying the curl
expression from the console: