无法通过 EsperIOSocketAdapter 接收事件
我试图通过套接字将事件发送到 Esper 引擎,但遇到了一些问题。
我已经配置了 EsperIOSocketAdapter 属性,当调用 EsperIOSocketAdapter.start() 方法时,它会启动一个新的守护线程,该线程将侦听客户端,但在套接字客户端实际尝试连接之前,守护线程会随着父线程退出而退出。
我的代码片段如下:
ConfigurationSocketAdapter adapterConfig = new ConfigurationSocketAdapter();
SocketConfig socket = new SocketConfig();
socket.setDataType(DataType.CSV);
socket.setPort(6789);
adapterConfig.getSockets().put("CourseSocket", socket);
EsperIOSocketAdapter socketAdapter = new EsperIOSocketAdapter (adapterConfig, "CourseSocket");
socketAdapter.start();
另一个疑问是在没有使用 SocketAdapter 的程序中,我曾经通过代码
EPRuntime.sendEvent(new TestEvent(event)); 发送事件;
使用 SocketAdapter 时,我应该使用 sendEvent() ,否则事件将自动推送到引擎中。
I'm trying to send Events to the Esper engine through sockets and ran into some problem.
i've configured the EsperIOSocketAdapter properties and when EsperIOSocketAdapter.start() method is invoked , it starts a new daemon thread which will listen for clients , but daemon thread exits as parent thread exits before a socket client actually tries to connect.
my code snippet is as follows:
ConfigurationSocketAdapter adapterConfig = new ConfigurationSocketAdapter();
SocketConfig socket = new SocketConfig();
socket.setDataType(DataType.CSV);
socket.setPort(6789);
adapterConfig.getSockets().put("CourseSocket", socket);
EsperIOSocketAdapter socketAdapter = new EsperIOSocketAdapter (adapterConfig, "CourseSocket");
socketAdapter.start();
Another doubt is in programs without using the SocketAdapter i used to send events through the code
EPRuntime.sendEvent(new TestEvent(event));
While using SocketAdapter, shoud i use sendEvent() or events will automatically pushed into the engine.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的套接字问题似乎具有一般性,其中 JVM 正在终止,因为您没有运行任何非守护线程。将父线程(或套接字线程)设置为非守护线程,JVM 将不会终止。 (确保您实际上可以停止线程,否则您的 JVM 将顽固地关闭:))
当您使用 SocketAdapter 时,您的“发送客户端”对于物理 EPRuntime 是远程的,但您使用远程套接字通过 EPRuntime 发送事件。套接字,如 文档。
Your socket problem seems to be of a generic nature where the JVM is terminating because you do not have any non-daemon threads running. Make the parent thread (or the socket thread) a non-daemon thread and the JVM will not terminate. (Make sure you can actually stop the thread or your JVM will be stubborn about shutting down :) )
When you use the SocketAdapter, your "sending client" is remote to the physical EPRuntime, but you use the remote socket to send events over the socket, as outlined in the docs.