Skip to content

Commit a8a1831

Browse files
Merge pull request #259 from ryanseys/pubsub-readme
Add pubsub to README
2 parents b3b4472 + 9ad01f2 commit a8a1831

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

README.md

+48
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ This client supports the following Google Cloud Platform services:
1212

1313
* [Google Cloud Datastore](https://cloud.google.com/products/cloud-datastore/)
1414
* [Google Cloud Storage](https://cloud.google.com/products/cloud-storage/)
15+
* [Google Cloud Pub/Sub][cloud-pubsub] (Developer Preview)
1516

1617
If you need support for other Google APIs, check out the [Google Node.js API Client library][googleapis].
1718

@@ -101,6 +102,50 @@ bucket.write('demo.txt', 'Hello World', function(err) {
101102
});
102103
```
103104

105+
## Google Cloud Pub/Sub (Alpha)
106+
107+
> Google Cloud Pub/Sub is in **Alpha status**. As a result, it might change in backward-incompatible ways and is not recommended for production use. It is not subject to any SLA or deprecation policy.
108+
109+
[Google Cloud Pub/Sub][cloud-pubsub] allows you to connect your services with reliable, many-to-many, asynchronous messaging hosted on Google's infrastructure. Cloud Pub/Sub automatically scales as you need it and provides a foundation for building your own robust, global services.
110+
111+
See [the gcloud-node API documentation][gcloud-pubsub] to learn how to connect to the Cloud Pub/Sub using this Client Library.
112+
113+
``` js
114+
var gcloud = require('gcloud');
115+
116+
// From Google Compute Engine:
117+
var pubsub = gcloud.pubsub();
118+
119+
// Or from elsewhere:
120+
var pubsub = gcloud.pubsub({
121+
keyFilename: '/path/to/keyfile.json',
122+
projectId: 'my-project'
123+
});
124+
125+
// Create a new topic.
126+
pubsub.createTopic('my-new-topic', function(err, topic) {
127+
// Subscribe to the topic.
128+
topic.subscribe('new-subscription', function(err, subscription) {
129+
// Create listeners to start listening for messages.
130+
function onError(err) {}
131+
function onMessage(message) {}
132+
subscription.on('error', onError);
133+
subscription.on('message', onMessage);
134+
135+
// Publish a message to the topic.
136+
topic.publish('New message!', function(err) {});
137+
138+
// Clean up listeners.
139+
subscription.removeListener('message', onMessage);
140+
subscription.removeListener('error', onError);
141+
});
142+
});
143+
144+
// Or reference an existing topic.
145+
var topic = pubsub.topic('my-existing-topic');
146+
// etc...
147+
```
148+
104149
## Contributing
105150

106151
Contributions to this library are always welcome and highly encouraged.
@@ -113,3 +158,6 @@ Apache 2.0 - See [COPYING](COPYING) for more information.
113158

114159
[googleapis]: https://github.com/google/google-api-nodejs-client
115160
[gcloud-todos]: https://github.com/GoogleCloudPlatform/gcloud-node-todos
161+
[cloud-pubsub]: https://cloud.google.com/pubsub/
162+
[pubsub-preview]: https://docs.google.com/a/google.com/forms/d/1IQY4LAbISLa86uxRv2dKAzkeWOyNZda_tUn7xgVYeoE/viewform
163+
[gcloud-pubsub]: https://googlecloudplatform.github.io/gcloud-node/#/docs/pubsub

0 commit comments

Comments
 (0)