stream - Siddhi 流式传输无模式数据
问题描述
我有一个来自 ActiveMQ 的源数据,我遇到的问题是这些数据没有固定的结构,因此,当我定义流时它会引发不兼容的数据类型错误,有没有办法通过某些条件来调节源流?
提前致谢。
/*
* Origin of data.
*/
@source(type='jms',
@map(type='csv', delimiter=',', fail.on.unknown.attribute='false'),
factory.initial='org.apache.activemq.jndi.ActiveMQInitialContextFactory',
provider.url='tcp://127.0.0.1:61616',
destination='simulatedData',
connection.factory.type='queue',
connection.factory.jndi.name='QueueConnectionFactory',
transport.jms.SubscriptionDurable='true',
transport.jms.DurableSubscriberClientID='wso2SPclient1')
define stream FileSourceProductionStream(type string, time long, studentId string, fileId string, totalAccesses float); /* totalAccesses : float Incompatible DataType*/
define stream TaskSourceProductionStream(type string, time long, studentId string, taskId string, deadline long); /*deadline: long Incompatible DataType*/
解决方案
在 siddhi 中,源流应该具有输入数据的模式。因此,我们无法将无模式数据接收到已定义的流中。
针对您的场景的一种可能解决方案是定义具有所有可能输入属性的流,并将输入预格式化为 siddhi-map 扩展支持的 JSON[1]、XML[2] 或 TEXT[3] 格式,使用属性名称和值。对于缺少的属性,json/xml/text 输入负载中不会有键或标签。
然后在源配置中使用 @map(fail.on.missing.attributes='false) 配置。
然后对于输入有效载荷中所有缺失的属性,NULL 将分配给输入流的相应属性。
[1] https://wso2-extensions.github.io/siddhi-map-json/api/4.0.20/
[2] https://wso2-extensions.github.io/siddhi-map-xml/api/4.0.12/
[3] https://wso2-extensions.github.io/siddhi-map-text/api/1.0.16/
推荐阅读
- audio - Dialogflow,从音频中检测意图
- java - Android 无法在 videoview 中播放视频
- php - 将函数或字符串注册到 Symfony 依赖注入容器中
- javascript - 具有 Web 用户控件的 ASP.NET 母版页丢失 css 和 javascript
- javascript - Vue重置变量竞争条件
- php - 为什么 mysqli prepare 语句没有清理数据
- c++ - 模板类中的 typedef 语句
- javascript - 箭头函数不起作用。普通人会。为什么?
- html - CSS 和 Boostrap:在 div 中拟合图像或轮播
- mongodb - 为什么我需要指定 $switch 默认语句,而它是可选的?