simpler-pubsub
v0.0.1
Published
Use GCP's PubSub with Protocol Buffers
Downloads
5
Maintainers
Readme
simple-pubsub
Simplifies publishing and subscribing to the GCP's PubSub. A topic you publish or subscribe to must be already created - an Error will be thrown otherwise. Read more about this design decision here.
How to use it
First, create a PubSub
instance and wrap it in a PubSubMessenger
instance:
const PubSub = require('@google-cloud/pubsub');
const messenger = new PubSubMessenger(new PubSub());
Use the messenger
to either publish
:
const buffer = Buffer.from("Hello, World!");
messenger.using("my-awesome-topic").publish(buffer);
or subscribe
:
let listener = {
onReceived: (message) => {
message.ack();
console.log(message);
},
onError: (err) => {
console.error(err);
}
};
messenger.using("my-awesome-topic").subscribe("my-subscription", listener);
If my-subscription
doesn't exists, it will be created.
License
Copyright (c) 2018, Tadej Slamic
Permission to use, copy, modify, and/or distribute this software for any purpose
with or without fee is hereby granted, provided that the above copyright notice
and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.