Created
October 20, 2019 13:21
-
-
Save zilehuda/a825bddf38d7f40b1640aa669ca52beb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const Eureka = require('eureka-js-client').Eureka; | |
const eurekaHost = (process.env.EUREKA_CLIENT_SERVICEURL_DEFAULTZONE || '127.0.0.1'); | |
const eurekaPort = 8761; | |
const hostName = (process.env.HOSTNAME || 'localhost') | |
const ipAddr = '172.0.0.1'; | |
exports.registerWithEureka = function(appName, PORT) { | |
const client = new Eureka({ | |
instance: { | |
app: appName, | |
hostName: hostName, | |
ipAddr: ipAddr, | |
port: { | |
'$': PORT, | |
'@enabled': 'true', | |
}, | |
vipAddress: appName, | |
dataCenterInfo: { | |
'@class': 'com.netflix.appinfo.InstanceInfo$DefaultDataCenterInfo', | |
name: 'MyOwn', | |
}, | |
}, | |
//retry 10 time for 3 minute 20 seconds. | |
eureka: { | |
host: eurekaHost, | |
port: eurekaPort, | |
servicePath: '/eureka/apps/', | |
maxRetries: 10, | |
requestRetryDelay: 2000, | |
}, | |
}) | |
client.logger.level('debug') | |
client.start( error => { | |
console.log(error || "user service registered") | |
}); | |
function exitHandler(options, exitCode) { | |
if (options.cleanup) { | |
} | |
if (exitCode || exitCode === 0) console.log(exitCode); | |
if (options.exit) { | |
client.stop(); | |
} | |
} | |
client.on('deregistered', () => { | |
process.exit(); | |
console.log('after deregistered'); | |
}) | |
client.on('started', () => { | |
console.log("eureka host " + eurekaHost); | |
}) | |
process.on('SIGINT', exitHandler.bind(null, {exit:true})); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey! how do you use the client constant outside this helper file, for example, to call getInstancesByAppId?