notification-client

module
v0.3.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2023 License: AGPL-3.0

README

notification-client

Notification client is a golang library for sending notification events to internal PubSub which later on is delivered to the users using Firebase Cloud Messaging or in-app notifications.

Installation

go get gitlab.com/picnic-app/backend/libs/golang/notification-client@<branch-name/tag>

Setup

In your cfg file extend env field with following parameters:

env:
  pubsub:
    project: picnic-stg

Next, go to .gitlab/terraform and add a new file pubsub.tf with following content:

module "pubsub" {
  source  = "gitlab.com/picnic-app/pubsub/google"
  version = "~> 1.0"

  env_id       = var.env_id
  service_name = var.service_name
  sa_email     = module.workload-identity.service_account.email

  subscriptions = []

  publishes = [
    "notification_ingest",
  ]
}

Usage

package main

import (
	"context"

	"gitlab.com/picnic-app/backend/libs/golang/notification-client/pkg/publisher"
)

func main() {
	ctx := context.Background()

	projectID := "some-random-project"
	// We need to pass envID because our subscriber has filter by message attribute "env_id".
	envID := "local-env"

	// First we need to create a new PubSub client.
	client, err := publisher.NewPubSubClient(ctx, projectID, "")
	if err != nil {
		panic(err)
	}

	// Later on using PubSub client we create connection to a particular topic.
	// Currently we only support SingleNotificationIngestTopic.
	pub, err := publisher.NewPublisher(ctx, envID, client, publisher.SingleNotificationIngestTopic)
	if err != nil {
		panic(err)
	}

	// To create a message we can use predefined functions - recommended,
	// or fill protobuf messages on our own.
	msg, err := publisher.CreateUserFollowedEvent("123", "Bob", "456")
	if err != nil {
		panic(err)
	}

	// To publish a message to a Google Cloud Pub/Sub topic just use Publish method.
	if err = pub.Publish(ctx, msg); err != nil {
		panic(err)
	}

	pub.Close()
}

Available notifications

All available notifications that we currently support are here.

Directories

Path Synopsis
examples
publisher command
pkg

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL