Skip to content
Permalink
Browse files
feat: add nacos for dubbo-js4.0
  • Loading branch information
godkun committed Jun 8, 2021
1 parent d1addbe commit 879b62399f5de42e99b4c6f1a0cd92c650d30ada
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 127 deletions.
@@ -60,5 +60,5 @@ es7
examples/hello-egg/typings
examples/hello-midway/src/typings

nacos-docker/example/standalone-logs/
nacos-docker/example/cluster-logs/
dubbo-java/nacos-docker/example/standalone-logs/
dubbo-java/nacos-docker/example/cluster-logs/
@@ -17,19 +17,18 @@

import Koa from 'koa'
import { Dubbo } from '@apache/dubbo-consumer'
import { Zk } from '@apache/dubbo-registry'
import service from './service'
// import { Zk } from '@apache/dubbo-registry'
import { Nacos } from '@apache/dubbo-registry'
import services from './service'

const dubbo =
new Dubbo() <
typeof service >
{
application: {
name: 'hello-api'
},
registry: Zk({ connect: 'localhost:2181' }),
service
}
const dubbo = new Dubbo<typeof services>({
application: {
name: 'hello-api'
},
registry: Nacos({ connect: 'nacos://localhost:8848' }),
// registry: Zk({ connect: 'localhost:2181' }),
services
})

const server = new Koa()
server.use(async (ctx) => {
@@ -40,5 +39,5 @@ server.use(async (ctx) => {
err: err?.message
}
})
server.listen(3000)
console.log('hello-api start at port 3000')
server.listen(6000)
console.log('hello-api start at port 6000....')
@@ -15,10 +15,10 @@
* limitations under the License.
*/

import { Dubbo, IDubboResult, java } from '@apache/dubbo-consumer'
import { Dubbo, TDubboCallResult, java } from '@apache/dubbo-consumer'

export interface IHelloService {
hello(name: string): Promise<IDubboResult<string>>
hello(name: string): Promise<TDubboCallResult<string>>
}

export const helloService = (dubbo: Dubbo): IHelloService =>
@@ -16,11 +16,13 @@
*/

import { DubboService } from '@apache/dubbo-service'
import { Zk } from '@apache/dubbo-registry'
// import { Zk } from '@apache/dubbo-registry'
import { Nacos } from '@apache/dubbo-registry'
import services from './service'
;(async function main() {
const dubbo = new DubboService({
registry: Zk({ connect: 'localhost:2181' }),
// registry: Zk({ connect: 'localhost:2181' }),
registry: Nacos({ connect: 'nacos://localhost:8848' }),
services
})
await dubbo.ready()
@@ -15,34 +15,35 @@
* limitations under the License.
*/

import {Dubbo, setting} from 'apache-dubbo-js'
import * as service from './service'
import { Dubbo, dubboSetting } from '@apache/dubbo-consumer'
import { Zk } from '@apache/dubbo-registry'
import * as services from './service'

/**
* setting dubbo invoke params, such version, group etc.
*/
const dubboSetting = setting
const setting = dubboSetting
.match(
[
'org.apache.dubbo.demo.DemoProvider',
'org.apache.dubbo.demo.ErrorProvider',
'org.apache.dubbo.demo.ErrorProvider'
],
{
version: '1.0.0',
},
version: '1.0.0'
}
)
.match('org.apache.dubbo.demo.BasicTypeProvider', {version: '2.0.0'})
.match('org.apache.dubbo.demo.BasicTypeProvider', { version: '2.0.0' })

/**
* create dubbo instance, it create proxyService
*/
// console.log('nacos-----', nacos);
const dubbo = new Dubbo<typeof service>({
application: {name: 'dubbo-node-consumer'},
service,
dubboSetting,
const dubbo = new Dubbo<typeof services>({
application: { name: 'dubbo-node-consumer' },
services,
dubboSetting: setting,
// default zookeeper
registry: `localhost:2181`,
registry: Zk({ connect: 'localhost:2181' })
})

/**
@@ -53,13 +54,4 @@ dubbo.use(async (ctx, next) => {
console.log('-providerAttachments-->', ctx.providerAttachments)
})

/**
* subscribe apache-dubbo-js inner message
*/
dubbo.subscribe({
onTrace(msg) {
console.log(msg)
},
})

export default dubbo
@@ -15,32 +15,32 @@
* limitations under the License.
*/

import {Dubbo, java, TDubboCallResult} from 'apache-dubbo-js';
import { Dubbo, java, TDubboCallResult } from '@apache/dubbo-consumer'

//=====================types===========================
export interface IUserResponse {
status?: string;
info?: {[name: string]: string};
status?: string
info?: { [name: string]: string }
}

export interface IDemoProvider {
sayHello(name: string): TDubboCallResult<string>;
test(): TDubboCallResult<void>;
echo(): TDubboCallResult<string>;
getUserInfo(): TDubboCallResult<IUserResponse>;
sayHello(name: string): TDubboCallResult<string>
test(): TDubboCallResult<void>
echo(): TDubboCallResult<string>
getUserInfo(): TDubboCallResult<IUserResponse>
}

export interface ITypeRequest {
bigDecimal?: {value: string};
map?: {[name: string]: string};
bigDecimal?: { value: string }
map?: { [name: string]: string }
}

export interface IBasicTypeProvider {
testBasicType(): TDubboCallResult<ITypeRequest>;
testBasicType(): TDubboCallResult<ITypeRequest>
}

export interface IErrorProvider {
errorTest(): TDubboCallResult<void>;
errorTest(): TDubboCallResult<void>
}

//========================provider=======================
@@ -49,7 +49,7 @@ export const demoProvider = (dubbo: Dubbo): IDemoProvider =>
dubboInterface: 'org.apache.dubbo.demo.DemoProvider',
methods: {
sayHello(name: string) {
return [java.String(name)];
return [java.String(name)]
},

echo() {},
@@ -61,12 +61,12 @@ export const demoProvider = (dubbo: Dubbo): IDemoProvider =>
java.combine('org.apache.dubbo.demo.UserRequest', {
id: 1,
name: 'nodejs',
email: 'node@qianmi.com',
}),
];
},
},
});
email: 'node@qianmi.com'
})
]
}
}
})

export const basicTypeProvider = (dubbo: Dubbo): IBasicTypeProvider =>
dubbo.proxyService({
@@ -75,20 +75,20 @@ export const basicTypeProvider = (dubbo: Dubbo): IBasicTypeProvider =>
testBasicType() {
return [
java.combine('org.apache.dubbo.demo.TypeRequest', {
map: java.Map({name: 'test'}),
bigDecimal: java.BigDecimal('1000.0000'),
}),
];
},
},
});
map: java.Map({ name: 'test' }),
bigDecimal: java.BigDecimal('1000.0000')
})
]
}
}
})

export const errorProvider = (dubbo: Dubbo): IErrorProvider =>
dubbo.proxyService({
dubboInterface: 'org.apache.dubbo.demo.ErrorProvider',
methods: {
errorTest() {
return [];
},
},
});
return []
}
}
})

0 comments on commit 879b623

Please sign in to comment.