1.2.2 • Published 5 years ago

@superbalist/js-pubsub-rest-proxy v1.2.2

Weekly downloads
-
License
MIT
Repository
github
Last release
5 years ago

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 VarDefaultDescription
PORT3000The port the web server will listen on
LOG_LEVELinfoThe log level (silly, debug, verbose, info, warn, error)
SENTRY_DSNnull
MAX_POST_SIZE10mbThe max post size for request payloads
PUBSUB_CONNECTIONredisThe pub/sub connection to use (/dev/null, local, redis, gcloud)
REDIS_HOSTlocalhost
REDIS_PORT6379
GOOGLE_CLOUD_PROJECT_IDnull
GOOGLE_APPLICATION_CREDENTIALSnullThe full path to the file containing the Google Cloud credentials
GOOGLE_CLOUD_CLIENT_IDENTIFIERnullThe client identifier used when talking to Google Cloud
VALIDATION_ERROR_SCHEMA_URLfalseThe url for invalid event schema below. Enables validation
VALIDATION_ERROR_CHANNELvalidation_errorThe channel to publish validation errors to
PUBLISH_INVALIDtruePublish invalid events (true, false)
RABBITMQ_FALLBACKfalseWhether the fallback should be used or now (true, false)
RABBITMQ_URLpubsub-rest-proxy-rabbitmqUrl with rabbitmq fallback
RABBITMQ_USERguestRabbitmq user
RABBITMQ_PASSWORDguestShould 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"
  }
}