Skip to content

Commit 3d777b0

Browse files
committed
Updated Legacy Package Versions and Restructured File Layout
1 parent ea51c39 commit 3d777b0

File tree

19 files changed

+1639
-9
lines changed

19 files changed

+1639
-9
lines changed

.env-example

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
defaultBindAddr=:8080
2+
defaultMetricsBindAddr=:8081
3+
defaultGrafanaURL=http://grafana:3000
4+
defaultGrafanaCredentials=admin:secret
5+
defaultAMQPURI=amqp://guest:guest@rabbitmq:5672/
6+
defaultAMQPQueue=deployments
7+
defaultKafkaBrokers=kafka:9092
8+
defaultKafkaTopic=events

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2023 Furkan Gulsen
3+
Copyright (c) 2019 Three Dots Labs
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,52 @@
1-
# Event Drivent Architecture with Golang
1+
# Event Driven Architecture with Golang (Example)
2+
3+
This is an example Event-Driven application written in Go, using [Watermill](https://github.com/ThreeDotsLabs/watermill).
4+
5+
The projects aims to integrate incoming GitHub webhooks with Grafana and Slack, essentially adding annotations and
6+
sending messages when a new commit is pushed. There are also simulated deployment messages sent over RabbitMQ to
7+
demonstrate working with multiple event streams.
8+
9+
![](https://threedots.tech/media/event-driven-applications/diagram.png)
10+
11+
An example result can look like this:
12+
13+
![](https://threedots.tech/media/event-driven-applications/grafana.png)
14+
15+
![](https://threedots.tech/media/event-driven-applications/slack.png)
16+
17+
## Running
18+
19+
If you'd like to integrate the example with your Slack workspace, copy `.env-example` to `.env` and fill in the
20+
webhook URL in `SLACK_WEBHOOK_URL` variable.
21+
22+
In addition to the application, the docker-compose environment consists of:
23+
24+
- **Kafka** and **ZooKeeper**
25+
- **RabbitMQ**
26+
- **Grafana**
27+
- **Prometheus**
28+
29+
The whole environment can be run with:
30+
31+
```bash
32+
docker-compose up
33+
```
34+
35+
You can now configure your GitHub repository to send webhooks to the application (you need to expose port `8080` to the
36+
external network first).
37+
38+
Alternatively, you can run `./scripts/send-stub-webhook.sh` to send some stub webhooks.
39+
40+
Visit [localhost:3000/d/webhooks](http://localhost:3000/d/webhooks) to see annotations added in Grafana. Use
41+
`admin:secret` as credentials.
42+
43+
## Metrics
44+
45+
You can access the Watermill dashboard at [localhost:3000/d/watermill](http://localhost:3000/d/watermill). See what
46+
changes when you send more webhooks over time.
47+
48+
![](https://threedots.tech/media/event-driven-applications/metrics.png)
49+
50+
## What's next?
51+
52+
See [Watermill's documentation](https://watermill.io/) to learn more.
File renamed without changes.

myapp/cmd/app/main.go renamed to app/cmd/app/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ package main
33
import (
44
"context"
55

6-
"github.com/Furkan-Gulsen/Event-Driven-Architecture-with-Golang/config"
7-
"github.com/Furkan-Gulsen/Event-Driven-Architecture-with-Golang/internal"
6+
"github.com/ThreeDotsLabs/event-driven-example/config"
7+
"github.com/ThreeDotsLabs/event-driven-example/internal"
88
"github.com/ThreeDotsLabs/watermill"
99
"github.com/ThreeDotsLabs/watermill/components/metrics"
1010
"github.com/ThreeDotsLabs/watermill/message"

myapp/config/config.go renamed to app/config/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ type Config struct {
3131

3232
KafkaBrokers []string
3333
KafkaTopic string
34+
35+
SlackWebhookURL string
3436
}
3537

3638
func LoadConfig() Config {
@@ -46,6 +48,8 @@ func LoadConfig() Config {
4648

4749
GrafanaURL: getEnv("GRAFANA_URL", defaultGrafanaURL),
4850
GrafanaCredentials: getEnv("GRAFANA_CREDENTIALS", defaultGrafanaCredentials),
51+
52+
SlackWebhookURL: getEnv("SLACK_WEBHOOK_URL", ""),
4953
}
5054
}
5155

myapp/go.mod renamed to app/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/Furkan-Gulsen/Event-Driven-Architecture-with-Golang
1+
module github.com/ThreeDotsLabs/event-driven-example
22

33
go 1.21
44

File renamed without changes.

myapp/internal/router.go renamed to app/internal/router.go

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import (
55
"math/rand"
66
"time"
77

8-
"github.com/Furkan-Gulsen/Event-Driven-Architecture-with-Golang/config"
9-
"github.com/Furkan-Gulsen/Event-Driven-Architecture-with-Golang/pkg"
8+
"github.com/ThreeDotsLabs/event-driven-example/config"
9+
"github.com/ThreeDotsLabs/event-driven-example/pkg"
1010
"github.com/ThreeDotsLabs/watermill"
1111
"github.com/ThreeDotsLabs/watermill-amqp/pkg/amqp"
1212
"github.com/ThreeDotsLabs/watermill-http/pkg/http"
@@ -140,6 +140,26 @@ func (r *Router) SetupRouter() error {
140140
pkg.GrafanaHandler,
141141
)
142142

143+
if r.Config.SlackWebhookURL != "" {
144+
slackPublisher, err := http.NewPublisher(
145+
http.PublisherConfig{
146+
MarshalMessageFunc: pkg.SlackMarshaller,
147+
}, r.Logger)
148+
if err != nil {
149+
return err
150+
}
151+
152+
r.Router.AddHandler(
153+
"kafka-to-slack",
154+
r.Config.KafkaTopic,
155+
kafkaSubscriber,
156+
r.Config.SlackWebhookURL,
157+
slackPublisher,
158+
pkg.SlackHandler,
159+
)
160+
}
161+
162+
// * DeploySimulator is a handler that simulates a deployment to a given environment.
143163
stagingDelay := time.Second * time.Duration(rand.Intn(60)+30)
144164
productionDelay := stagingDelay + time.Second*time.Duration(rand.Intn(120)+60)
145165

File renamed without changes.

0 commit comments

Comments
 (0)