首页
学习
活动
专区
圈层
工具
发布

Siddhi
EN

Stack Overflow用户
提问于 2018-04-25 09:10:20
回答 1查看 491关注 0票数 3

这个问题是关于Siddhi - CEP的java库的。

描述:

我试图建立一个HTTP源来接收数据。创建运行时并启动它时没有错误。

代码语言:javascript
复制
[nioEventLoopGroup-2-1] INFO org.wso2.transport.http.netty.listener.ServerConnectorBootstrap$HTTPServerConnector - HTTP(S) Interface starting on host localhost and port 9056
[main] INFO org.wso2.extension.siddhi.io.http.source.HttpConnectorPortBindingListener - siddhi: started HTTP server connector localhost:9056
[main] INFO org.wso2.extension.siddhi.io.http.source.HttpSourceListener - Source Listener has created for url http://localhost:9056/endpoints/

但是,当我向指定的地址发送邮件请求时。我收到一个错误:

代码语言:javascript
复制
[nioEventLoopGroup-3-1] ERROR org.wso2.extension.siddhi.io.http.source.HTTPConnectorListener - Error in http server connector
java.lang.NoSuchMethodError: io.netty.handler.codec.http.HttpRequest.method()Lio/netty/handler/codec/http/HttpMethod;
    at org.wso2.transport.http.netty.listener.CustomHttpContentCompressor.decode(CustomHttpContentCompressor.java:44)
    at org.wso2.transport.http.netty.listener.CustomHttpContentCompressor.decode(CustomHttpContentCompressor.java:14)
    at io.netty.handler.codec.MessageToMessageCodec$2.decode(MessageToMessageCodec.java:81)
    at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:89)
    at io.netty.handler.codec.MessageToMessageCodec.channelRead(MessageToMessageCodec.java:111)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.handler.codec.ByteToMessageDecoder.fireChannelRead(ByteToMessageDecoder.java:276)
    at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:354)
    at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:244)
    at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:318)
    at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:304)
    at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:846)
    at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
    at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
    at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
    at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:112)
    at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137)
    at java.lang.Thread.run(Thread.java:748)

有人能提出我做错事的原因吗?提前谢谢你。

影响的产品版本: 4.1.17

OS,DB,其他环境详细信息和版本:

IntelliJ IDEA 2017.3.5 (社区版) Build #IC-173.4674.33,建于2018年3月6日,JRE: 1.8.0_152-release-1024-b15 amd64 JVM: OpenJDK 64位服务器VM,由JetBrains s.r.o Windows 10 10.0编写

复制步骤:,我编写的测试代码:

代码语言:javascript
复制
import org.wso2.siddhi.core.SiddhiAppRuntime;
import org.wso2.siddhi.core.SiddhiManager;
import org.wso2.siddhi.core.event.Event;
import org.wso2.siddhi.core.stream.output.StreamCallback;
import org.wso2.siddhi.core.util.EventPrinter;
//import org.wso2.extension.siddhi.io.http.source.*;

public class httpTest
{
    public static void main(String[] args) {
        String siddhiString = "@App:name(\"haha\") " +
                "@App:description(\"fasd\") " +
                "@App:statistics(reporter = \"jmx\", interval = \"30\") " +
                "@source(type=\"http\",receiver.url=\"http://localhost:9056/endpoints/\",@map(type=\"text\",fail.on.missing.attribute=\"true\",regex.A=\"(.*)\",@attributes(data=\"A\"))) " +
                "@sink(type=\"mqtt\",url=\"tcp://120.78.71.179:1883\",topic=\"34\",@map(type=\"text\")) " +
                "define stream a4P068X5YCK(data String);";
        SiddhiManager siddhiManager = new SiddhiManager();
        SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(siddhiString);

        siddhiAppRuntime.addCallback("a4P068X5YCK", new StreamCallback() {
            @Override
            public void receive(Event[] events) {
                EventPrinter.print(events);
            }
        });

        siddhiAppRuntime.start();
    }
}

然后我向http://localhost:9056/endpoints/发送一个帖子请求。它返回上面发布的异常。

更新:,我返回并检查了Siddhi-io-http github文档页。我发现上面写着:

..。此扩展仅在WSO2数据分析服务器中工作,不能单独运行。

我想这可能意味着目前siddhi库不支持http。我已经在siddhi存储库页面上提交了问题,以要求确认。

更新2:我已经更改了查询,以便将源流复制到其他接收器流中。守则的其他部分保持不变:

