Skip to content

Commit

Permalink
Deploy with Heroku button support
Browse files Browse the repository at this point in the history
  • Loading branch information
mattheworiordan committed Jan 26, 2017
1 parent 436cb4a commit c7e8174
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 5 deletions.
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
Copyright (c) 2017 Ably

Copyright 2016 Ably Real-time Ltd

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
1 change: 1 addition & 0 deletions Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: node example.js
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# [Ably](https://www.ably.io) Ably Reactor Queue and Wolfram Alpha demo

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).

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.

Want to try this demo now? Deploy to Heroku for free:

[![Deploy](https://www.herokucdn.com/deploy/button.svg)](https://heroku.com/deploy?template=https://github.com/ably/tutorials/tree/queue-wolfram-alpha-nodejs)

# Setting up the demo on Heroku

Once the app has been deployed to Heroku using the button above, there a few quick steps needed to get this demo running:

* [Sign up for a free Developer AppId with Wolfram Alpha](http://developer.wolframalpha.com/)
* 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]`
* Log in to your Ably dashboard `heroku addons:open ably --app [heroku app name you assigned for this demo]`
* Set up a queue (in the Queues tab) with the name `default` in the `US East (Virgina)` area.
* Set up a queue rule (button to add rules is further down the page within the Queues tab) with the following:
* Queue - choose the `default` queue you just set up
* Source - choose "Message"
* Channel Filter - enter `"^wolfram:questions"` to ensure that all questions published to the `wolfram:questions` channel are republished into the `default` queue

You are now ready to run the demo: `heroku open --app [heroku app name you assigned for this demo]`

# Ably Reactor

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.

[Find out more about the Ably Reactor](https://www.ably.io/reactor)

# Questions

Please visit http://support.ably.io/ for access to our knowledgebase and to ask for any assistance.

# License

Copyright (c) 2017 Ably Real-time Ltd, Licensed under the Apache License, Version 2.0. Refer to [LICENSE](./LICENSE) for the license terms.
13 changes: 13 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "Ably Wolfram Queue demo",
"description": "A simple demo to demonstrate using Ably Reactor Queues with Wolfram Alpha",
"repository": "https://github.com/ably/tutorials/tree/queue-wolfram-alpha-nodejs",
"logo": "https://files.ably.io/logo-70x70.png",
"keywords": ["Ably", "AMQP", "Wolfram Alpha", "realtime"],
"success_url": "https://github.com/ably/tutorials/blob/queue-wolfram-alpha-nodejs/README.md#setting-up-the-demo-on-heroku",
"addons": [
{
"plan": "ably:test"
}
]
}
16 changes: 11 additions & 5 deletions example.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
const Ably = require('ably');
const Express = require('express');
const ServerPort = 3000;
const ServerPort = process.env.PORT || 3000;
const worker = require('./worker');

const ApiKey = 'INSERT-YOUR-API-KEY-HERE'; /* Add your Ably API key here */
const ApiKey = process.env.ABLY_API_KEY || 'INSERT-YOUR-API-KEY-HERE'; /* Add your Ably API key here */
if (ApiKey.indexOf('INSERT') === 0) { throw('Cannot run without an Ably API key. Add your key to example.js'); }

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

/* Instance the Ably library */
var rest = new Ably.Rest({ key: ApiKey });
Expand All @@ -29,8 +29,14 @@ app.get('/auth', function (req, res) {
});

/* Server static HTML files from /public folder */
if (WolframAppId.indexOf('INSERT') === 0) {
app.get('/', function (req, res) {
res.status(500).send('WolframAppId is not set. You need to configure an environment variable WOLFRAM_APP_ID');
});
}

app.use(express.static('public'));
app.listen(3000);
app.listen(ServerPort);

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

Expand Down

0 comments on commit c7e8174

Please sign in to comment.