All Projects → sagi → workers-pubsub

sagi / workers-pubsub

Licence: MIT license
Google Pub/Sub API for Cloudflare Workers (and Node.js)

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to workers-pubsub

Gizmo
A Microservice Toolkit from The New York Times
Stars: ✭ 3,566 (+14164%)
Mutual labels:  pubsub, google-pubsub
emulator-tools
Google Cloud BigTable and PubSub emulator tools to make development a breeze
Stars: ✭ 16 (-36%)
Mutual labels:  pubsub, google-pubsub
cloudenvoy
Cross-application messaging for Ruby and Rails using Google Cloud Pub/Sub
Stars: ✭ 31 (+24%)
Mutual labels:  pubsub, google-pubsub
iris3
An upgraded and improved version of the Iris automatic GCP-labeling project
Stars: ✭ 38 (+52%)
Mutual labels:  pubsub, google-pubsub
gobroker
golang wrapper for all (to-be) kinds of message brokers
Stars: ✭ 15 (-40%)
Mutual labels:  pubsub, google-pubsub
workers-unsplash-api
Serverless API for requesting images from Unsplash's API, designed for use with a React frontend
Stars: ✭ 20 (-20%)
Mutual labels:  cloudflare-workers
network-monorepo
Monorepo containing all the main components of Streamr Network.
Stars: ✭ 223 (+792%)
Mutual labels:  pubsub
remix-guide
A platform for sharing everything about Remix
Stars: ✭ 197 (+688%)
Mutual labels:  cloudflare-workers
twurple
Interact with Twitch's API, chat and subscribe to events via PubSub and EventSub.
Stars: ✭ 479 (+1816%)
Mutual labels:  pubsub
websub-hub
A WebSub Hub implementation in Node.js
Stars: ✭ 44 (+76%)
Mutual labels:  pubsub
parsed-html-rewriter
A DOM-based implementation of Cloudflare Worker's HTMLRewriter.
Stars: ✭ 34 (+36%)
Mutual labels:  cloudflare-workers
webfunc
Universal Serverless Web Framework. Write Express apps ready to be deployed to Zeit-Now, Google Cloud Functions (incl. functions reacting to Pub/Sub topics or Storage changes), and AWS Lambdas.
Stars: ✭ 71 (+184%)
Mutual labels:  pubsub
uorb
C++ inter-thread publish/subscribe middleware ported from PX4 and redesigned based on POSIX
Stars: ✭ 35 (+40%)
Mutual labels:  pubsub
smartacus-mqtt-broker
smartacus-mqtt-broker is a Java-based open source MQTT broker that fully supports MQTT 3.x .Using Netty 4.1.37
Stars: ✭ 25 (+0%)
Mutual labels:  pubsub
reader
get a reader mode sharable url for any url - built with cloudflare workers https://reader.tuananh.net
Stars: ✭ 24 (-4%)
Mutual labels:  cloudflare-workers
payload
A javascript single page application (SPA) driver for REST API payload management.
Stars: ✭ 16 (-36%)
Mutual labels:  pubsub
dead-simple
💀💡 Dead simple PubSub and EventEmitter in JavaScript
Stars: ✭ 21 (-16%)
Mutual labels:  pubsub
IPFS PHOTO SHARE
💰用甚嚒服务器,ServerLess搭建一个图片分享站点!| 基于CloudFlareWorker无服务器函数和IPFS去中心化存储的图片分享网站
Stars: ✭ 76 (+204%)
Mutual labels:  cloudflare-workers
notification
OST Notification helps publish critical events for cross platform communications
Stars: ✭ 20 (-20%)
Mutual labels:  pubsub
workers-react-pwa-example
No description or website provided.
Stars: ✭ 80 (+220%)
Mutual labels:  cloudflare-workers

workers-pubsub

@sagi.io/workers-pubsub is a Google Pub/Sub REST API for Cloudflare Workers (can also be used with Node).

We use it at OpenSay to efficiently access Google's PubSub REST API with 1 round trip.

CircleCI Coverage Status MIT License version

Installation

$ npm i @sagi.io/workers-pubsub

API

We follow Google's Pub/Sub REST API specification. We'll add more methods if there's demand.

See below for concrete examples for Cloudflare Workers and Node.js.

PubSubREST({ ... })

Instantiates PubSub instance.

Function definition:

 const PubSubREST = async ({
  serviceAccountJSON,
  cryptoImpl = null,
  fetchImpl = null,
}) => { ... }

Where:

  • serviceAccountJSON required Is a Google Cloud service account with a Pub/Sub Admin role. An object.
  • cryptoImpl optional Not needed when running on Cloudflare Workers. See concrete example below for how to use it with Node.js.
  • fetchImpl optional Not needed when running on Cloudflare Workers. See concrete example below for how to use it with Node.js.

PubSub.topics.publish({ ... })

Publishes a message to a topic.

Function definition:

const publish = ({ topic, messages } = {}) => { ... }

Where:

  • topic required The topic to send messages to.
  • messages required an array of Pub/Sub messages. You can use the PubSub.helpers.createPubSubMessage method to easily create a Pub/Sub message.

PubSub.topics.list({ ... })

Lists all topics.

PubSub.helpers.createPubSubMessage({ ... })

Helps create a PubSub message easily.

Function definition:

const createPubSubMessage = ({ message = '', attributes = undefined } = {}) => { ... }

Where:

  • message optional A message string. e.g. Hello World.
  • attributes optional An object with string values. e.g. { type: 'slack-poll' }.
  • ordering_key optional An ordering key to allow subscribers to receive messages in order in the same region. Read more here.

Returns a Pub/Sub message.

Cloudflare Workers Example

import base64url from 'base64url'
import PubSubREST from '@sagi.io/workers-pubsub'

const serviceAccountJSON = ...

const PubSub = await PubSubREST({ serviceAccountJSON })

const topic = 'gcf-task'
const psMessage = PubSub.helpers.createPubSubMessage({ message: 'Hello World!' })
const messages = [ psMessage ]

await PubSub.topics.publish({ topic, messages })

Node.js Example

import fetchImpl from 'cross-fetch'
import { Crypto }from 'node-webcrypto-ossl'
import PubSubREST from '@sagi.io/workers-pubsub'

const cryptoImpl = new Crypto()

const serviceAccountJSON = ...

const PubSub = await PubSubREST({ serviceAccountJSON, cryptoImpl. fetchImpl })

const topic = 'gcf-task'
const psMessage = PubSub.helpers.createPubSubMessage({ message: 'Hello World!' })
const messages = [ psMessage ]

await PubSub.topics.publish({ topic, messages })
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].