本文整理匯總了TypeScript中dubbo2.js.Dubbo.use方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript js.Dubbo.use方法的具體用法?TypeScript js.Dubbo.use怎麽用?TypeScript js.Dubbo.use使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類dubbo2.js.Dubbo
的用法示例。
在下文中一共展示了js.Dubbo.use方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: default
export default (app: EggApplication) => {
const dubboSetting = setting
.match(
[
'com.alibaba.dubbo.demo.DemoProvider',
'com.alibaba.dubbo.demo.ErrorProvider',
],
{
version: '1.0.0',
},
)
.match('com.alibaba.dubbo.demo.BasicTypeProvider', {version: '2.0.0'});
const dubbo = new Dubbo<typeof service>({
application: {name: 'node-egg-bff'},
register: 'localhost:2181',
service,
dubboSetting,
});
// extends middleware
dubbo.use(async (ctx: Context, next: any) => {
const start = Date.now();
await next();
const end = Date.now();
app.coreLogger.info(
`${ctx.dubboInterface} was invoked, cost-time ${end - start}`,
);
});
app.dubbo = dubbo;
};
示例2: test
const dubbo = new Dubbo<typeof service>({
application: {name: '@qianmi/node-dubbo'},
register: 'localhost:2181',
dubboInvokeTimeout: 0.001,
service,
dubboSetting,
});
//use middleware
dubbo.use(async function test(ctx, next) {
const startTime = Date.now();
await next();
const endTime = Date.now();
const {
request: {dubboInterface, methodName},
} = ctx;
console.log(
`timeout: invoke ${dubboInterface}#${methodName} costTime: ${endTime -
startTime}`,
);
});
describe('dubbo timeout test suite', () => {
it('test echo timeout', async () => {
const {res, err} = await dubbo.service.DemoProvider.echo();
expect(res).toEqual(null);
expect(err != null).toEqual(true);
expect(err.message).toMatch(/remote invoke timeout/);
});
it('test sayHello', async () => {
示例3: costtime
);
const dubbo = new Dubbo<typeof service>({
application: {name: '@qianmi/node-dubbo'},
register: 'localhost:2181',
service,
dubboSetting,
});
//use middleware
dubbo.use(async function costtime(ctx, next) {
const startTime = Date.now();
await next();
const endTime = Date.now();
const {
request: {dubboInterface, methodName},
} = ctx;
console.log(
`invoke ${dubboInterface}#${methodName} costTime: ${endTime - startTime}`,
);
});
dubbo.use(async function trace(ctx: Context, next) {
const uuid = Date.now();
//auto merge attchments when assign more
ctx.attachments = {
uuid,
};
ctx.attachments = {
userId: uuid,