mirror of
https://github.com/cool-team-official/cool-admin-midway.git
synced 2026-05-30 12:18:14 +00:00
37 lines
876 B
TypeScript
37 lines
876 B
TypeScript
import { Inject, Post, Provide } from '@midwayjs/decorator';
|
|
import { CoolController, BaseController } from '@cool-midway/core';
|
|
import { CoolRpc } from '@cool-midway/rpc';
|
|
import { DemoRpcService } from '../../service/rpc';
|
|
|
|
/**
|
|
* 微服务
|
|
*/
|
|
@Provide()
|
|
@CoolController()
|
|
export class DemoRpcController extends BaseController {
|
|
@Inject()
|
|
rpc: CoolRpc;
|
|
|
|
@Inject()
|
|
demoRpcService: DemoRpcService;
|
|
|
|
@Post('/call', { summary: '远程调用' })
|
|
async call() {
|
|
return this.ok(
|
|
await this.rpc.call('goods', 'demoGoodsService', 'test', { a: 1 })
|
|
);
|
|
}
|
|
|
|
@Post('/event', { summary: '集群事件' })
|
|
async event() {
|
|
this.rpc.broadcastEvent('test', { a: 1 });
|
|
return this.ok();
|
|
}
|
|
|
|
@Post('/transaction', { summary: '分布式事务' })
|
|
async transaction() {
|
|
await this.demoRpcService.transaction({ a: 1 });
|
|
return this.ok();
|
|
}
|
|
}
|