我想在siddhi中创建一个MQTT源代码,我的代码是
public class MqttReceiver {
private static final Logger log = Logger.getLogger(MqttReceiver.class);
/**
* Main method to start the test client.
*
* @param args no args need to be provided
*/
public static void main(String[] args) {
log.info("Initialize mqtt receiver.");
SiddhiManager siddhiManager = new SiddhiManager();
// String url = "tcp://localhost:5020";
// String topic = "mqtt_topic";
// String type = "xml";
SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(
"@App:name(\"PublishMqttInXmlFormatTest\")\n" +
"@source(type='mqtt', url= 'tcp://localhost:1883', topic='mqtt_topic', clean.session='true',quality.of.service= '1', keep.alive= '60',connection.timeout='30' , @map(type='xml'))" +
"define stream LowProducitonAlertStream (name string, amount double);\n" +
"@sink(type='log')\n" +
"define stream logStream(name string, amount double);\n" +
"from LowProducitonAlertStream\n" +
"select * \n" +
"insert into logStream;");
siddhiAppRuntime.start();
while (true) {
}
}
}
但我收到以下异常
No extension exist for sourceMapper:xml
从下图中可以看出,XML
作为库文件中的示例
我做错了什么?
似乎库文件中未提及name parameter
的{{1}},但示例中提到了api
type
如何在siddhi中使用MQTT?
答案 0 :(得分:1)
在我的头撞到屏幕一小时之后,我认为这是我的全部错误,实际上,@map json
是另一个需要导入maven POM的扩展。因此,如果您遇到此问题,请将this dependency放入POM