pubsub_middleware

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2020 License: MIT Imports: 2 Imported by: 0

README

Pub/Sub middleware

GoDoc Build Status codecov Go Report Card

This repo contains go middleware for Google Pub/Sub. See the following links for more information on Google Pub/Sub.

https://cloud.google.com/pubsub/docs/overview

https://github.com/googleapis/google-cloud-go/tree/master/pubsub

The following snippet shows how to use recovery middleware when receiving pubsub messages.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/bvwells/pubsub-middleware/recovery"

	"cloud.google.com/go/pubsub"
)

func main() {
	ctx := context.Background()
	client, err := pubsub.NewClient(ctx, "project-id")
	if err != nil {
		log.Fatal(err)
	}

	// Log message ID if panic occurs when processing received message.
	recoveryFunc := recovery.WithRecoveryFunc(func(_ context.Context, msg *pubsub.Message, _ interface{}) {
		log.Printf("recovered from panic while handling message '%s'", msg.ID)
	})

	// Use a callback to receive messages via subscription.
	sub := client.Subscription("subscription")
	err = sub.Receive(ctx, recovery.NewRecoveryHandler(func(ctx context.Context, m *pubsub.Message) {
		fmt.Println(m.Data)
		m.Ack() // Acknowledge that we've consumed the message.
	}, recoveryFunc))
	if err != nil {
		log.Println(err)
	}
}

Documentation

Overview

Package pubsub_middleware is a collection of Google Pub/Sub middleware.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HandlerFunc

type HandlerFunc func(ctx context.Context, m *pubsub.Message)

HandlerFunc is a pubsub handler function which can be used in pubsub subscription receive.

Directories

Path Synopsis
Package logging contains middleware for logging handling of messages.
Package logging contains middleware for logging handling of messages.
logrus
Package pubsub_logrus contains middleware which logs messages using the logrus structured logger (see https://github.com/sirupsen/logrus).
Package pubsub_logrus contains middleware which logs messages using the logrus structured logger (see https://github.com/sirupsen/logrus).
Package recovery contains middleware which recovers when a pubsub receive function panics.
Package recovery contains middleware which recovers when a pubsub receive function panics.

Jump to

Keyboard shortcuts

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