You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dubbo.apache.org by hu...@apache.org on 2021/08/02 03:53:38 UTC

[dubbo-js] branch master updated: fixed: dubbo-service registry url

This is an automated email from the ASF dual-hosted git repository.

hufeng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/dubbo-js.git


The following commit(s) were added to refs/heads/master by this push:
     new 220936a  fixed: dubbo-service registry url
220936a is described below

commit 220936af59dab42913f05773d0f1acbb07ebd3b8
Author: hufeng <fe...@gmail.com>
AuthorDate: Mon Aug 2 11:53:11 2021 +0800

    fixed: dubbo-service registry url
---
 packages/dubbo-service/src/dubbo-service.ts | 40 +++++++++++++++++++++--------
 packages/dubbo-service/src/types.ts         |  2 ++
 2 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/packages/dubbo-service/src/dubbo-service.ts b/packages/dubbo-service/src/dubbo-service.ts
index 1c7b6dc..9fcbb8a 100644
--- a/packages/dubbo-service/src/dubbo-service.ts
+++ b/packages/dubbo-service/src/dubbo-service.ts
@@ -58,6 +58,9 @@ export default class DubboService {
   private reject: Function
   private readonly readyPromise: Promise<void>
 
+  private application: { name: string }
+  private dubbo: string
+
   private retry: Retry
   private port: number
   private server: net.Server
@@ -70,6 +73,10 @@ export default class DubboService {
   constructor(props: IDubboServerProps) {
     DubboService.checkProps(props)
 
+    // set application name
+    this.application = props.application
+    this.dubbo = props.dubbo
+
     // init ready promise
     this.readyPromise = new Promise((resolve, reject) => {
       this.resolve = resolve
@@ -290,18 +297,29 @@ export default class DubboService {
   private buildUrl(service: IDubboService) {
     const { dubboInterface, group, version, methods } = service
     const methodName = Object.keys(methods).join()
+    const params = {
+      interface: dubboInterface,
+      methods: methodName,
+      side: 'provider',
+      pid: process.pid,
+      protocol: 'dubbo',
+      anyhost: true,
+      timestamp: Date.now()
+    }
+    if (this.application) {
+      params['application'] = this.application.name || 'node-dubbo-service'
+    }
+    if (this.dubbo) {
+      params['dubbo'] = this.dubbo
+    }
+    if (group !== '') {
+      params['group'] = group
+    }
+    if (version !== '0.0.0') {
+      params['version'] = version
+    }
     return (
-      `dubbo://${ipAddr}:${this.port}/${dubboInterface}?` +
-      qs.stringify({
-        group,
-        version,
-        methods: methodName,
-        side: 'provider',
-        pid: process.pid,
-        protocol: 'dubbo',
-        anyhost: true,
-        timestamp: Date.now()
-      })
+      `dubbo://${ipAddr}:${this.port}/${dubboInterface}?` + qs.stringify(params)
     )
   }
 
diff --git a/packages/dubbo-service/src/types.ts b/packages/dubbo-service/src/types.ts
index 0bb1c0e..8347f43 100644
--- a/packages/dubbo-service/src/types.ts
+++ b/packages/dubbo-service/src/types.ts
@@ -26,6 +26,8 @@ export type TMatchThunk = (
 ) => IDubboServiceSetting
 
 export interface IDubboServerProps {
+  application?: { name: string }
+  dubbo?: string
   registry: IRegistry<any>
   services: { [name in string]: IDubboService }
   dubboSetting?: DubboSetting