Just a second...

Connections on IBM Bluemix

Connect your Diffusion™ Cloud service to an app to provide seamless integration of Diffusion Cloud with the application code, without the need to hard code connection or credentials information. Bluemix handles integration with the Diffusion Cloud service, so you can focus on building outstanding web and mobile apps.

When you create a connection between your app and a Diffusion Cloud service, Diffusion Cloud generates all the data that you require to connect your app to Diffusion Cloud. This information is made available to your app in JSON format through the environment variable VCAP_SERVICES:
{
  "push-reappt": [
    {
      "name": "service_name",
      "label": "push-reappt",
      "plan": "diffusion_cloud_edition",
      "credentials": {
        "host": "host_name",
        "principal": "principal",
        "credentials": "password"
      }
    }
  ]
}
name
The name assigned to this instance of the Diffusion Cloud service in Bluemix.
plan
The edition of your Diffusion Cloud service.

For more information about the available editions of Diffusion Cloud, see https://www.pushtechnology.com/pricing/.

host_name
The host name to use when connecting client applications to your Diffusion Cloud service.
principal
The security principal to use when connecting to your Diffusion Cloud service. This principal is automatically generated when the binding is created.
Note: Do not delete this principal from the Diffusion Cloud system authentication store.

By default, this principal is assigned the following roles: CLIENT, CLIENT_CONTROL, and TOPIC_CONTROL. You can use the Diffusion Cloud Dashboard to change the roles assigned to this principal.

credentials
The password associated with the principal.
Note: Do not change the password in the Diffusion Cloud system authentication store.
There are a number of ways you can create a connection between an app and a Diffusion Cloud service.

Connect your app to an existing Diffusion Cloud service

If you already have a Diffusion Cloud service and an app in your space, you can create a connection between the two from the app.
  1. Click on the app to go to the app Overview page.
  2. Click the Connect existing button in the Connections panel of the Overview page.
    The Connections panel.
    You are redirected to a list of existing services.
  3. Select your Diffusion Cloud service from the list and click Connect.
    A list of services available to connect to.
    Bluemix prompts you to restage your app.
  4. On the Restage App dialog, click Restage
    The restage dialog.
The connected Diffusion Cloud service is shown on the connections tab:
A list of connected services.

Add a new Diffusion Cloud service and connect your app to it

From your app you can add a Diffusion Cloud service and create a connection to it at the same time.
  1. Click on the app to go to the app Overview page.
  2. Click the Connect new button in the Connections panel of the Overview page.
    The Connections panel.
    You are redirected to the Bluemix® catalog.
  3. Search for Diffusion Cloud in the catalog and click the Diffusion Cloud icon.
    Diffusion Cloud in the Bluemix catalog.
  4. Select the edition of Diffusion Cloud you need and click Create
    The Connect to field is pre-filled with your app name.
    The Connect to field is already completed with the name of your app.
    Bluemix prompts you to restage your app.
  5. On the Restage App dialog, click Restage
    The restage dialog.
The connected Diffusion Cloud service is shown on the connections tab:
A list of connected services.
On rare occasions the Diffusion Cloud service does not provision in time for a binding to be created. In this case, go to the app overview and bind the Diffusion Cloud service from there.

Connect your Diffusion Cloud service to an existing app

If you already have a Diffusion Cloud service and an app in your space, you can create a connection between the two from the Diffusion Cloud service management pages.
  1. Go to the Connections tab for your Diffusion Cloud service.
    Diffusion Cloud connections tab.
  2. Click the Create connection button.
    Create connection button.
  3. From the list of apps available for connection, select your app and click Connect.
    A list of apps to connect to.
    Bluemix prompts you to restage your app.
  4. On the Restage App dialog, click Restage
    The restage dialog.
The connected app is shown on the connections tab:
A list of connected services.
On rare occasions the Diffusion Cloud service does not provision in time for a binding to be created. In this case, go to the app overview and bind the Diffusion Cloud service from there.

Connecting Diffusion Cloud to a Node.js app

If your Bluemix app is a web app that uses SDK for Node.js, this example shows how to connect a Diffusion Cloud service to your app.
  1. Create your SDK for Node.js app.
    SDK for Node.js in the Bluemix catalog.
    SDK for Node.js is available in the IBM Bluemix catalog: https://console.ng.bluemix.net/catalog/starters/sdk-for-nodejs/
  2. Create and connect a Diffusion Cloud service to your app.
  3. In the app pages, select Start Coding from the left sidebar.
    The Start Coding page contains instructions to get started coding your app using one of a number of tools.
  4. Use your preferred method to get the starter code for your app.
  5. Edit the package.json file to include the diffusion client library as a dependency.
    "dependencies": {
            "express": "4.13.x",
            "cfenv": "1.0.x",
            "diffusion": "5.9.23"
    	},
  6. Edit the app.js file to integrate your connected Diffusion Cloud service with the Node.js app.
    The full example app.js file is provided after the steps.
    1. Import the diffusion client by using require.
      var diffusion = require('diffusion');
    2. Parse the environment variable that contains the information about your Diffusion Cloud service.
      var vcap_services = {};
      try {
          vcap_services = JSON.parse(process.env.VCAP_SERVICES);
      }
      catch (e) {
          console.log('Unable to parse VCAP_SERVICES. Is a binding present?');
          process.exit(1);
      }
    3. Inside the app.listen method, get the Diffusion Cloud connection options from vcap_services.
      var options = vcap_services['push-reappt'][0].credentials;
    4. Inside the app.listen method, connect to Diffusion Cloud with the options.
      diffusion.connect(options).then(function(session) {
          console.log("Connected to Diffusion!");
        }, function(error) {
          console.log(error);
        });
  7. Upload your updated app.js file to your app by using your preferred method.
When you start your Node.js app, it connects to your Diffusion Cloud service and prints a message to the console on the Logs page of the app.
/*eslint-env node*/

//------------------------------------------------------------------------------
// node.js starter application for Bluemix
//------------------------------------------------------------------------------

// This application uses express as its web server
// for more info, see: http://expressjs.com
var express = require('express');

// cfenv provides access to your Cloud Foundry environment
// for more info, see: https://www.npmjs.com/package/cfenv
var cfenv = require('cfenv');

// Import the diffusion client
var diffusion = require('diffusion');

// Parse the environment vars
var vcap_services = {};
try {
    vcap_services = JSON.parse(process.env.VCAP_SERVICES);
}
catch (e) {
    // If we can't get the VCAP_SERVICES env var, we can't access the binding.
    console.log('Unable to parse VCAP_SERVICES. Is a binding present?');
    process.exit(1);
}

// create a new express server
var app = express();

// serve the files out of ./public as our main files
app.use(express.static(__dirname + '/public'));

// get the app environment from Cloud Foundry
var appEnv = cfenv.getAppEnv();


// start server on the specified port and binding host
app.listen(appEnv.port, '0.0.0.0', function() {
  // print a message when the server starts listening
  console.log("server starting on " + appEnv.url);

  // get the options for the diffusion connection from the environment
  var options = vcap_services['push-reappt'][0].credentials;

  // establish the connection to diffusion
  diffusion.connect(options).then(function(session) {
    console.log("Connected to Diffusion!");
  }, function(error) {
    console.log(error);
  });
});