Skip to content

Commit

Permalink
Add kafka example
Browse files Browse the repository at this point in the history
  • Loading branch information
zalbiraw committed Nov 13, 2024
1 parent 6b47a7c commit c8c3d04
Show file tree
Hide file tree
Showing 8 changed files with 493 additions and 35 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
vendor
server
producer
**/.DS_Store
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN CGO_ENABLED=0 GO111MODULE=on go build -o services/graphql-subgraphs/users/se
RUN CGO_ENABLED=0 GO111MODULE=on go build -o services/graphql-subgraphs/posts/server services/graphql-subgraphs/posts/server.go
RUN CGO_ENABLED=0 GO111MODULE=on go build -o services/graphql-subgraphs/comments/server services/graphql-subgraphs/comments/server.go
RUN CGO_ENABLED=0 GO111MODULE=on go build -o services/graphql-subgraphs/notifications/server services/graphql-subgraphs/notifications/server.go
RUN CGO_ENABLED=0 GO111MODULE=on go build -o services/kafka/notifications/producer services/kafka/notifications/producer.go

# Stage 2: Create the final lightweight image
FROM alpine:latest
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# go-api-test-service
This library allows you to launch different REST, GraphQL and GraphQL subgraphs to help test your APIs.
This library allows you to launch different REST, GraphQL, GraphQL subgraphs, and Kafka producers to help test your APIs.

The available services are:
- rest
Expand All @@ -14,6 +14,7 @@ The available services are:
- posts-subgraph
- comments-subgraph
- notifications-subgraph (federated subscription)
- notifications-kafka-producer

The same docker file will allow you to run the different services. You can launch the service you want by setting the entrypoint to the docker container to be `entrypoint: ./$SERVICE_NAME/server`.

Expand All @@ -38,6 +39,7 @@ Run `docker-compose up` from the root of the repo. You should be able to access
- posts-subgraph: `4202`
- comments-subgraph: `4203`
- notifications-subgraph: `4204`
- notifications-kafka-producer: `5104`

### Containers
Containers are available on DockerHub under [zalbiraw/go-api-test-service](https://hub.docker.com/r/zalbiraw/go-api-test-service).
Expand Down
89 changes: 64 additions & 25 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,132 +1,171 @@
services:
rest:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: rest
entrypoint: ./services/rest/rest/server

environment:
- PORT=3100
PORT: 3100

ports:
- "3100:3100"

users-rest:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: users-rest
entrypoint: ./services/rest/users/server

environment:
- PORT=3101
PORT: 3101

ports:
- "3101:3101"

posts-rest:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: posts-rest
entrypoint: ./services/rest/posts/server

environment:
- PORT=3102
PORT: 3102

ports:
- "3102:3102"

comments-rest:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: comments-rest
entrypoint: ./services/rest/comments/server

environment:
- PORT=3103
PORT: 3103

ports:
- "3103:3103"

users-graph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: users-graph
entrypoint: ./services/graphql/users/server

environment:
- PORT=4101
PORT: 4101

ports:
- "4101:4101"

posts-graph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: posts-graph
entrypoint: ./services/graphql/posts/server

environment:
- PORT=4102
PORT: 4102

ports:
- "4102:4102"

comments-graph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: comments-graph
entrypoint: ./services/graphql/comments/server

environment:
- PORT=4103
PORT: 4103

ports:
- "4103:4103"

notifications-graph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: notifications-graph
entrypoint: ./services/graphql/notifications/server

environment:
- PORT=4104
PORT: 4104

ports:
- "4104:4104"

users-subgraph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: users-subgraph
entrypoint: ./services/graphql-subgraphs/users/server

environment:
- PORT=4201
PORT: 4201

ports:
- "4201:4201"

posts-subgraph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: posts-subgraph
entrypoint: ./services/graphql-subgraphs/posts/server

environment:
- PORT=4202
PORT: 4202

ports:
- "4202:4202"

comments-subgraph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: comments-subgraph
entrypoint: ./services/graphql-subgraphs/comments/server

environment:
- PORT=4203
PORT: 4203

ports:
- "4203:4203"

notifications-subgraph:
image: zalbiraw/go-api-test-service:v3.3.0
image: zalbiraw/go-api-test-service:v3.4.0
container_name: notifications-subgraph
entrypoint: ./services/graphql-subgraphs/notifications/server

environment:
- PORT=4204
PORT: 4204

ports:
- "4204:4204"
- "4204:4204"

notifications-kafka-producer:
image: zalbiraw/go-api-test-service:v3.4.0
container_name: notifications-kafka-producer
entrypoint: ./services/kafka/notifications/producer

networks:
- kafka

environment:
KAFKA_BROKER_URL: http://kafka:9092
KAFKA_TOPIC: test
PRODUCE_INTERVAL: 5

kafka:
image: apache/kafka:3.9.0

networks:
- kafka

environment:
KAFKA_NODE_ID: 1
KAFKA_PROCESS_ROLES: broker,controller
KAFKA_LISTENERS: PLAINTEXT://:9092,CONTROLLER://:9093
KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092
KAFKA_CONTROLLER_LISTENER_NAMES: CONTROLLER
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: CONTROLLER:PLAINTEXT,PLAINTEXT:PLAINTEXT
KAFKA_CONTROLLER_QUORUM_VOTERS: 1@localhost:9093
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_REPLICATION_FACTOR: 1
KAFKA_TRANSACTION_STATE_LOG_MIN_ISR: 1
KAFKA_GROUP_INITIAL_REBALANCE_DELAY_MS: 0
KAFKA_NUM_PARTITIONS: 3

ports:
- "9092:9092"

networks:
kafka:
13 changes: 8 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@ go 1.23

require (
github.com/99designs/gqlgen v0.17.13
github.com/confluentinc/confluent-kafka-go v1.9.2
github.com/go-chi/chi v1.5.4
github.com/gorilla/websocket v1.5.0
github.com/linkedin/goavro v2.1.0+incompatible
github.com/vektah/gqlparser/v2 v2.4.6
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0
go.opentelemetry.io/otel v1.29.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0
go.opentelemetry.io/otel/sdk v1.29.0
gopkg.in/loremipsum.v1 v1.1.0
)

Expand All @@ -16,19 +22,16 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.22.0 // indirect
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/logrusorgru/aurora/v3 v3.0.0 // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.14 // indirect
github.com/mitchellh/mapstructure v1.4.3 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.54.0 // indirect
go.opentelemetry.io/otel v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.29.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.29.0 // indirect
go.opentelemetry.io/otel/metric v1.29.0 // indirect
go.opentelemetry.io/otel/sdk v1.29.0 // indirect
go.opentelemetry.io/otel/trace v1.29.0 // indirect
go.opentelemetry.io/proto/otlp v1.3.1 // indirect
golang.org/x/net v0.28.0 // indirect
Expand All @@ -38,5 +41,5 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20240822170219-fc7c04adadcd // indirect
google.golang.org/grpc v1.65.0 // indirect
google.golang.org/protobuf v1.34.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
gopkg.in/linkedin/goavro.v1 v1.0.5 // indirect
)
Loading

0 comments on commit c8c3d04

Please sign in to comment.