gpt4 book ai didi

java - Siddhi HTTP NoSuchMethodError 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:08:35 26 4
gpt4 key购买 nike

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

描述:

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

[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/

但是,当我向指定地址发送POST请求时。我得到一个错误:

[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

操作系统、数据库、其他环境详细信息和版本:
IntelliJ IDEA 2017.3.5(社区版)构建 #IC-173.4674.33,构建于 2018 年 3 月 6 日JRE:1.8.0_152-release-1024-b15 amd64JVM:JetBrains s.r.o 的 OpenJDK 64 位服务器 VMWindows 10 10.0

重现步骤:我写的测试代码:

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/ 发送一个 POST 请求.它返回上面发布的异常。

更新:我回去查看 Siddhi-io-http github documentation page .我发现它说:

... This extension only works inside the WSO2 Data Analytic Server and cannot be run with standalone siddhi.

我想这可能表明 siddhi 库目前不支持 http。我已在 siddhi 存储库页面上提交问题以请求确认。

更新 2:我已经更改了我的 Siddhi 查询,以便它将源流复制到另一个接收器流中。代码的其他部分保持不变:

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 库。

我试着一个一个删除依赖,看看我的测试程序是否还能正常运行。最后我找到了那个包裹。有了这个包,我的代码运行良好。

    <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 警告消失了,代码仍然有效。所以也许这不是原因。

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 文件。与我相比,你多了一个仓库。

<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>

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

最佳答案

文档似乎有问题...这应该适用于独立的 Siddhi。您所要做的就是在您的项目中添加以下依赖项(还有 mqtt,我没有在下面包含);

<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 定义为单个流。这是错误的。如果你想让它成为直通,那么你必须定义两个流(一个用于源,一个用于接收器)并编写一个查询以将事件从源流插入到接收器流。

更新:

可以找到样本here ;请尝试一下,看看它是否有效。

关于java - Siddhi HTTP NoSuchMethodError 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50018296/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com