Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/client/consumer.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ class RpcConsumer extends Base {
return this.options.targetAppName;
}

get groupName() {
return this.options.groupName;
}

get registryConfig() {
return {
protocol: 'bolt',
Expand All @@ -72,6 +76,7 @@ class RpcConsumer extends Base {
group: this.group,
appName: this.targetAppName,
timeout: this.options.responseTimeout,
groupName: this.groupName
};
}

Expand Down Expand Up @@ -116,6 +121,7 @@ class RpcConsumer extends Base {
codecType: options.codecType,
timeout: options.responseTimeout || this.options.responseTimeout,
ctx: options.ctx,
groupName: this.groupName
});
}

Expand Down
1 change: 1 addition & 0 deletions lib/client/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class RpcRequest {
this.requestProps = data.requestProps || {
service: data.serverSignature,
};
this.groupName = data.groupName;
this.ctx = data.ctx;
this.meta = {
id: null,
Expand Down
1 change: 1 addition & 0 deletions lib/server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class RpcServer extends Base {
logger: this.logger,
group: this.options.group,
version: this.options.version,
groupName: this.options.groupName,
delegate,
}, info));
service.on('error', err => { this.emit('error', err); });
Expand Down
2 changes: 2 additions & 0 deletions lib/server/service.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class RpcService extends Base {
this.version = options.version;
this.uniqueId = options.uniqueId;
this.group = options.group;
this.groupName = options.groupName;
// 获取自定义元数据
// get custom metadata
this.customMeta = typeof options.customMeta === 'object' ? options.customMeta : {};
Expand Down Expand Up @@ -71,6 +72,7 @@ class RpcService extends Base {
interfaceName: this.interfaceName,
version: this.version,
group: this.group,
groupName: this.groupName,
url: url.toString(),
};
return Object.assign(reg, customMeta);
Expand Down
17 changes: 17 additions & 0 deletions test/supports/custom_group_name_server.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

const RpcServer = require('../../lib').server.RpcServer;

const server = new RpcServer({
appName: 'node-rpc-server-test',
logger: console,
groupName: 'custom-group-name'
});

server.addService('com.alipay.node.rpctest.echoService', {
async ping() {
return server.options.groupName;
},
});

module.exports = server;
12 changes: 12 additions & 0 deletions test/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,4 +430,16 @@ describe('test/test/index.test.js', () => {
}, done);
});
});

describe('support custom group name', () => {
it('should ping success', done => {
const server = require('../supports/custom_group_name_server');
request(server)
.service('com.alipay.node.rpctest.echoService')
.invoke('ping')
.expect(res => {
assert.equal(res, 'custom-group-name');
}, done);
});
});
});