ibm-messaging / event-streams-samples

Apache License 2.0
95 stars 168 forks source link

App fails to start when using cups service #37

Closed hlarubi closed 6 years ago

hlarubi commented 6 years ago

Hi,

I'm trying to use a cf cups command to link to a public MH service from a private environment to test out the sample code and connectivity. Unfortunately, the app fails to start as it can't find the messagehub service from a "user-provided" service type. The error is in the npm package called message-hub-rest. Could you please take a look?

Thanks!

2018-09-11T23:49:39.93-0700 [CELL/0] OUT Creating container 2018-09-11T23:49:40.50-0700 [CELL/0] OUT Successfully created container 2018-09-11T23:49:45.33-0700 [APP/PROC/WEB/0] OUT > message-hub-nodejs-console-sample@3.0.0 start /home/vcap/app 2018-09-11T23:49:45.33-0700 [APP/PROC/WEB/0] OUT > node ./app.js 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR /home/vcap/app/node_modules/message-hub-rest/lib/messagehub.js:76 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR throw new Error(serviceNamePrefix + ' is not provided in the services environment variable. ' + 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at new Client (/home/vcap/app/node_modules/message-hub-rest/lib/messagehub.js:76:13) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Object.Module._extensions..js (module.js:663:10) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Object. (/home/vcap/app/app.js:50:29) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Module.load (module.js:565:32) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at tryModuleLoad (module.js:505:12) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at bootstrap_node.js:612:3 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR ^ 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Module._compile (module.js:652:30) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] OUT Using VCAP_SERVICES to find credentials. 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR Error: messagehub is not provided in the services environment variable. Make sure you have bound the Message Hub service to your Bluemix application 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Function.Module._load (module.js:497:3) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at Function.Module.runMain (module.js:693:10) 2018-09-11T23:49:45.48-0700 [APP/PROC/WEB/0] ERR at startup (bootstrap_node.js:191:16) 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! code ELIFECYCLE 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! errno 1 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! message-hub-nodejs-console-sample@3.0.0 start: node ./app.js 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! Exit status 1 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! This is probably not a problem with npm. There is likely additional logging output above. 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! 2018-09-11T23:49:45.50-0700 [APP/PROC/WEB/0] ERR npm ERR! Failed at the message-hub-nodejs-console-sample@3.0.0 start script. 2018-09-11T23:49:45.66-0700 [APP/PROC/WEB/0] ERR npm ERR! /home/vcap/app/.npm/_logs/2018-09-12T06_49_45_507Z-debug.log 2018-09-11T23:49:45.66-0700 [APP/PROC/WEB/0] ERR npm ERR! A complete log of this run can be found in: 2018-09-11T23:49:45.71-0700 [CELL/0] OUT Stopping instance 67d705a8-bf01-44e6-6683-7dfa

edoardocomar commented 6 years ago

The stack trace shows that parsing the VCAP_SERVICES env var fails. It must be simply the case that its structure for your app using a CUPS differs from the ordinary case.

You should simply edit the app.js code to suit your environment. Try modify these lines https://github.com/ibm-messaging/message-hub-samples/blob/master/kafka-nodejs-console-sample/app.js#L38-L50 to extract the info from your specific VCAP_SERVICES and get the 3 values and assign them to the objects used by the demo app. e.g.

opts.brokers = your_list_of_brokers_from_your_vcap
opts.api_key = your_api_key_from_your_vcap
adminRestInstance = new MessageHubAdminRest(wrap_vcap_service(your_api_key_from_your_vcap, your_admin_url_from_your_vcap))