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.
Connect your app to an existing Diffusion Cloud service
Add a new Diffusion Cloud service and connect your app to it
Connect your Diffusion Cloud service to an existing app
Connecting Diffusion Cloud to a Node.js 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); }); });