代码语言:javascript
复制
String siddhiString = "@App:name(\"haha\") " +
            "@App:description(\"fasd\") " +
            "@App:statistics(reporter = \"jmx\", interval = \"30\") " +
            "@source(type=\"http\",receiver.url=\"http://localhost:9056/endpoints/\",@map(type=\"text\",fail.on.missing.attribute=\"true\",regex.A=\"(.*)\",@attributes(data=\"A\"))) " +
            "define stream a4P068X5YCK(data String); " +
            "@sink(type=\"mqtt\",url=\"tcp://120.78.71.179:1883\",topic=\"34\",@map(type=\"text\")) " +
            "define stream pout(data String); " +
            "from a4P068X5YCK " +
            "select * " +
            "insert into pout; " +
            "";

同样的问题仍然存在。我试过wso2处理器,它运行良好。现在我的猜测是:

  1. 版本失配
  2. 缺少wso2处理器依赖的一些包。

我将尝试在这两个方向识别它,一旦我发现新的东西,我将在这里更新并发布页面。

更新3:在我不断添加更新时,格式似乎有一些问题,但幸运的是,这个问题也结束了。我试图包含来自wso2处理器源代码的所有依赖项,我的测试程序开始工作。因此,我假设wso2处理器中有一个缺少siddhi库的组件。

我试着一个一个地删除依赖项,看看我的测试程序是否还能工作。最后我找到了那个包裹。有了这个包,我的代码就能正常工作了。

代码语言:javascript
复制
    <dependency>
        <groupId>org.wso2.msf4j</groupId>
        <artifactId>org.wso2.msf4j.feature</artifactId>
        <version>${msf4j.version}</version>
            <type>zip</type>
    </dependency>

由于我是一个初学者,编码,我不是完全是什么问题。如果有人能向我解释问题的原因,我将不胜感激。我很感谢在这个过程中得到的所有帮助,这对我来说也是一次很棒的经历。

更新4: @Grainier --我试过了你发布的示例代码,它真的成功了!虽然我还是不知道为什么。我试图在我的项目中将您的确切代码复制到新的.java中。但还是没用的。因此,我想这与POM文件有关。

我注意到,在运行示例代码时,控制台中打印的警告很少:小更新:我发现出现警告是因为我使用的是JDK 10。一旦切换到1.8警告,代码仍然有效。所以也许这不是原因。

代码语言:javascript
复制
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by io.netty.util.internal.ReflectionUtil (file:/C:/Users/ktz001/.m2/repository/io/netty/netty-common/4.1.16.Final/netty-common-4.1.16.Final.jar) to constructor java.nio.DirectByteBuffer(long,int)
WARNING: Please consider reporting this to the maintainers of io.netty.util.internal.ReflectionUtil
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release

第二个区别是POM文件。与我的存储库相比,您还添加了一个存储库。

代码语言:javascript
复制
<repository>
        <id>wso2-nexus</id>
        <name>WSO2 internal Repository</name>
        <url>http://maven.wso2.org/nexus/content/groups/wso2-public/</url>
        <releases>
            <enabled>true</enabled>
            <updatePolicy>daily</updatePolicy>
            <checksumPolicy>ignore</checksumPolicy>
        </releases>
    </repository>

如果你能提出任何理由,那就太好了。谢谢你所有的工作!这真的很有帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-04-27 10:42:58

文件好像有问题..。这应该适用于独立的Siddhi。您所要做的就是在您的项目中添加以下依赖项(也是mqtt,我没有在下面介绍);

代码语言:javascript
复制
<dependencies>
    <dependency>
        <groupId>org.wso2.siddhi</groupId>
        <artifactId>siddhi-core</artifactId>
        <version>${siddhi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.siddhi</groupId>
        <artifactId>siddhi-annotations</artifactId>
        <version>${siddhi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.siddhi</groupId>
        <artifactId>siddhi-query-compiler</artifactId>
        <version>${siddhi.version}</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.extension.siddhi.io.http</groupId>
        <artifactId>siddhi-io-http</artifactId>
        <version>${siddhi.io.http.version}</version>
    </dependency>
    <dependency>
        <groupId>org.wso2.extension.siddhi.map.text</groupId>
        <artifactId>siddhi-map-text</artifactId>
        <version>${siddhi.mapper.text.version}</version>
    </dependency>
</dependencies>

但是,您的查询存在一个问题,即您已经将@source@sink定义为单个流。这是错误的。如果您想让它成为一个过路,那么您必须定义两个流(一个用于源流,一个用于接收器),并编写一个查询以从源流插入事件到接收器流。

更新:

一个示例可以找到这里;请尝试一下,看看它是否有效。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50018296

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档