Skip to content

Commit 0bd5868

Browse files
Deploy with Heroku button support
1 parent 404d37e commit 0bd5868

File tree

5 files changed

+77
-4
lines changed

5 files changed

+77
-4
lines changed

LICENSE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Copyright (c) 2017 Ably
2+
3+
Copyright 2016 Ably Real-time Ltd
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.

Procfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
web: node server.js

README.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# [Ably](https://www.ably.io) Ably Reactor Queue and Wolfram Alpha demo
2+
3+
Ably is a hugely scalable, superfast and secure hosted real-time messaging service for web-enabled devices. [Find out more about Ably](https://www.ably.io).
4+
5+
This demo uses realtime pub/sub to publish questions and subscribe to answers, and uses the [Ably Reactor Queues](https://www.ably.io/reactor) to subscribe to realtime data from a worker server over AMQP. When the worker receives a question, it sends the request to Wolfram Alpha to get the answer, and publishes the answer on a channel so that the browser receives it.
6+
7+
Want to try this demo now? Deploy to Heroku for free:
8+
9+
[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/ably/tutorials/tree/queue-wolfram-alpha-nodejs)
10+
11+
# Setting up the demo on Heroku
12+
13+
Once the app has been deployed to Heroku using the button above, there a few quick steps needed to get this demo running:
14+
15+
* [Sign up for a free Developer AppId with Wolfram Alpha](http://developer.wolframalpha.com/)
16+
* Configure an environment variable with the Wolfram AppId (replace `[your wolfram app id]` with the AppId from the previous step): `heroku config:set WOLFRAM_APP_ID=[your wolfram app id] --app [heroku app name you assigned for this demo]`
17+
* Log in to your Ably dashboard `heroku addons:open ably --app [heroku app name you assigned for this demo]`
18+
* Set up a queue (in the Queues tab) with the name `wolfram` in the `US East (Virgina)` area.
19+
* Set up a queue rule (button to add rules is further down the page within the Queues tab) with the following:
20+
* Queue - choose the `wolfram` queue you just set up
21+
* Source - choose "Message"
22+
* Channel Filter - enter `"^wolfram:questions"` to ensure that all questions published to the `wolfram:questions` channel are republished into the `wolfram` queue
23+
24+
You are now ready to run the demo: `heroku open --app [heroku app name you assigned for this demo]`
25+
26+
# Ably Reactor
27+
28+
The Ably Reactor provides Queues to consume realtime data, Events to trigger server-side code or functions in respons to realtime data, and Firehose to stream events to other queue or streaming services.
29+
30+
[Find out more about the Ably Reactor](https://www.ably.io/reactor)
31+
32+
# Questions
33+
34+
Please visit http://support.ably.io/ for access to our knowledgebase and to ask for any assistance.
35+
36+
# License
37+
38+
Copyright (c) 2017 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to [LICENSE](./LICENSE) for the license terms.

app.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "Ably Wolfram Queue demo",
3+
"description": "A simple demo to demonstrate using Ably Reactor Queues with Wolfram Alpha",
4+
"repository": "https://github.com/ably/tutorials/tree/queue-wolfram-alpha-nodejs",
5+
"logo": "https://files.ably.io/logo-70x70.png",
6+
"keywords": ["Ably", "AMQP", "Wolfram Alpha", "realtime"],
7+
"success_url": "https://github.com/ably/tutorials/blob/queue-wolfram-alpha-nodejs/README.md#setting-up-the-demo-on-heroku",
8+
"addons": [
9+
{
10+
"plan": "ably:test"
11+
}
12+
]
13+
}

server.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
const Ably = require('ably');
22
const Express = require('express');
3-
const ServerPort = 3000;
3+
const ServerPort = process.env.PORT || 3000;
44
const worker = require('./worker');
55

66
const ApiKey = 'INSERT-YOUR-API-KEY-HERE'; /* Add your API key here */
77
if (ApiKey.indexOf('INSERT') === 0) { throw('Cannot run without an Ably API key. Add your key to server.js'); }
88

9-
const WolframAppId = 'INSERT-YOUR-WOLFRAM-API-KEY-HERE'; /* Add your Wolfram AppID here */
10-
if (WolframAppId.indexOf('INSERT') === 0) { throw('Cannot run without a Wolfram API key. Add your key to server.js'); }
9+
const WolframAppId = process.env.WOLFRAM_APP_ID || 'INSERT-YOUR-WOLFRAM-APP-ID-HERE'; /* Add your Wolfram AppID here */
10+
if (WolframAppId.indexOf('INSERT') === 0) { console.warn('Cannot run without a Wolfram AppID. Add your AppID to server.js'); }
1111

1212
/* Instance the Ably library */
1313
const rest = new Ably.Rest({ key: ApiKey });
@@ -27,9 +27,15 @@ app.get('/auth', function (req, res) {
2727
});
2828
});
2929

30+
if (WolframAppId.indexOf('INSERT') === 0) {
31+
app.get('/', function (req, res) {
32+
res.status(500).send('WolframAppId is not set. You need to configure an environment variable WOLFRAM_APP_ID');
33+
});
34+
}
35+
3036
/* Server static HTML files from /public folder */
3137
app.use(Express.static('public'));
32-
app.listen(3000);
38+
app.listen(ServerPort);
3339

3440
worker.start(ApiKey, WolframAppId, 'wolfram:answers', 'wolfram', 'us-east-1-a-queue.ably.io:5671/shared');
3541

0 commit comments

Comments
 (0)