Skip to content

Latest commit

 

History

History
114 lines (96 loc) · 4.6 KB

README.md

File metadata and controls

114 lines (96 loc) · 4.6 KB

js-pubsub-rest-proxy

An HTTP server which acts as a gateway for publishing messages via a js-pubsub adapter.

Author Software License NPM Version NPM Downloads

This service wraps the js-pubsub-manager library which bundles support for the following adapters:

  • Local
  • /dev/null
  • Redis
  • Google Cloud

It exposes a /messages/(channel) end-point where messages can be POSTed to.

eg:

POST /messages/test HTTP/1.1
Content-Type: application/json

{
	"messages": [
		"Hello World",
		{
			"another": "message"
		}
	]
}

This is an async end-point which queues messages for background publishing.

The js-pubsub-http adapter is a client-side implementation for publishing messages via this service.

Installation

The service is available as a docker image OR an npm package.

npm install @superbalist/js-pubsub-rest-proxy

Environment Variables

When you start the js-pubsub-rest-proxy image, you can adjust the configuration of the instance by passing one or more environment variables on the docker run command line.

Env Var Default Description
PORT 3000 The port the web server will listen on
LOG_LEVEL info The log level (silly, debug, verbose, info, warn, error)
SENTRY_DSN null
MAX_POST_SIZE 10mb The max post size for request payloads
PUBSUB_CONNECTION redis The pub/sub connection to use (/dev/null, local, redis, gcloud)
REDIS_HOST localhost
REDIS_PORT 6379
GOOGLE_CLOUD_PROJECT_ID null
GOOGLE_APPLICATION_CREDENTIALS null The full path to the file containing the Google Cloud credentials
GOOGLE_CLOUD_CLIENT_IDENTIFIER null The client identifier used when talking to Google Cloud
VALIDATION_ERROR_SCHEMA_URL false The url for invalid event schema below. Enables validation
VALIDATION_ERROR_CHANNEL validation_error The channel to publish validation errors to
PUBLISH_INVALID true Publish invalid events (true, false)
RABBITMQ_FALLBACK false Whether the fallback should be used or now (true, false)
RABBITMQ_URL pubsub-rest-proxy-rabbitmq Url with rabbitmq fallback
RABBITMQ_USER guest Rabbitmq user
RABBITMQ_PASSWORD guest Should be a base64 encoded string (guest == Z3Vlc3Q=)

Running

  1. Start a container using the Redis Pub/Sub adapter
$ docker run \
  -d \
  --rm \
  --name js-pubsub-rest-proxy \
  -e PUBSUB_CONNECTION='redis' \
  -e REDIS_HOST='127.0.0.1' \
  -e REDIS_PORT='6379' \
  superbalist/js-pubsub-rest-proxy
  1. Start a container using the Google Cloud Pub/Sub adapter
$ docker run \
  -d \
  --rm \
  --name js-pubsub-rest-proxy \
  -e PUBSUB_CONNECTION='gcloud' \
  -e GOOGLE_CLOUD_PROJECT_ID='your-project-id-here' \
  -e GOOGLE_APPLICATION_CREDENTIALS='/etc/gcloud_credentials.json' \
  superbalist/js-pubsub-rest-proxy

Validation Error Schema

"properties": {
  "schema": {
      "type": "string",
      "format": "uri"
  },
  "meta": {
      "type": "object"
  },
  "event": {
      "type": "object"
  },
  "errors": {
      "type": "array"
  }
}