npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@minso_minso/cloud-run-pubsub

v2.2.5

Published

Package with the boilerplate to use PubSub with Cloud Run. Is essentially a wrapper around Express.js

Downloads

43

Readme

Cloud Run PubSub

About

This is a package that receives and parses PubSub messages while deployed on Cloud Run.

It is basically a wrapper around Express.js so everything that is possible in Express is possible here too.

Usage

For the basic use case, just receiving messages and not doing anything special, following snippet is enough. Note that the handlefunction must be bound to the instance if it needs to use this inside the function.

import { CloudRunPubsub } from '@minso_minso/cloud-run-pubsub'

const msg = new MessageHandler()
const pubsub = new CloudPubSub({
	port: 5000,
	handleFunc: msg.handleFunc.bind(msg),
})

pubsub.listen()

It is possible to add Sentry integration by providing Sentry.NodeOptions to the CloudPubSub constructor as following:

const pubsub = new CloudRunPubsub({
	handleFunc: async (message: Message) => console.log(message),
	port: process.env.PORT || 5000,
	sentrySettings: {
		dsn: process.env.SENTRY_DSN,
		release: process.env.VERSION || 'DEV',
	},
})

The handleFunc needs to accept a message as its single parameter (others can be added with defaults etc). Messages has the following props:

type Message = {
	id: string
	attributes: {
		eventType: string
	}
	data: unknown
}

attributes can have more props but in this stage it hasnt been added.

Adding Middlewares

Since this package is a wrapper around Express.js it is possible to add middlewares to validate or modify the message on the way in. But this is before the message is parsed so the data is still a Buffer. In future versions the message parsing will be added as a middleware so that the following middlewares will have access to the parsed data.

Example:

import { CloudRunPubsub } from '@minso_minso/cloud-run-pubsub'

const mWare = (req, res, next) => {
	console.log('Time:', Date.now())
	next()
}

const msg = new MessageHandler()
const pubsub = new CloudPubSub({
	middlewares: [mWare],
	port: 5000,
	handleFunc: msg.handleFunc.bind(msg),
})

pubsub.listen()