1

我正在尝试在网关处创建一个端点,该端点将调用多个服务调用并将它们组合成一个响应。快递网关可以吗?

这是我的 gateway.config.yml。

http:
  port: 8080
admin:
  port: 9876
  host: localhost
apiEndpoints:
  api:
    host: localhost
    paths: '/ip'
  uuid:
    host: localhost
    paths: '/uuid'
  agent: 
    host: localhost
    paths: '/user-agent'

serviceEndpoints:
  httpbin:
    url: 'https://httpbin.org'
  uuid:
    url: 'https://httpbin.org'
  agent:
    url: 'https://httpbin.org'    
policies:
  - basic-auth
  - cors
  - expression
  - key-auth
  - log
  - oauth2
  - proxy
  - rate-limit
pipelines:
  default:
    apiEndpoints:
      - api
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: httpbin 
              changeOrigin: true
  default-1:
    apiEndpoints:
      - uuid
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: uuid 
              changeOrigin: true            
  default-2:
    apiEndpoints:
      - agent
    policies:
    # Uncomment `key-auth:` when instructed to in the Getting Started guide.
      - key-auth:
      - proxy:
          - action:
              serviceEndpoint: agent 
              changeOrigin: true

基本上,我想将所有声明的 serviceEndpoints 组合到一个路径。假设我触发 /ip ,它将调用 'api,uuid,agent' serviceEndpoints 并将它们全部组合成一个响应。那可能吗?

4

2 回答 2

0

在这方面有多种方法建议,您可以根据您的用例、技术堆栈、团队和技术技能以及其他变量进行权衡。

  1. 编写一个调用其他底层服务的聚合服务
  2. 让网关执行服务聚合、数据格式化等...这里的重要方面是确保您不会打破域边界。它极有可能/很有可能在网关处注入一些域逻辑以及聚合,所以要非常小心。
  3. 看看那里的 GraphQL 库,它可以很好地暴露在您的标准 REST API 之上,您可以定义架构并定义解析器。
于 2020-10-11T09:53:56.687 回答
0

不幸的是,Express Gateway 并不真正支持这种情况。您将不得不编写自己的插件——但这不会那么容易。

于 2020-01-14T10:04:42.460 回答