Description:
Currently, the nats extension for siddhi only supports String.class Line in code, unlike gRPC extension which supports String.class and GeneratedMessageV3.class Line in code. Since nats and nats-streaming both support protobuf messages as payload, this extension throws an exception when trying to send protobuf messages to siddhi via nats, like:
@source(type='nats', destination='channel1',@Map(type='protobuf', class='com.example.InputStream'))
define stream inputStream (timeStamp long, data int)
Exception:
ERROR {io.siddhi.distribution.core.internal.ServiceComponent} - Exception occurred when deploying the Siddhi AppTEST.siddhi io.siddhi.distribution.core.internal.exception.SiddhiAppDeploymentException: io.siddhi.core.exception.SiddhiAppCreationException: Error on 'TEST' @ Line: 6. Position: 110, near '@source(type='nats', destination='channel1',@Map(type='protobuf', class='com.example.InputStream'))'. At stream 'inputStream', source 'nats' produces incompatible '[class java.lang.String, interface java.util.Map]' classes, while it's source mapper 'protobuf' can only consume '[class com.google.protobuf.GeneratedMessageV3]' classes.
Caused by: io.siddhi.core.exception.SiddhiAppCreationException: Error on 'TEST' @ Line: 6. Position: 110, near '@source(type='nats', destination='channel1',@Map(type='protobuf', class='com.example.InputStream'))'. At stream 'inputStream', source 'nats' produces incompatible '[class java.lang.String, interface java.util.Map]' classes, while it's source mapper 'protobuf' can only consume '[class com.google.protobuf.GeneratedMessageV3]' classes.
at io.siddhi.core.util.parser.helper.DefinitionParserHelper.validateSourceMapperCompatibility(DefinitionParserHelper.java:422)
at io.siddhi.core.util.parser.helper.DefinitionParserHelper.addEventSource(DefinitionParserHelper.java:357)
at io.siddhi.core.util.SiddhiAppRuntimeBuilder.defineStream(SiddhiAppRuntimeBuilder.java:114)
at io.siddhi.core.util.parser.SiddhiAppParser.defineStreamDefinitions(SiddhiAppParser.java:373)
at io.siddhi.core.util.parser.SiddhiAppParser.parse(SiddhiAppParser.java:229)
at io.siddhi.core.SiddhiManager.createSiddhiAppRuntime(SiddhiManager.java:66)
at io.siddhi.core.SiddhiManager.createSiddhiAppRuntime(SiddhiManager.java:76)
at io.siddhi.distribution.core.internal.StreamProcessorService.deploySiddhiApp(StreamProcessorService.java:69)
at io.siddhi.distribution.core.internal.StreamProcessorDeployer.deploySiddhiQLFile(StreamProcessorDeployer.java:92)
... 55 more
Suggested Labels:
type/improvement
Suggested Assignees:
@pcnfernando
Affected Product Version:
Siddhi v5.1.0
siddhi-io-nats v 2.0.6 extension
OS, DB, other environment details and versions:
Ubuntu 18.04 LTS
siddhi-runner v0.1.0
JDK 1.8.0-openjdk-amd64
Steps to reproduce:
Run TEST.siddhi using:
TEST.siddhi
@app:name("TEST")
@app:description("Test implementation for Nats and Protobuf in siddhi")
@info(name='Input stream from Nats + Protobuf publisher')
@source(type='nats', destination='channel1',@Map(type='protobuf', class='com.example.InputStream'))
define stream inputStream (timeStamp long, data int)
InputStream.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "com.example";
message InputStream {
uint64 timeStamp = 1;
uint32 data = 2;
}
- Generate Java sources from the InputStream.proto file
protoc InputStream.proto --java_out=./java-sources/
- Compile Java Sources to Java Classes
javac -cp ".:/home/$USER/siddhi-runner-0.1.0/bin/bootstrap/protobuf-java-3.9.1.jar" ./java-sources/com/example/* -d ./java-classes/
Note: protobuf-java-3.9.1.jar is passed to javac classpath for java source files to be compiled.
- Create jar file from java-classes
jar cvf com.example.jar -C java-classes .
-
Copy the generated jar file to the siddhi runner classpath, I was not able to load from /jars, so I copied to siddhi-runner-0.1.0/bin/bootstrap/com.example.jar (This is not the recommended way, maybe a separate issue)
-
Run siddhi:
./siddhi-runner-0.1.0/bin/runner.sh -Dapps=/path/to/TEST.siddhi
Will provide more details if needed.
Related Issues: