-
Notifications
You must be signed in to change notification settings - Fork 33
Connecting to Micro Cloud Foundry NATS Server
To connect to a Micro Cloud Foundry, you first need to download, install, and setup a Micro Cloud Foundry VM.
-
When setting up the VM, be sure to remember the password you enter. If you don't, you can change the password in the VM console using option
3. reconfigure vcap password
. -
You need to configure the NATS server on the VM to accept connections from more than just the loopback interface. To do this, you need to login as the 'vcap' user using the password from step 1. You can login using ssh or you can switch to a virtual console within the VM. I can do this on my workstation by pushing Windows Button+F2. At the virtual console login using the user 'vcap' and use the password from step 1.
-
Once you are logged in as the 'vcap' user, open the file
/var/vcap/jobs/micro/nats/config/nats.yml
using an editor such as vi. Change thenet:
property from127.0.0.1
to0.0.0.0
. -
While you have the
nats.yml
file open, be sure to copy the password. On my VM, the password is "4d100351123b0a78". I'm not sure if it changes when the VM gets setup or not. -
Now reboot your VM.
You should be able to connect to the NATS server on your VM once your VM has successfully rebooted. You can do this with the Java NATS client by doing something like the following:
import nats.client.Message;
import nats.client.Nats;
import nats.client.NatsConnector;
public class SimpleClient {
public static void main(String[] args) {
final String natsPassword = "4d100351123b0a78";
final String vmIpAddress = "172.16.149.128";
Nats nats = new NatsConnector().addHost("nats://nats:4d100351123b0a78@" + vmIpAddress).connect();
for (Message message : nats.subscribe(">")) {
System.out.println(message.getSubject() + "\t" + message.getBody());
}
}
}
Be sure to change natsPassword
to the password from you nats.yml
file in step 4 and change vmIpAddress
to the IP address of your VM.
When you run this, the client will subscribe to all the Cloud Foundry messages getting sent over NATS. You should see something like the following in your console:
MongoaaS.announce {"available_memory":256,"id":"mongodb_node_1"}
RaaS.announce {"available_memory":256,"id":"redis_node_1"}
AuaaS.announce {"available_storage":2147483648,"id":"postgresql_node_1"}
vcap.cc.events ["2012-10-25T05:54:41+00:00","USER","N/A","POST:/services/v1/offerings","SUCCEEDED"]
vcap.cc.events ["2012-10-25T05:54:52+00:00","USER","N/A","POST:/services/v1/offerings","SUCCEEDED"]
router.start {"id":"2d6a9323e4f06b0d4e48c791e5118085","version":0.98}
router.register {"host":"127.0.0.1","port":9022,"uris":["api.mikeheath.cloudfoundry.me"],"tags":{"component":"CloudController"}}
vcap.cc.events ["2012-10-25T05:54:55+00:00","USER","N/A","POST:/services/v1/offerings","SUCCEEDED"]
If you deploy an application, you will see all the messages Cloud Foundry uses to deploy the application.