-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make cluster client configurable in egg (#1459)
- Loading branch information
Showing
10 changed files
with
221 additions
and
41 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
'use strict'; | ||
|
||
const ApiClient = require('./lib/api_client'); | ||
const ApiClient2 = require('./lib/api_client_2'); | ||
const RegistryClient = require('./lib/registry_client'); | ||
|
||
module.exports = function(agent) { | ||
const done = agent.readyCallback('register_client', { | ||
isWeakDep: agent.config.runMode === 0, | ||
}); | ||
agent.registryClient = agent.cluster(RegistryClient).create(); | ||
agent.registryClient.ready(done); | ||
agent.apiClient = new ApiClient({ | ||
cluster: agent.cluster, | ||
}); | ||
agent.apiClient2 = new ApiClient2({ | ||
cluster: agent.cluster, | ||
}); | ||
|
||
agent.beforeStart(function*() { | ||
yield agent.registryClient.ready(); | ||
yield agent.apiClient.ready(); | ||
yield agent.apiClient2.ready(); | ||
}); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
'use strict'; | ||
|
||
const ApiClient = require('./lib/api_client'); | ||
const ApiClient2 = require('./lib/api_client_2'); | ||
const RegistryClient = require('./lib/registry_client'); | ||
|
||
module.exports = function(app) { | ||
const done = app.readyCallback('register_client', { | ||
isWeakDep: app.config.runMode === 0, | ||
}); | ||
const cluster = app.cluster; | ||
app.registryClient = cluster(RegistryClient).create(); | ||
app.registryClient.ready(done); | ||
|
||
app.registryClient.subscribe({ | ||
dataId: 'demo.DemoService', | ||
}, val => { | ||
app.val = val; | ||
}); | ||
|
||
app.apiClient = new ApiClient({ cluster }); | ||
app.apiClient2 = new ApiClient2({ cluster }); | ||
|
||
app.beforeStart(function*() { | ||
yield app.registryClient.ready(); | ||
yield app.apiClient.ready(); | ||
yield app.apiClient2.ready(); | ||
}); | ||
}; |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
'use strict'; | ||
|
||
const APIClientBase = require('cluster-client').APIClientBase; | ||
|
||
class ApiClient extends APIClientBase { | ||
get DataClient() { | ||
return require('./registry_client'); | ||
} | ||
|
||
get clusterOptions() { | ||
return { | ||
name: 'ApiClient', | ||
}; | ||
} | ||
|
||
* getResponseTimeout() { | ||
return this._client.options.responseTimeout; | ||
} | ||
} | ||
|
||
module.exports = ApiClient; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
'use strict'; | ||
|
||
const APIClientBase = require('cluster-client').APIClientBase; | ||
|
||
class ApiClient2 extends APIClientBase { | ||
get DataClient() { | ||
return require('./registry_client'); | ||
} | ||
|
||
get clusterOptions() { | ||
return { | ||
name: 'ApiClient2', | ||
responseTimeout: 1000, | ||
}; | ||
} | ||
|
||
* getResponseTimeout() { | ||
return this._client.options.responseTimeout; | ||
} | ||
} | ||
|
||
module.exports = ApiClient2; |
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