Skip to content

Commit bb748f5

Browse files
initial commit
0 parents  commit bb748f5

20 files changed

+537
-0
lines changed

.editorconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# editorconfig.org
2+
root = true
3+
4+
[*]
5+
indent_style = space
6+
indent_size = 2
7+
end_of_line = lf
8+
charset = utf-8
9+
trim_trailing_whitespace = true
10+
insert_final_newline = true
11+
12+
[*.md]
13+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"extends": "google",
3+
"env": {
4+
"node": true,
5+
"es6": true
6+
},
7+
"rules": {
8+
"max-len": ["error", {
9+
"ignoreComments": true,
10+
"ignoreUrls": true,
11+
"ignoreStrings": true,
12+
"ignoreRegExpLiterals": true
13+
}]
14+
}
15+
}

.gitignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
.grunt
29+
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
32+
33+
# node-waf configuration
34+
.lock-wscript
35+
36+
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
build/Release
38+
39+
# Dependency directories
40+
node_modules/
41+
jspm_packages/
42+
43+
# Typescript v1 declaration files
44+
typings/
45+
46+
# Optional npm cache directory
47+
.npm
48+
49+
# Optional eslint cache
50+
.eslintcache
51+
52+
# Optional REPL history
53+
.node_repl_history
54+
55+
# Output of 'npm pack'
56+
*.tgz
57+
58+
# Yarn Integrity file
59+
.yarn-integrity
60+
61+
# dotenv environment variables file
62+
.env
63+
64+
65+
# End of https://www.gitignore.io/api/node
66+
67+
.idea
68+
lib

.npmignore

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
2+
# Created by https://www.gitignore.io/api/node
3+
4+
### Node ###
5+
# Logs
6+
logs
7+
*.log
8+
npm-debug.log*
9+
yarn-debug.log*
10+
yarn-error.log*
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
24+
# nyc test coverage
25+
.nyc_output
26+
27+
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
28+
.grunt
29+
30+
# Bower dependency directory (https://bower.io/)
31+
bower_components
32+
33+
# node-waf configuration
34+
.lock-wscript
35+
36+
# Compiled binary addons (http://nodejs.org/api/addons.html)
37+
build/Release
38+
39+
# Dependency directories
40+
node_modules/
41+
jspm_packages/
42+
43+
# Typescript v1 declaration files
44+
typings/
45+
46+
# Optional npm cache directory
47+
.npm
48+
49+
# Optional eslint cache
50+
.eslintcache
51+
52+
# Optional REPL history
53+
.node_repl_history
54+
55+
# Output of 'npm pack'
56+
*.tgz
57+
58+
# Yarn Integrity file
59+
.yarn-integrity
60+
61+
# dotenv environment variables file
62+
.env
63+
64+
65+
# End of https://www.gitignore.io/api/node
66+
67+
.idea
68+
src

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
language: node_js
2+
3+
node_js:
4+
- "node"
5+
- "7"
6+
- "6"
7+
- "5"
8+
- "4"

Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
FROM node:7.9.0
2+
MAINTAINER Superbalist <tech+docker@superbalist.com>
3+
4+
RUN mkdir -p /usr/src/app
5+
WORKDIR /usr/src/app
6+
7+
COPY package.json /usr/src/app/
8+
RUN npm install
9+
10+
COPY src /usr/src/app/src/
11+
COPY examples /usr/src/app/examples/
12+
13+
RUN npm run build
14+
15+
CMD ["/bin/bash"]

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2017 Superbalist.com a division of Takealot Online (Pty) Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
up:
2+
@docker-compose rm -f
3+
@docker-compose pull
4+
@sed -e "s/HOSTIP/$$(docker-machine ip)/g" docker-compose.yml | docker-compose --file - up --build -d
5+
@docker-compose run js-pubsub-http /bin/bash
6+
7+
down:
8+
@docker-compose stop -t 1

README.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
# @superbalist/js-pubsub-http
2+
3+
An HTTP adapter for the [js-pubsub](https://github.com/Superbalist/js-pubsub) package.
4+
5+
[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist)
6+
[![Build Status](https://img.shields.io/travis/Superbalist/js-pubsub-http/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/js-pubsub-http)
7+
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE)
8+
[![NPM Version](https://img.shields.io/npm/v/@superbalist/js-pubsub-http.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-http)
9+
[![NPM Downloads](https://img.shields.io/npm/dt/@superbalist/js-pubsub-http.svg)](https://www.npmjs.com/package/@superbalist/js-pubsub-http)
10+
11+
This adapter assumes that you have a HTTP service which accepts an array of messages POSTed to a
12+
/messages/(channel) end-point.
13+
14+
## Installation
15+
16+
```bash
17+
npm install @superbalist/js-pubsub-http
18+
```
19+
20+
## Usage
21+
```node
22+
'use strict';
23+
24+
let pubsub = require('@google-cloud/pubsub');
25+
let GoogleCloudPubSubAdapter = require('@superbalist/js-pubsub-google-cloud');
26+
let HTTPPubSubAdapter = require('@superbalist/js-pubsub-http');
27+
28+
process.env.GOOGLE_APPLICATION_CREDENTIALS = '/path/to/your-gcloud-key.json';
29+
30+
// create the underlying adapter which is going to be decorated
31+
let client = pubsub({
32+
projectId: 'your-project-id-here',
33+
});
34+
35+
let googleCloudAdapter = new GoogleCloudPubSubAdapter(client);
36+
37+
// now create our decorator
38+
// the decorator will proxy subscribe calls straight to the googleCloudAdapter
39+
// publish calls will be POSTed to the service uri
40+
let adapter = new HTTPPubSubAdapter('http://127.0.0.1', googleCloudAdapter);
41+
42+
adapter.subscribe('my_channel', (message) => {
43+
console.log(message);
44+
console.log(typeof message);
45+
});
46+
47+
// consume messages
48+
// note: this is a blocking call
49+
adapter.subscribe('my_channel', (message) => {
50+
console.log(message);
51+
console.log(typeof message);
52+
});
53+
54+
// publish messages
55+
adapter.publish('my_channel', {first_name: 'Matthew'});
56+
adapter.publish('my_channel', 'Hello World');
57+
58+
// publish multiple messages
59+
let messages = [
60+
'message 1',
61+
'message 2',
62+
];
63+
adapter.publishBatch('my_channel', messages);
64+
```
65+
66+
## TODO
67+
68+
* Add unit tests
69+
70+
## Examples
71+
72+
The library comes with [examples](examples) for the adapter and a [Dockerfile](Dockerfile) for
73+
running the example scripts.
74+
75+
Run `make up`.
76+
77+
You will start at a `bash` prompt in the `/usr/src/app` directory.
78+
79+
If you need another shell to publish a message to a blocking consumer, you can run `docker-compose run js-pubsub-http /bin/bash`
80+
81+
To run the examples:
82+
```bash
83+
$ ./run_consumer.sh
84+
$ ./run_publisher.sh (in a separate shell)
85+
```

changelog.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Changelog
2+
3+
## 1.0.0 - 2017-05-23
4+
5+
* Initial release

0 commit comments

Comments
 (0)