shenyu icon indicating copy to clipboard operation
shenyu copied to clipboard

[Question] Suggest simple the route config or Give some help video

Open ochive opened this issue 1 year ago • 1 comments

Question

Suggest simple the route config?

I want to route to a python service behind the nacos.

the request uri:“someServiceApi/someModule/doSomething” the actual uri in the python service: "someModule/doSomething"

To config the route, it seems that i need do below steps:

  1. config boot strap server, let it connect to nacos server.
  2. use httpProcess/Rewrite to strip the prefix "someServiceApi".
  3. use Proxy/SpringCloud to route via serviceId "someServiceApi".

Why can not do this one-stop in one plugin? For example, There is a discovery config in divide plugin, Just add a pathRewrite on form to complete the workflow. PS: I can not successed with the discovery config in divide, never.

help video

I hope can get some video about common route scenario:

  1. route to pure http service, contains pathRewrite, request header modify, oauth integration, etc.
  2. route to http service(write in any program lang, not just java spring) behind service discovery
  3. route to websocket service
  4. route to websocket service behind service discovery

ochive avatar Sep 29 '24 07:09 ochive

thanks for your suggestions

moremind avatar Oct 10 '24 00:10 moremind

Can i do this requirement

Implementation Steps:

1.Modify the Data Model of the Divide Plugin: In the handler class of the Divide plugin, add configuration fields related to path rewriting. 2.Modify the Processing Logic of the Divide Plugin: During the request processing, perform path rewriting first, and then execute service discovery and routing. 3.Modify the Frontend Interface of ShenYu Admin: In the rule configuration of the Divide plugin, add path rewrite configuration options for users to input.

Considerations

  1. Compatibility and Default Values:

    • Ensure that when users do not provide path rewrite configurations, the Divide plugin continues to work as per the original logic.
    • In the code, add checks so that path rewriting is performed only when the configuration fields are not empty.
  2. Configuration Validation:

    • In the frontend form, add basic validation for regular expressions to prompt users to enter the correct format.
  3. Performance Impact:

    • Since the path rewrite processing is added, pay attention to the impact on request processing performance. You can evaluate this through performance testing.
  4. Logging:

    • Add logs before and after path rewriting to facilitate debugging and issue troubleshooting.

      if (matcher.find()) {
          String newPath = matcher.replaceAll(ruleHandle.getPathRewriteReplacement());
          LOG.info("Path rewritten from {} to {}", originalPath, newPath);
          // ...
      }
      
  5. Exception Handling:

    • For possible exceptions (e.g., errors in regular expressions), ensure proper try-catch handling to avoid affecting the request flow.

yunmaoQu avatar Oct 18 '24 16:10 yunmaoQu