Skip to content

Commit

Permalink
updating README
Browse files Browse the repository at this point in the history
  • Loading branch information
jquatier committed Jan 20, 2016
1 parent c7a3ae8 commit 86f3e4d
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 14 deletions.
34 changes: 33 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# eureka-js-client
# eureka-js-client
[![npm version](https://badge.fury.io/js/eureka-js-client.svg)](http://badge.fury.io/js/eureka-js-client) [![Build Status](https://api.travis-ci.org/jquatier/eureka-js-client.svg)](https://travis-ci.org/jquatier/eureka-js-client) [![Coverage Status](https://coveralls.io/repos/jquatier/eureka-js-client/badge.svg?branch=master&service=github)](https://coveralls.io/github/jquatier/eureka-js-client?branch=master) [![Dependency Status](https://david-dm.org/jquatier/eureka-js-client.svg)](https://david-dm.org/jquatier/eureka-js-client)

A JavaScript implementation of a client for Eureka (https://github.com/Netflix/eureka), the Netflix OSS service registry.
Expand Down Expand Up @@ -69,6 +69,38 @@ var appInfo = client.getInstancesByAppId('YOURSERVICE');
var appInfo = client.getInstancesByVipAddress('YOURSERVICEVIP');
```

## Configuring for AWS environments

For AWS environments (`dataCenterInfo.name` == `Amazon`) the client has built-in logic to request the AWS metadata that the Eureka
server requires. See [Eureka REST schema](https://github.com/Netflix/eureka/wiki/Eureka-REST-operations) for more information.

```javascript
// example configuration for AWS
var client = new Eureka({
// application instance information
instance: {
app: 'jqservice',
port: 8080,
vipAddress: 'jq.test.something.com',
statusPageUrl: 'http://__HOST__:8080/',
healthCheckUrl: 'http://__HOST__:8077/healthcheck',
dataCenterInfo: {
name: 'Amazon'
}
},
eureka: {
// eureka server host / port / EC2 region
host: '192.168.99.100',
port: 32768
}
});
```

Notes:
* Under this configuration, the instance `hostName` and `ipAddr` will be set to the public host and public IP that the AWS metadata provides.
* For status and healthcheck URLs, you may use the replacement key of `__HOST__` to use the public host.
* Metadata fetching can be disabled by setting `config.eureka.fetchAwsMetadata` to `false` if you want to provide your own metadata in AWS environments.

## Debugging

The library uses [request](https://github.com/request/request) for all service calls, and debugging can be turned on by passing `NODE_DEBUG=request` when you start node. This allows you you double-check the URL being called as well as other request properties.
Expand Down
2 changes: 1 addition & 1 deletion src/default-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default {
servicePath: '/eureka/v2/apps/',
ssl: false,
useDns: false,
fetchAwsMetadata: true
fetchMetadata: true
},
instance: {}
};
20 changes: 10 additions & 10 deletions src/eureka-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ export class Eureka {
start(callback = noop) {
series([
done => {
if (this.amazonDataCenter && this.config.eureka.fetchAwsMetadata) {
return this.addAwsInstanceMetadata(done);
if (this.metadataClient && this.config.eureka.fetchMetadata) {
return this.addInstanceMetadata(done);
}
done();
},
Expand Down Expand Up @@ -307,7 +307,7 @@ export class Eureka {
}

/*
Fetches the AWS metadata using the built-in client and updates the instance
Fetches the metadata using the built-in client and updates the instance
configuration with the public hostname and IP address. A string replacement
is done on the healthCheckUrl and statusPageUrl so that users can define
the URLs with a placeholder for the host ('__HOST__'). This allows
Expand All @@ -317,17 +317,17 @@ export class Eureka {
set config.eureka.fetchAwsMetadata to false if you want to provide your own
metadata in AWS environments.
*/
addAwsInstanceMetadata(callback = noop) {
this.metadataClient.fetchMetadata(awsMetadata => {
this.config.instance.dataCenterInfo.metadata = merge(this.config.instance.dataCenterInfo.metadata, awsMetadata);
this.config.instance.hostName = awsMetadata['public-hostname'];
this.config.instance.ipAddr = awsMetadata['public-ipv4'];
addInstanceMetadata(callback = noop) {
this.metadataClient.fetchMetadata(metadataResult => {
this.config.instance.dataCenterInfo.metadata = merge(this.config.instance.dataCenterInfo.metadata, metadataResult);
this.config.instance.hostName = metadataResult['public-hostname'];
this.config.instance.ipAddr = metadataResult['public-ipv4'];

if (this.config.instance.statusPageUrl) {
this.config.instance.statusPageUrl = this.config.instance.statusPageUrl.replace('__HOST__', awsMetadata['public-hostname']);
this.config.instance.statusPageUrl = this.config.instance.statusPageUrl.replace('__HOST__', metadataResult['public-hostname']);
}
if (this.config.instance.healthCheckUrl) {
this.config.instance.healthCheckUrl = this.config.instance.healthCheckUrl.replace('__HOST__', awsMetadata['public-hostname']);
this.config.instance.healthCheckUrl = this.config.instance.healthCheckUrl.replace('__HOST__', metadataResult['public-hostname']);
}

callback();
Expand Down
4 changes: 2 additions & 2 deletions test/eureka-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ describe('Eureka client', () => {
});
});

describe('addAwsInstanceMetadata()', () => {
describe('addInstanceMetadata()', () => {

let client, config, metadataSpy;
beforeEach(() => {
Expand All @@ -582,7 +582,7 @@ describe('Eureka client', () => {
});

it('should update hosts with AWS metadata public host', () => {
client.addAwsInstanceMetadata(metadataSpy);
client.addInstanceMetadata(metadataSpy);
expect(client.config.instance.hostName).to.equal('ec2-127-0-0-1.us-fake-1.mydomain.com');
expect(client.config.instance.ipAddr).to.equal('54.54.54.54');
expect(client.config.instance.statusPageUrl).to.equal('http://ec2-127-0-0-1.us-fake-1.mydomain.com:8080/');
Expand Down

0 comments on commit 86f3e4d

Please sign in to comment.