【问题标题】:How to set default values to stream parameters in siddhi?如何在 siddhi 中为流参数设置默认值?
【发布时间】:2019-08-29 06:52:43
【问题描述】:

我是否可以在 siddhi 中为流的参数设置默认值?

我有一个通过 curl 命令获取输入的输入流。

@source(type='http', receiver.url='http://0.0.0.0:8008/test', @map(type = 'json', @attributes(a='$.a', b='$.b', c='$.c')))

除非在我的 cURL 命令中另外指定,否则我希望将参数 c 设置为默认值“测试”。

有什么办法可以做到吗?

【问题讨论】:

    标签: siddhi wso2sp


    【解决方案1】:

    您可以在 JSON 映射器中将 fail.on.missing.attribute 设置为 false 并进行空值检查并分配值。请参考official Source JSON Mapper documentationSiddhi default function,如果参数为空,您可以使用它们为参数设置默认值。

    以下是一个示例 Siddhi 应用程序供您参考。

    @App:name("ReceiveAndOutput")
    
    @Source(type = 'http',
            receiver.url='http://localhost:8006/productionStream',
            basic.auth.enabled='false',
            @map(type='json',fail.on.missing.attribute='false', @attributes(name='$.item', amount='$.charge')))
    define stream SweetProductionStream (name string, amount string);
    
    @sink(type='log')
    define stream OutputStream (name string, amount string);
    
    -- Count the incoming events
    @info(name='query1')
    from SweetProductionStream
    select default(name, 'DefaultName') as name, default(amount, '0.0') as amount
    insert into OutputStream;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-03-25
      • 2019-07-08
      • 1970-01-01
      • 2017-02-06
      • 2013-10-07
      • 1970-01-01
      • 2013-01-01
      • 2011-07-31
      相关资源
      最近更新 更多