Skip to content

Commit

Permalink
Get non-docker-compose commands working (#13)
Browse files Browse the repository at this point in the history
* Get non-docker-compose commands working

* Slight cleanups
  • Loading branch information
bufdev authored Oct 2, 2024
1 parent f76149d commit 80dbdcd
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 18 deletions.
41 changes: 25 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
BUFSTREAM_VERSION := 0.1.0

.DEFAULT_GOAL := run-docker-compose
.DEFAULT_GOAL := docker-compose-run

## Demo run commands

.PHONY: run-docker-compose
run-docker-compose: # Run the demo within docker compose.
.PHONY: docker-compose-run
docker-compose-run: # Run the demo within docker compose.
docker compose up --build

.PHONY: run-bufstream
run-bufstream: # Run Bufstream within Docker.
docker run --rm -p "9092:9092" -v "./config/bufstream.yaml:/bufstream.yaml" \
us-docker.pkg.dev/buf-images-1/bufstream-public/images/bufstream:$(BUFSTREAM_VERSION) -c "/bufstream.yaml"
.PHONY: docker-bufstream-run
docker-bufstream-run: # Run Bufstream within Docker.
docker run --rm -p 9092:9092 -v ./config/bufstream.yaml:/bufstream.yaml \
"us-docker.pkg.dev/buf-images-1/bufstream-public/images/bufstream:$(BUFSTREAM_VERSION)" \
--config /bufstream.yaml

.PHONY: run-consume
run-consume: # Run the demo consumer within Docker.
.PHONY: docker-produce-run
docker-produce-run: # Run the demo producer within Docker. If you have Go installed, you can call produce-run.
docker build -t bufstream/demo-produce -f Dockerfile.produce .
docker run --rm --network=host bufstream/demo-produce

.PHONY: docker-consume-run
docker-consume-run: # Run the demo consumer within Docker. If you have Go installed, you can call consume-run.
docker build -t bufstream/demo-consume -f Dockerfile.consume .
docker run --rm bufstream/demo-consume
docker run --rm --network=host bufstream/demo-consume

.PHONY: run-produce
run-produce: # Run the demo producer within Docker.
docker build -t bufstream/demo-produce -f Dockerfile.produce .
docker run --rm bufstream/demo-produce
.PHONY: produce-run
produce-run: # Run the demo producer. Go must be installed.
go run ./cmd/bufstream-demo-produce

.PHONY: consume-run
consume-run: # Run the demo consumer. Go must be installed.
go run ./cmd/bufstream-demo-consume

.PHONY: clean-docker-compose
clean-docker-compose: # Cleanup docker compose assets.
.PHONY: docker-compose-clean
docker-compose-clean: # Cleanup docker compose assets.
docker compose down --rmi all

## Development commands
Expand Down
1 change: 1 addition & 0 deletions cmd/bufstream-demo-consume/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func run(ctx context.Context, config app.Config) error {
consume.WithMessageHandler(handleEmailUpdated),
)

slog.Info("starting consume")
for {
// Read as many messages as we can.
//
Expand Down
11 changes: 11 additions & 0 deletions cmd/bufstream-demo-produce/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ package main

import (
"context"
"errors"
"log/slog"
"time"

Expand Down Expand Up @@ -52,11 +53,15 @@ func run(ctx context.Context, config app.Config) error {
config.Kafka.Topic,
)

slog.Info("starting produce")
for {
id := newID()
// Produces semantically-valid EmailUpdated message, where both email
// fields are valid email addresses.
if err := producer.ProduceProtobufMessage(ctx, id, newSemanticallyValidEmailUpdated(id)); err != nil {
if errors.Is(err, context.Canceled) {
return err
}
slog.Error("error on produce or semantically valid protobuf message", "error", err)
} else {
slog.Info("produced semantically valid protobuf message", "id", id)
Expand All @@ -65,13 +70,19 @@ func run(ctx context.Context, config app.Config) error {
// Produces a semantically-invalid EmailUpdated message, where the new email field
// is not a valid email address.
if err := producer.ProduceProtobufMessage(ctx, id, newSemanticallyInvalidEmailUpdated(id)); err != nil {
if errors.Is(err, context.Canceled) {
return err
}
slog.Error("error on produce of semantically invalid protobuf message", "error", err)
} else {
slog.Info("produced semantically invalid protobuf message", "id", id)
}
id = newID()
// Produces record containing a payload that is not valid Protobuf.
if err := producer.ProduceInvalid(ctx, id); err != nil {
if errors.Is(err, context.Canceled) {
return err
}
slog.Error("error on produce of invalid data", "error", err)
} else {
slog.Info("produced invalid data", "id", id)
Expand Down
2 changes: 1 addition & 1 deletion config/bufstream.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ kafka:
host: 0.0.0.0
port: 9092
public_address:
host: bufstream
host: 0.0.0.0
port: 9092
observability:
trace_exporter: NONE
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ services:
# Edit config/bufstream.yaml within this repository to change configuation.
volumes:
- "./config/bufstream.yaml:/bufstream.yaml"
command: [ "-c", "/bufstream.yaml" ]
command: [
"--config", "/bufstream.yaml",
"--config.kafka.public_address.host", "bufstream",
]
# The demo consumer.
#
# This is a Docker image that just runs the binary created from cmd/bufstream-demo-consume.
Expand Down

0 comments on commit 80dbdcd

Please sign in to comment.