Skip to content

digitalocean/sample-golang-kafka

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Getting Started

We provide a sample app that produces and consumes messages to/from Kafka using Golang that you can deploy on App Platform. These steps will get this sample application running for you using App Platform.

Note: Following these steps may result in charges for the use of DigitalOcean services.

Requirements

Deploying the App

Deploy to DigitalOcean

  1. Click "Add Resource (Optional)", select "Database", click "Add"
  2. Select "Previously Created DigitalOcean Database"
  3. Select your kafka cluster under "Database Cluster", click "Attach Database", and click "Next"
  4. In the "Environment Variables" step, click on "Edit" next to "Global", click on "Bulk Edit", and add the following environment variables. Make sure to replace your-kafka-instance-name with the name of your kafka cluster, and change the KAFKA_TOPIC environment variable to the topic you created.
KAFKA_BROKER=${your-kafka-instance-name.HOSTNAME}:${your-kafka-instance-name.PORT}
KAFKA_USERNAME=${your-kafka-instance-name.USERNAME}
KAFKA_PASSWORD=${your-kafka-instance-name.PASSWORD}
KAFKA_CA_CERT=${your-kafka-instance-name.CA_CERT}
KAFKA_TOPIC=set this to the kafka topic you created
  1. Click "Save", click "Next"
  2. Click "Next" on the "Info" step
  3. Review the information presented in the "Review" step and click "Create Resources"

Deploying the App using doctl

Fork this GitHub repository to your account so that you have a copy of it stored to the cloud. Click the Fork button in the GitHub repository and follow the on-screen instructions.

After forking the repo, you should now be viewing this README in your own GitHub org (e.g. https://github.com/<your-org>/sample-golang-kafka). To deploy the new repo, make a couple of changes to the .do/app.yaml file.

  1. Search and replace mykafka to your kafka instance name.
  2. Update the value of the environment variable KAFKA_TOPIC under envs to the kafka topic where you want to publish to and consume from.
  3. Set services -> github -> repo to your forked repository.

Once the above changes are made, run doctl apps create --spec .do/app.yaml.

  1. Go to https://cloud.digitalocean.com/apps, and select your app. You should see a "Building..." progress indicator. You can click View Logs to see more details of the build.
  2. It can take a few minutes for the build to finish, but you can follow the progress in the Deployments tab.
  3. Once the build completes successfully, right click on the Live App link in the header, click "Copy Link Address" and run curl -X POST https://xxx.ondigitalocean.app/produce --data "hello world!" in a terminal. Go to the Runtime Logs of the consumer and you should now see message consumed logs.

Making Changes to Your App

If you followed the steps to fork the repo and used your own copy when deploying the app, you can push changes to your fork and see App Platform automatically re-deploy the update to your app. During these automatic deployments, your application will never pause or stop serving request because App Platform offers zero-downtime deployments.

Learn More

You can learn more about the App Platform and how to manage and update your application at https://www.digitalocean.com/docs/app-platform/.

Deleting the App

When you no longer need this sample application running live, you can delete it by following these steps:

  1. Visit the Apps control panel at https://cloud.digitalocean.com/apps.
  2. Navigate to the sample app.
  3. In the Settings tab, click Destroy.

Note: If you do not delete your app, charges for using DigitalOcean services will continue to accrue.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published