You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

WSO2 SP中能否基于流参数配置HTTP Sink动态publisher.url?

动态设置WSO2 SP HTTP Request Sink的URL

当然可以!WSO2 Streaming Processor完全支持为HTTP Request Sink构建动态URL,不管是将流属性作为URL路径的一部分,还是作为查询参数,都能轻松实现。针对你的场景,只需要调整publisher.url的语法,用流中的var属性替换路径中的固定占位符即可。

核心修改点

你原来的publisher.url里用了<var>这种自定义占位符,这不是Siddhi支持的语法。正确的做法是使用{{attributeName}}的模板语法来引用流中的属性——不管是URL路径段还是查询参数,都可以用这种方式动态替换。

修改后的完整Siddhi代码

@App:name("TestApp")

@source(type='http', receiver.url='http://0.0.0.0:8008/xyz', 
        @map(type = 'json', 
             @attributes(a='$.b', b='$.b', c='$.c', var='$.var')))
@sink(type='log')
define stream InputStream(a string, b string, c string, var string);

@source(type='http-response' ,sink.id='1234', 
        @map(type='json', 
             @attributes(a1='a1', a2='a2', a3='a3')))
@sink(type='log')
define stream ResponseStream (a1 string, a2 string, a3 string);

@sink(type='http-request', sink.id='1234', 
      publisher.url='http://<host>:<port>/{{var}}/parse?a={{a}}&b={{b}}&c={{c}}', 
      method='GET', 
      headers="'Content-Type:text/plain'", 
      @map(type='keyvalue', 
           @payload(a='{{b}}', b='{{b}}', c='{{c}}')))
define stream InterStream (a string, b string, c string, var string);

from InputStream 
select a, b, c, var 
insert into InterStream;

关键说明

  • 把路径中的<var>替换为{{var}}后,Siddhi会自动从InterStream的var字段取值,动态拼接成完整URL。比如当var的值为order-service时,实际请求的URL会变成http://<host>:<port>/order-service/parse?a=xxx&b=xxx&c=xxx。
  • 确保InterStream中确实包含var属性(你的代码里已经通过InputStream传递过来了,这部分逻辑没问题),避免因属性缺失导致URL构建失败。
  • 如果需要更复杂的动态URL逻辑(比如拼接多个属性、添加固定后缀),还可以使用Siddhi的表达式函数扩展,例如用concat()函数:
    publisher.url='http://<host>:<port>/{{concat(var, "-v1")}}/parse?a={{a}}'
    

内容的提问来源于stack exchange,提问作者dilip sundar

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.14 08:00:02