Skip to content
Permalink
Browse files
fixed: example dubbo setting
  • Loading branch information
hufeng committed Apr 12, 2022
1 parent d2d5db2 commit 0b1502f063f97187fa65cd468df1709054e9a597
Showing 5 changed files with 34 additions and 37 deletions.
@@ -15,8 +15,8 @@
* limitations under the License.
*/

import {Context, Dubbo, setting} from 'apache-dubbo-js'
import {EggApplication} from 'egg'
import { Context, Dubbo, s } from 'apache-dubbo-js'
import { EggApplication } from 'egg'
import service from './service'

declare module 'egg' {
@@ -26,32 +26,30 @@ declare module 'egg' {
}

// dubbo interface setting
const dubboSetting = setting
.match(
const dubboSetting = s.Setting(
s.service(
[
'org.apache.dubbo.demo.DemoProvider',
'org.apache.dubbo.demo.ErrorProvider',
'org.apache.dubbo.demo.ErrorProvider'
],
{
version: '1.0.0',
},
)
.match('org.apache.dubbo.demo.BasicTypeProvider', {version: '2.0.0'})

{ version: '1.0.0' }
),
s.service('org.apache.dubbo.demo.BasicTypeProvider', { version: '2.0.0' })
)
export default (app: EggApplication) => {
// create a dubboo object
const {application, registry} = app.config.dubbo
const { application, registry } = app.config.dubbo
const dubbo = new Dubbo<typeof service>({
application,
registry,
service,
dubboSetting,
dubboSetting
})

dubbo.subscribe({
onTrace(err) {
console.log(err)
},
}
})

// extends middleware
@@ -60,7 +58,7 @@ export default (app: EggApplication) => {
await next()
const end = Date.now()
app.coreLogger.info(
`${ctx.dubboInterface} was invoked, cost-time ${end - start}`,
`${ctx.dubboInterface} was invoked, cost-time ${end - start}`
)
})

@@ -15,12 +15,12 @@
* limitations under the License.
*/

import {BasicTypeProvider} from './providers/org/apache/dubbo/demo/BasicTypeProvider';
import {DemoProvider} from './providers/org/apache/dubbo/demo/DemoProvider';
import {ErrorProvider} from './providers/org/apache/dubbo/demo/ErrorProvider';
import { BasicTypeProvider } from './providers/org/apache/dubbo/demo/BasicTypeProvider'
import { DemoProvider } from './providers/org/apache/dubbo/demo/DemoProvider'
import { ErrorProvider } from './providers/org/apache/dubbo/demo/ErrorProvider'

export default {
DemoProvider,
BasicTypeProvider,
ErrorProvider,
};
ErrorProvider
}
@@ -15,7 +15,7 @@
* limitations under the License.
*/

import {Service} from 'egg';
import { Service } from 'egg'

/**
* Test Service
@@ -26,6 +26,6 @@ export default class Test extends Service {
* @param name - your name
*/
public async sayHi(name: string) {
return `hi, ${name}`;
return `hi, ${name}`
}
}
@@ -15,24 +15,23 @@
* limitations under the License.
*/

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

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

/**
* create dubbo instance, it create proxyService
@@ -28,13 +28,13 @@ router.get('/', (ctx) => {
})

router.get('/hello', async (ctx) => {
const {res, err} = await dubbo.service.demoProvider.sayHello('test')
const { res, err } = await dubbo.service.demoProvider.sayHello('test')
console.log(await dubbo.service.basicTypeProvider.testBasicType())
ctx.body = err ? err.message : res
})

router.get('/user', async (ctx) => {
const {res, err} = await dubbo.service.demoProvider.getUserInfo()
const { res, err } = await dubbo.service.demoProvider.getUserInfo()
ctx.body = res || err.message
})

@@ -43,19 +43,19 @@ router.get('/echo', async (ctx) => {
})

router.get('/type', async (ctx) => {
const {res, err} = await dubbo.service.basicTypeProvider.testBasicType()
const { res, err } = await dubbo.service.basicTypeProvider.testBasicType()
ctx.body = res || err.message
})

router.get('/exp', async (ctx) => {
const {res, err} = await dubbo.service.errorProvider.errorTest()
const { res, err } = await dubbo.service.errorProvider.errorTest()
console.log(res)
ctx.body = err.message
})

router.get('/tracer', async (ctx) => {
const {res: hello} = await dubbo.service.demoProvider.sayHello('test')
const {res: userInfo} = await dubbo.service.demoProvider.getUserInfo()
const { res: hello } = await dubbo.service.demoProvider.sayHello('test')
const { res: userInfo } = await dubbo.service.demoProvider.getUserInfo()

setTimeout(async () => {
await dubbo.service.basicTypeProvider.testBasicType()
@@ -66,7 +66,7 @@ router.get('/tracer', async (ctx) => {

ctx.body = {
hello,
userInfo,
userInfo
}
})

0 comments on commit 0b1502f

Please sign in to comment.