Rdebu opened a new issue #5561:
URL: https://github.com/apache/apisix/issues/5561


   ### Issue description
   
   I want to add a new parameter SID to the request based on the RID parameter, 
and then customize the publication based on the SID parameter.  I wanted to use 
Vars and custom plug-ins to do this, but after testing, I found that custom 
plug-ins have a lower priority than Vars. Now I created a new intermediate 
route and asked it to create sid parameters directly, upstream from Apisix 
itself.  The other route receives the intermediate URI and streams the SID 
parameter.  I feel that this way is a bit troublesome, may I ask if Apisix 
provides a solution that can be completed with only one route  
   
【我想要在请求中根据rid参数添加一个新参数sid,再根据sid参数进行自定义发布。我本来想使用vars和自定义插件完成,但是经过测试发现自定义插件的优先级没有vars高,现在的解决方案是我又新建了个过渡的路由,让它直接接收请求创建sid参数,他的上游是apisix自己;另一个路由接收的是那个中间过渡的uri,再对sid参数进行分流。我感觉我这种方式有点麻烦,请问apisix有没有提供一个可以只用一个路由就能完成的方案呢】
   
   Here is my configuration
   【以下是我的配置】
   
   My plug-in for sid generation
   【我的用于生成sid的插件:】
   @Component
   public class RidGetSidFilter implements PluginFilter {
       @Override
       public String name() {
           return "RidGetSidFilter";
       }
   
       @Override
       public Mono<Void> filter(HttpRequest request, HttpResponse response, 
PluginFilterChain chain) {
           String ridStr = request.getArg("rid");
           Long ridLong = Long.parseLong(ridStr);
           //根据rid生成sid
           RID rid = RID.parse(ridLong);
           int sid = rid.getSid();
           request.setArg("sid", String.valueOf(sid));
           return chain.filter(request, response);
       }
   }
   
   The first route I configured(Access the Java plug-in to generate the SID 
parameter  ):
   【我配置的第一个路由(访问java插件生成sid参数):】
   {
     "uri": "/rid",
     "name": "rid",
     "desc": "RidGetSidFilter",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE"
     ],
     "plugins": {
       "ext-plugin-pre-req": {
         "conf": [
           {
             "name": "RidGetSidFilter",
             "value": ""
           }
         ]
       },
       "proxy-rewrite": {
         "uri": "/sid"
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "127.0.0.1",
           "port": 9080,
           "weight": 1
         }
       ],
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "status": 1
   }
   
   The second route I configured (custom advertise based on sid 0)  
   【我配置的第二个路由(根据sid是否为0进行自定义发布)】
   {
     "uri": "/sid",
     "name": "sid",
     "methods": [
       "GET",
       "POST",
       "PUT",
       "DELETE",
       "PATCH",
       "HEAD",
       "OPTIONS",
       "CONNECT",
       "TRACE"
     ],
     "vars": [
       [
         "arg_sid",
         "==",
         "0"
       ]
     ],
     "plugins": {
       "proxy-rewrite": {
         "uri": "/rid"
       }
     },
     "upstream": {
       "nodes": [
         {
           "host": "172.20.23.125",
           "port": 8002,
           "weight": 1
         }
       ],
       "type": "roundrobin",
       "scheme": "http",
       "pass_host": "pass"
     },
     "status": 1
   }
   
   
   例外附上我最开始的路由,但是vars的优先级高于自定义插件
   {
       "uri":"/rid",
       "name":"sid",
       "methods":[
           "GET",
           "POST",
           "PUT",
           "DELETE",
           "PATCH",
           "HEAD",
           "OPTIONS",
           "CONNECT",
           "TRACE"
       ],
       "vars":[
           [
               "arg_sid",
               "==",
               "0"
           ]
       ],
       "plugins":{
           "ext-plugin-pre-req":{
               "conf":[
                   {
                       "name":"RidGetSidFilter",
                       "value":""
                   }
               ]
           }
       },
       "upstream":{
           "nodes":[
               {
                   "host":"172.20.23.125",
                   "port":8002,
                   "weight":1
               }
           ],
           "type":"roundrobin",
           "scheme":"http",
           "pass_host":"pass"
       },
       "status":1
   }
   
   
   ### Environment
   
   - apisix version (cmd: `apisix version`): 2.7
   - OS (cmd: `uname -a`): centos7
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`): 
openresty/1.19.9.1
   - etcd version, if have (cmd: run `curl 
http://127.0.0.1:9090/v1/server_info` to get the info from server-info API): 
3.4.0
   - apisix-dashboard version, if have: 2.8
   - the plugin runner version, if the issue is about a plugin runner (cmd: 
depended on the kind of runner): java8 + apisix-java-plugin-runner 0.1
   - luarocks version, if the issue is about installation (cmd: `luarocks 
--version`): 3.4.0
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to