首页 \ 问答 \ GraphQL和微服务架构(GraphQL and Microservice Architecture)

GraphQL和微服务架构(GraphQL and Microservice Architecture)

我试图了解GraphQL最适合在Microservice架构中使用的位置。

有一些争论,只有一个GraphQL模式作为API网关代理对目标微服务的请求并强制他们的响应。 微服务器仍然会使用REST / Thrift协议进行通信思想。

相反,另一种方法是每个微服务器具有多个GraphQL模式。 拥有一个更小的API网关服务器,将请求的路由请求到目标微服务,并附有请求+图形查询的所有信息。

第一种方法

拥有1个GraphQL架构作为API网关将会有一个缺点,每次更改您的微服务合同输入/输出时,我们必须在API网关侧相应更改GraphQL架构。

第二种方法

如果每个微服务使用多个GraphQL架构,则以某种方式有意义,因为GraphQL强制执行模式定义,并且消费者将需要遵守从微服务器给出的输入/输出。

问题

  • 您在哪里可以找到GraphQL适合设计微服务架构?

  • 您将如何使用可能的GraphQL实现来设计API网关?


I'm trying to understand where GraphQL is most suitable to use within a Microservice architecture.

There is some debate about having only 1 GraphQL schema that works as API Gateway proxying the request to the targeted microservices and coercing their response. Microservices still would use REST / Thrift protocol for communication thought.

Another approach is instead to have multiple GraphQL schemas one per microservice. Having a smaller API Gateway server that route the request to the targeted microservice with all the information of the request + the GraphQL query.

1st Approach

Having 1 GraphQL Schema as an API Gateway will have a downside where every time you change your microservice contract input/output, we have to change the GraphQL Schema accordingly on the API Gateway Side.

2nd Approach

If using Multiple GraphQL Schema per microservices, make sense in a way because GraphQL enforces a schema definition, and the consumer will need to respect input/output given from the microservice.

Questions

  • Where do you find GraphQL the right fit for designing microservice architecture?

  • How would you design an API Gateway with a possible GraphQL implementation?


原文:https://stackoverflow.com/questions/38071714
更新时间:2023-08-25 13:08

最满意答案

仅当您的catch语句抛出到另一个try / catch时,例如:

try{

    ...

   try{
        ...
   }
   catch(ExceptionA a)
   {
      throw;
   }
   catch(Exception e)
   {
       //will not not catch ExceptionA (rethrow or not)
   }
}
catch(ExceptionA a)
{
    //this would catch the re-throw
}
catch( Exception e)
{
}

相反,为什么不捕获一般的Exception ,然后判断异常类型?

try{
        ...
   }
   catch(Exception e)
   {
       if (e is ExceptionA){
            ...
       }
   }

或者把逻辑放在finally

 System.Exception thrownException = null;
 try{
        ...
   }
   catch( ExceptionA a)
   {
      thrownException = a;
      ...  // do special handling...
   }
   catch( ExceptionB b)
   {
      thrownException = b;
      ...  // do special handling...
   }
   catch(Exception e)
   {
      ...
   }
   finally{
     if ( thrownException != null ) {
          ...   //case the type here or use some other way to identify..
     }
   }

Only if your catch statement throws to another try/catch, for example:

try{

    ...

   try{
        ...
   }
   catch(ExceptionA a)
   {
      throw;
   }
   catch(Exception e)
   {
       //will not not catch ExceptionA (rethrow or not)
   }
}
catch(ExceptionA a)
{
    //this would catch the re-throw
}
catch( Exception e)
{
}

Instead why don't you catch the general Exception and then case the exception types?

try{
        ...
   }
   catch(Exception e)
   {
       if (e is ExceptionA){
            ...
       }
   }

Or put logic on the finally

 System.Exception thrownException = null;
 try{
        ...
   }
   catch( ExceptionA a)
   {
      thrownException = a;
      ...  // do special handling...
   }
   catch( ExceptionB b)
   {
      thrownException = b;
      ...  // do special handling...
   }
   catch(Exception e)
   {
      ...
   }
   finally{
     if ( thrownException != null ) {
          ...   //case the type here or use some other way to identify..
     }
   }

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何检索Ember.js模型的所有属性(How to retrieve all properties of an Ember.js model)
  • maven中snapshot快照库和release发布库的区别和作用
  • arraylist中的搜索元素(Search element in arraylist)
  • 从mysli_fetch_array中获取选定的值并输出(Get selected value from mysli_fetch_array and output)
  • Windows Phone上的可用共享扩展(Available Share Extensions on Windows Phone)
  • 如何在命令提示符下将日期设置为文件名(How to set file name as date in command prompt)
  • 如何在Laravel 5.2中使用paginate与关系?(How to use paginate with relationships in Laravel 5.2?)
  • 从iframe访问父页面的id元素(accessing id element of parent page from iframe)
  • linux的常用命令干什么用的
  • Feign Client + Eureka POST请求正文(Feign Client + Eureka POST request body)
  • 怎么删除禁用RHEL/CentOS 7上不需要的服务
  • 为什么Gradle运行测试两次?(Why does Gradle run tests twice?)
  • 由于有四个新控制器,Auth刀片是否有任何变化?(Are there any changes in Auth blades due to four new controllers?)
  • 如何交换返回集中的行?(How to swap rows in a return set?)
  • 在android中的活动之间切换?(Switching between activities in android?)
  • Perforce:如何从Depot到Workspace丢失文件?(Perforce: how to get missing file from Depot to Workspace?)
  • Webform页面避免运行服务器(Webform page avoiding runat server)
  • 在ios 7中的UITableView部分周围绘制边界线(draw borderline around UITableView section in ios 7)
  • 内存布局破解(memory layout hack)
  • 使用Boost.Spirit Qi和Lex时的空白队长(Whitespace skipper when using Boost.Spirit Qi and Lex)
  • 我们可以有一个调度程序,你可以异步添加东西,但会同步按顺序执行吗?(Can we have a dispatcher that you can add things todo asynchronously but will be executed in that order synchronously?)
  • “FROM a,b”和“FROM a FULL OUTER JOIN b”之间有什么区别?(What is the difference between “FROM a, b” and “FROM a FULL OUTER JOIN b”?)
  • Java中的不可变类(Immutable class in Java)
  • bat批处理文件结果导出到txt
  • WordPress发布查询(WordPress post query)
  • 如何在关系数据库中存储与IPv6兼容的地址(How to store IPv6-compatible address in a relational database)
  • 是否可以检查对象值的条件并返回密钥?(Is it possible to check the condition of a value of an object and JUST return the key?)
  • 德州新起点计算机培训学校主要课程有什么?
  • GEP分段错误LLVM C ++ API(GEP segmentation fault LLVM C++ API)
  • “latin1_german1_ci”整理来自哪里?(Where is “latin1_german1_ci” collation coming from?)