Java Apache Ignite 事件侦听器意外行为
Java Apache Ignite event listner unexpected behavior
我玩过 Ignite 微服务示例 https://github.com/dmagda/MicroServicesExample。我添加了一个事件监听器,并明确订阅了一个特定的缓存
数据节点-config.xml:
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="includeEventTypes">
<util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/>
</property>
DataNodeStartup.java:
ignite.events(ignite.cluster().forCacheNodes("vehicles")).remoteListen(locLsnr, rmtLsnr,
EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
但我总是捕捉到另一个缓存“维护”的意外事件。
是 forCacheNodes("vehicles") 不起作用还是我配置错误?
更新:
我正在收听这样的活动
IgnitePredicate<CacheEvent> rmtLsnr = new IgnitePredicate<CacheEvent>() {
@Override
public boolean apply(CacheEvent evt) {
System.out.println("Cache event [name=" + evt.name() + ", newValue : " + evt.newValue() + "]");
return true;
}
};
这是预期的行为。如果您想监听来自特定缓存的事件,您可以在远程过滤器中执行此操作。
您的侦听器不只是侦听特定缓存的事件。它从你的缓存所在的节点监听指定类型的所有事件,这不是一回事。
我玩过 Ignite 微服务示例 https://github.com/dmagda/MicroServicesExample。我添加了一个事件监听器,并明确订阅了一个特定的缓存
数据节点-config.xml:
<bean class="org.apache.ignite.configuration.IgniteConfiguration">
<property name="includeEventTypes">
<util:constant static-field="org.apache.ignite.events.EventType.EVTS_CACHE"/>
</property>
DataNodeStartup.java:
ignite.events(ignite.cluster().forCacheNodes("vehicles")).remoteListen(locLsnr, rmtLsnr,
EVT_CACHE_OBJECT_PUT, EVT_CACHE_OBJECT_READ, EVT_CACHE_OBJECT_REMOVED);
但我总是捕捉到另一个缓存“维护”的意外事件。
是 forCacheNodes("vehicles") 不起作用还是我配置错误?
更新:
我正在收听这样的活动
IgnitePredicate<CacheEvent> rmtLsnr = new IgnitePredicate<CacheEvent>() {
@Override
public boolean apply(CacheEvent evt) {
System.out.println("Cache event [name=" + evt.name() + ", newValue : " + evt.newValue() + "]");
return true;
}
};
这是预期的行为。如果您想监听来自特定缓存的事件,您可以在远程过滤器中执行此操作。
您的侦听器不只是侦听特定缓存的事件。它从你的缓存所在的节点监听指定类型的所有事件,这不是一回事。