eggjs / egg

🥚 Born to build better enterprise frameworks and apps with Node.js & Koa
https://eggjs.org
MIT License
18.83k stars 1.81k forks source link

egg rpc( sofa-node )维护性问题 #4726

Open nxg916 opened 2 years ago

nxg916 commented 2 years ago

以zookeeper 为主的服务端与客户端要同时引入.proto文件并创建proxy.js,是不是增加了协同开发的成本和维护的便利性? 假设现在有一个 gateway服务、a服务、b服务 这个三个服务,gateway服务要对外提供接口,那么就要融入a服务与b服务的.proto文件,不论a服务、b服务哪个服务增加接口,网关层都要跟随做修改,这样的强关联性并不利于维护与开发。 不知是我对egg-sofa-node的理解不深入还是就是我所描述的这样?如果是我描述的这样,是否有其他的解决方式?

atian25 commented 2 years ago

gateway 的玩法不会是这样的,网关需要的是泛化调用 和 SPI 调用规范。

gxcsoccer commented 2 years ago

gateway 的话,一般两种做法

  1. 完全泛化的(固定的结构 + JSON)
  2. 网关自己提供类型注册的能力,然后客户端和服务端都能消费
3338606790 commented 2 years ago

gateway 的话,一般两种做法

  1. 完全泛化的(固定的结构 + JSON)
  2. 网关自己提供类型注册的能力,然后客户端和服务端都能消费

eggjs + zookeeper , 怎么实现完全泛化的?不需要引入.proto文件。直接在网关用这段话可以吗?

const consumer = app.rpcClient.createConsumer({
    interfaceName: 'com.alipay.sofa.rpc.protobuf.aServer',
    targetAppName: 'aServer',
    version: '1.0',
    group: 'SOFA',
    proxyName: 'aServer',
  });

  if (!consumer) {
    // `app.config['typeset_rpc.rpc.service.enable'] = false` will disable this consumer
    return;
  }

  app.beforeStart(async() => {
    await consumer.ready();
  });

consumer.invoke('route func name', [ req ], { 
        ctx: this.ctx,
});
gxcsoccer commented 2 years ago

gateway 的话,一般两种做法

  1. 完全泛化的(固定的结构 + JSON)
  2. 网关自己提供类型注册的能力,然后客户端和服务端都能消费

eggjs + zookeeper , 怎么实现完全泛化的?不需要引入.proto文件。直接在网关用这段话可以吗?

const consumer = app.rpcClient.createConsumer({
    interfaceName: 'com.alipay.sofa.rpc.protobuf.aServer',
    targetAppName: 'aServer',
    version: '1.0',
    group: 'SOFA',
    proxyName: 'aServer',
  });

  if (!consumer) {
    // `app.config['typeset_rpc.rpc.service.enable'] = false` will disable this consumer
    return;
  }

  app.beforeStart(async() => {
    await consumer.ready();
  });

consumer.invoke('route func name', [ req ], { 
        ctx: this.ctx,
});

不行,至少要提供参数的签名,然后通过 JSON 序列化,最后在服务端进行类型恢复,这个是 dubbo 泛化调用的实现

nxg916 commented 2 years ago

@gxcsoccer JSON序列化是 JSON.stringfy() 吗? 参数签名是为了服务端验证用吗?有没有可借鉴或使用的例子?如果 consumerA, consumerB都注册到gateway, 每个服务对外提供一个接口,接口参数包含方法名 和 一个json数据,可不可以?


const consumerA = app.rpcClient.createConsumer(...);
const consumerB = app.rpcClient.createConsumer(...);

// req: {fun_name: 'sayHello', data JSON.stringfy({ key, value })}

consumerA.invoke('A_FUN', [ req ], { 
        ctx: this.ctx,
});

consumerB.invoke('B_FUN', [ req ], { 
        ctx: this.ctx,
});