pubsubpush

package module
v0.0.0-...-5b34bd1 Latest Latest
Warning

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

Go to latest
Published: Mar 1, 2023 License: Apache-2.0 Imports: 7 Imported by: 0

README

pubsub-push

pubsub-push is a small utility for Pulling messages from a subscription in Google PubSub and redirect them as an HTTP POST to a local endpoint.

It is necessary because using the normal PubSub HTTP Push you need a public and a domain verified endpoint. Using this tool for development purposes you will be able to receive HTTP Push locally.

Installation

You can just download the latest binary from Releases tab and put it inside your PATH.

If you have a recent go installation, you can use:

$ go get github.com/klassmann/pubsub-push
$ go install github.com/klassmann/pubsub-push/cmd/pubsub-push

Usage

Before running, you have to set GOOGLE_APPLICATION_CREDENTIALS environment variable with the path of your service account key created with the correct Roles for getting messages from the desired subscription. See more here and here.

Example in Linux/Mac:

$ export GOOGLE_APPLICATION_CREDENTIALS=$HOME/project/key.json

After that you should run the following command with your configurations. These arguments are required:

$ pubsub-push -project gcloud-project -sub subscription_name -endpoint http://localhost

If you want to add some headers to request, you can use the -header option.

Note that -header can be used multiple times and you must use the format "key=value".

Adding headers:

$ pubsub-push -project proj-id -sub name -endpoint localhost -header "Content-type=application/json" -header "Auth-Key=my-secret-key"
Arguments
-project        The ID of your project inside Google Cloud Platform.
                    Eg: -project my-cloud-project

-sub            The subscription name, not including namespace, only the name.
                    Eg: -sub topic_sub

-endpoint       The complete URL, including schema, domain, port and the path.
                    Eg: -endpoint http://localhost:5000/services/sync

-header         A string like "key=value" for request headers. It can be used
                multiplem times.
                    Eg: -header "Content-type=application/json"

Requirements and Go version

It was built with go1.12.5 linux/amd64 and you can see dependencies inside go.mod.

License

Apache 2.0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EncodeMessage

func EncodeMessage(m *pubsub.Message) ([]byte, int)

EncodeMessage prepares the message to be like the HTTP Push from PubSub It is a JSON with a data field containing a base64 value

func PostMessage

func PostMessage(url string, contentType string, body io.Reader, h *Headers) (*http.Response, error)

PostMessage sends the message to endpoint

Types

type Headers

type Headers []string

Headers is the list of HTTP Header to be applied on Request

func (*Headers) Set

func (h *Headers) Set(value string) error

Set appends a new Header

func (*Headers) String

func (h *Headers) String() string

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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