Skip to content

Commit 22287d3

Browse files
author
Grzegorz Burzyński
authored
Add docs on publishing messages in transactions with help of Forwarder component (ThreeDotsLabs#261)
1 parent 28527d6 commit 22287d3

File tree

10 files changed

+1374
-1
lines changed

10 files changed

+1374
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
validation_cmd: "docker-compose up"
2+
teardown_cmd: "docker-compose down"
3+
timeout: 60
4+
expected_output: "Sending a prize to the winner"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Publishing events in transactions with help of Forwarder component (MySQL to Google Pub/Sub)
2+
3+
While working with an event-driven application, you may in some point need to store an application state and publish a message
4+
telling the rest of the system about what just happened. As it may look trivial at a first glance, it could become
5+
a bit tricky if we consider what can go wrong in case we won't pay enough attention to details.
6+
7+
## Solution
8+
9+
This example presents a solution to this problem: saving events in transaction along with persisting application state.
10+
It also compares two other approaches which lack transactional publishing therefore expose application to a risk
11+
of inconsistency across the system.
12+
13+
## Requirements
14+
15+
To run this example you will need Docker and docker-compose installed. See installation guide at https://docs.docker.com/compose/install/
16+
17+
## Running
18+
19+
```bash
20+
docker-compose up
21+
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
version: '3'
2+
services:
3+
server:
4+
image: golang:1.17
5+
environment:
6+
- PUBSUB_EMULATOR_HOST=googlecloud:8085
7+
depends_on:
8+
- mysql
9+
- googlecloud
10+
volumes:
11+
- .:/app
12+
- $GOPATH/pkg/mod:/go/pkg/mod
13+
working_dir: /app
14+
command: go run .
15+
16+
mysql:
17+
image: mysql:8.0
18+
restart: unless-stopped
19+
logging:
20+
driver: none
21+
ports:
22+
- 3306:3306
23+
environment:
24+
MYSQL_DATABASE: watermill
25+
MYSQL_ALLOW_EMPTY_PASSWORD: "yes"
26+
27+
googlecloud:
28+
image: google/cloud-sdk:360.0.0
29+
logging:
30+
driver: none
31+
entrypoint: gcloud --quiet beta emulators pubsub start --host-port=0.0.0.0:8085 --verbosity=debug --log-http
32+
ports:
33+
- 8085:8085
34+
restart: unless-stopped
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
module main.go
2+
3+
go 1.17
4+
5+
require (
6+
github.com/ThreeDotsLabs/watermill v1.2.0-rc.7
7+
github.com/ThreeDotsLabs/watermill-googlecloud v1.0.11
8+
github.com/ThreeDotsLabs/watermill-sql v1.3.5
9+
github.com/go-sql-driver/mysql v1.4.1
10+
)
11+
12+
require (
13+
cloud.google.com/go v0.97.0 // indirect
14+
cloud.google.com/go/pubsub v1.17.0 // indirect
15+
github.com/cenkalti/backoff/v3 v3.2.2 // indirect
16+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
17+
github.com/golang/protobuf v1.5.2 // indirect
18+
github.com/google/go-cmp v0.5.6 // indirect
19+
github.com/google/uuid v1.3.0 // indirect
20+
github.com/googleapis/gax-go/v2 v2.1.1 // indirect
21+
github.com/hashicorp/errwrap v1.1.0 // indirect
22+
github.com/hashicorp/go-multierror v1.1.1 // indirect
23+
github.com/lithammer/shortuuid/v3 v3.0.7 // indirect
24+
github.com/oklog/ulid v1.3.1 // indirect
25+
github.com/pkg/errors v0.9.1 // indirect
26+
go.opencensus.io v0.23.0 // indirect
27+
golang.org/x/net v0.0.0-20211008194852-3b03d305991f // indirect
28+
golang.org/x/oauth2 v0.0.0-20211005180243-6b3c2da341f1 // indirect
29+
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
30+
golang.org/x/sys v0.0.0-20211007075335-d3039528d8ac // indirect
31+
golang.org/x/text v0.3.7 // indirect
32+
google.golang.org/api v0.59.0 // indirect
33+
google.golang.org/appengine v1.6.7 // indirect
34+
google.golang.org/genproto v0.0.0-20211028162531-8db9c33dc351 // indirect
35+
google.golang.org/grpc v1.41.0 // indirect
36+
google.golang.org/protobuf v1.27.1 // indirect
37+
)

_examples/real-world-examples/transactional-events-forwarder/go.sum

Lines changed: 798 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)