oakpubsub
v0.7.0
Published
gcloud-node google pubsub functional wrapper using bluebird promises
Downloads
22
Maintainers
Readme
oakpubsub
A partial gcloud-node (google cloud) pubsub wrapper with bluebird promises, in functional style. Only does minimally what we need, no guarantees expressed or implied. Pull Requests for expanded functions/features are welcome.
See tests for usage.
Use care when doing mass deletes of topics or subscriptions, an incorrect regular expression could destroy data. It would be nice if google pubsub supported namespaces to avoid potential clobbering.
Tested with node v4 LTS
API Reference
oakpubsub module.
- oakpubsub
- .getPubsub(options) ⇒ Object
- .createTopic_P(pubsub, topic_title) ⇒ Promise
- .getTopic(pubsub, topic_title, [options]) ⇒ Object
- .getOrCreateTopic_P(pubsub, topic_title, [options]) ⇒ Promise
- .getSubscription(topic, subscription_id, [options]) ⇒ Object
- .createSubscription_P(topic, subscription_id, [options]) ⇒ Promise
- .publish_P(topic, messages) ⇒ Promise
- .deleteTopic_P(topic) ⇒ Promise
- .deleteSubscription_P(subscription) ⇒ Promise
- .ack_P(subscription, acknowledge) ⇒ Promise
- .pull_P(subscription, [options]) ⇒ Promise
- .makeMessage(data, [attributes]) ⇒ Object
- .pluckAcks(message) ⇒ Array.<string>
- .resetMessages(messages) ⇒ Array.<Object>
- .resetMessage(message) ⇒ Object
- .processTopics_P(pubsub, worker_P, [query_options]) ⇒ Promise
- .processSubs_P(pubsub, worker_P, [query_options]) ⇒ Promise
- .deleteTopicsMatching_P(pubsub, regex, [page_size], [concurrency]) ⇒ Promise
- .deleteSubsMatching_P(pubsub, regex, [page_size], [concurrency]) ⇒ Promise
oakpubsub.getPubsub(options) ⇒ Object
Get a pubsub object, for use in subsequent module function calls
Kind: static method of oakpubsub
Returns: Object - an authenticated pubsub object from gcloud-node
| Param | Type | Description | | --- | --- | --- | | options | Object | passed directly to gcloud-node for i.e. authentication |
oakpubsub.createTopic_P(pubsub, topic_title) ⇒ Promise
Remote call to create a google pubsub topic
Kind: static method of oakpubsub
Returns: Promise - resolving to topic returned by gcloud-node pubsub#createTopic()
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | topic_title | string | the name of the topic |
oakpubsub.getTopic(pubsub, topic_title, [options]) ⇒ Object
Get a pubsub topic, for use in subsequent module function calls
Kind: static method of oakpubsub
Returns: Object - topic returned by gcloud-node pubsub#topic()
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | topic_title | string | the name of the topic | | [options] | Object | additional gcloud-node options |
oakpubsub.getOrCreateTopic_P(pubsub, topic_title, [options]) ⇒ Promise
Remote call to get or create a topic
Kind: static method of oakpubsub
Returns: Promise - resolving to the topic returned by gcloud-node pubsub#createTopic()
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | topic_title | string | the name of the topic | | [options] | Object | additional gcloud-node options |
oakpubsub.getSubscription(topic, subscription_id, [options]) ⇒ Object
Gets a subscription
Kind: static method of oakpubsub
Returns: Object - returns a subscription from gcloud-node topic#subscription()
| Param | Type | Description | | --- | --- | --- | | topic | Object | gcloud-node topic object | | subscription_id | string | the name of the subscription | | [options] | Object | gcloud-node subscription options: autoAck, interval |
oakpubsub.createSubscription_P(topic, subscription_id, [options]) ⇒ Promise
Remote call to create a subscription
Kind: static method of oakpubsub
Returns: Promise - resolving to subscription returned by gcloud-node topic#subscribe()
| Param | Type | Description | | --- | --- | --- | | topic | Object | gcloud-node topic object | | subscription_id | string | the name of the subscription | | [options] | Object | gcloud-node subscribe options: ackDeadlineSeconds, autoAck, interval, maxInProgress, reuseExisting, timeout |
oakpubsub.publish_P(topic, messages) ⇒ Promise
Remote call to publish a message
Kind: static method of oakpubsub
Returns: Promise - resolving to array of message ids returned by gcloud-node topic#publish()
| Param | Type | Description | | --- | --- | --- | | topic | Object | gcloud-node topic object | | messages | Object | Array.<Object> | the message(s) to pass to gcloude-node topic#publish() |
oakpubsub.deleteTopic_P(topic) ⇒ Promise
Remote call to delete a topic
Kind: static method of oakpubsub
Returns: Promise - resolving to apiResponse returned by gcloud-node topic#delete()
| Param | Type | Description | | --- | --- | --- | | topic | Object | gcloud-node topic object |
oakpubsub.deleteSubscription_P(subscription) ⇒ Promise
Remote call to delete a subscription
Kind: static method of oakpubsub
Returns: Promise - resolving to apiResponse returned by gcloud-node subscription#delete()
| Param | Type | Description | | --- | --- | --- | | subscription | Object | gcloud-node subscription object |
oakpubsub.ack_P(subscription, acknowledge) ⇒ Promise
Remote call to acknowledge completion of message processing
Kind: static method of oakpubsub
Returns: Promise - resolving to apiResponse returned by gcloud-node subscription#ack()
| Param | Type | Description | | --- | --- | --- | | subscription | Object | gcloud-node subscription object | | acknowledge | string | Array.<string> | IDs |
oakpubsub.pull_P(subscription, [options]) ⇒ Promise
Remote call to pull messages from server
Kind: static method of oakpubsub
Returns: Promise - resolving to array of messages returned by gcloud-node subscription#pull()
| Param | Type | Description | | --- | --- | --- | | subscription | Object | gcloud-node subscription object | | [options] | Object | additional gcloud-node options for subscription#pull(): maxResults, returnImmediately |
oakpubsub.makeMessage(data, [attributes]) ⇒ Object
Utility to create a message object
Kind: static method of oakpubsub
Returns: Object - message object that can be used in publish_P()
| Param | Type | Description | | --- | --- | --- | | data | string | number | array | Object | to publish (gcloud-node will JSON encode/decode for you) | | [attributes] | Object | additional key-value attributes attached to the message |
oakpubsub.pluckAcks(message) ⇒ Array.<string>
Utility to pluck ackIds from messages
Kind: static method of oakpubsub
Returns: Array.<string> - array of ackIds, can be passed to ack_P()
| Param | Type | Description | | --- | --- | --- | | message | Object | Array.<Object> | or messages returned by pull_P() |
oakpubsub.resetMessages(messages) ⇒ Array.<Object>
Utility to create an array of message objects from previously pulled messages, useful for pubsub message passing
Kind: static method of oakpubsub
Returns: Array.<Object> - messages that can be used in publish_P()
| Param | Type | Description | | --- | --- | --- | | messages | Array.<Object> | returned by pull_P() |
oakpubsub.resetMessage(message) ⇒ Object
Utility to create a publishable message object from a previously pulled message
Kind: static method of oakpubsub
Returns: Object - message object that can be used in publish_P()
| Param | Type | Description | | --- | --- | --- | | message | Object | returned by pull_P() |
oakpubsub.processTopics_P(pubsub, worker_P, [query_options]) ⇒ Promise
Helper to get multiple pubsub topics and process them asynchronously
Kind: static method of oakpubsub
Returns: Promise - resolving to the final apiResponse
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | worker_P | Promise | function | a function or promise processing each array of topics | | [query_options] | Object | additional gcloud-node pubsub query options for pubsub.getTopics() |
oakpubsub.processSubs_P(pubsub, worker_P, [query_options]) ⇒ Promise
Helper to get multiple pubsub subscriptions and process them asynchronously
Kind: static method of oakpubsub
Returns: Promise - resolving to the final apiResponse
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | worker_P | Promise | function | a function or promise processing each array of subscriptions | | [query_options] | Object | additional gcloud-node pubsub query options for pubsub.getSubscriptions() |
oakpubsub.deleteTopicsMatching_P(pubsub, regex, [page_size], [concurrency]) ⇒ Promise
Helper to get delete pubsub topics matching a regular expression, using processTopics_P and deleteTopic_P
Kind: static method of oakpubsub
Returns: Promise - resolving to the final apiResponse
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | regex | string | javascript regular expression in string format, e.g. '^match_me' | | [page_size] | integer | number of topics to fetch per response (default: 100) | | [concurrency] | integer | max number of topics to delete simultaneously (default: 5) |
oakpubsub.deleteSubsMatching_P(pubsub, regex, [page_size], [concurrency]) ⇒ Promise
Helper to get delete pubsub subscriptions matching a regular expression, using processSubs_P and deleteSubscription_P
Kind: static method of oakpubsub
Returns: Promise - resolving to the final apiResponse
| Param | Type | Description | | --- | --- | --- | | pubsub | Object | gcloud-node pubsub object | | regex | string | javascript regular expression matching subscription name in string format, e.g. '^match_me' | | [page_size] | integer | number of subscriptions to fetch per response (default: 100) | | [concurrency] | integer | max number of subscriptions to delete simultaneously (default: 5) |
Update Docs
doc/generate
Development
Transpile with gulp or, if using the atom editor, the atom babel package.
Test
npm test
or
npm run testwatch
or
npm test -- watch