Skip to content

Commit

Permalink
feat: publish the change stream to pubsub
Browse files Browse the repository at this point in the history
  • Loading branch information
ucpr committed Dec 16, 2023
1 parent d3321e0 commit 531b1ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
8 changes: 8 additions & 0 deletions cmd/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,13 @@ func NewEventHandler(ps pubsub.Publisher) *EventHandler {

func (e *EventHandler) EventHandler(ctx context.Context, event []byte) error {
log.Info("event", slog.String("event", string(event)))
res := e.pubsub.AsyncPublish(ctx, pubsub.Message{
Data: event,
})
id, err := res.Get(ctx)
if err != nil {
return err
}
log.Info("successful publish event", slog.String("id", id))
return nil
}
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ services:
- "8085:8085"
entrypoint: /bin/bash

pubsub-init:
image: gcr.io/google.com/cloudsdktool/cloud-sdk:455.0.0-emulators
depends_on:
- pubsub-emulator
environment:
PUBSUB_EMULATOR_HOST: "pubsub-emulator:8085"
command: |
gcloud config configurations create emulator && gcloud config set project dummy-project && gcloud config set auth/disable_credentials true && gcloud pubsub topics create dummy-topic && echo "finish setup pubsub"
mongo-streamer:
build: .
restart: always
Expand Down

0 comments on commit 531b1ea

Please sign in to comment.