简体   繁体   English

Hazelcast地图条目侦听器不是来自Spring

[英]Hazelcast map entry listener does not from Spring

I am trying to configure Hazelcast map to use entry listener using Spring. 我正在尝试将Hazelcast映射配置为使用Spring使用条目侦听器。 However, I see that it does not work (events are not coming to the listener). 但是,我看到它不起作用(事件没有传给侦听器)。

My entry listener: 我的条目监听器:

public class MyMapListener extends EntryAdapter<String, String> implements MapListener{
    @Override
    public void onEntryEvent(EntryEvent<String, String> event) {
        EntryEventType type = event.getEventType();
        System.out.println("Event type: " + type);
    }
}

My Spring application context: 我的Spring应用程序上下文:

<hz:hazelcast id="instance">
    <hz:config>
        <hz:group name="dev" password="password"/>
        <hz:properties>
            <hz:property name="hazelcast.merge.first.run.delay.seconds">5</hz:property>
            <hz:property name="hazelcast.merge.next.run.delay.seconds">5</hz:property>
        </hz:properties>
        <hz:network port="5705" port-auto-increment="true">
            <hz:join>
                <hz:multicast enabled="true"/>
            </hz:join>
        </hz:network>
        <hz:map name="myMap" >
            <hz:entry-listeners>
                <hz:entry-listener class-name="rw.gov.dgie.bms.hazelcast.listener.map.MyMapListener" include-value="true"/>
                <hz:entry-listener implementation="myMapListener" local="true"/>
            </hz:entry-listeners>
        </hz:map>
    </hz:config>
</hz:hazelcast>

<hz:client id="client">
    <hz:group name="dev" password="password"/>
    <hz:network>
        <hz:member>127.0.0.1:5705</hz:member>
    </hz:network>
</hz:client>

<bean class="rw.gov.dgie.bms.hazelcast.listener.map.MyMapListener" name="myMapListener"/>

<hz:map id="myMap" instance-ref="instance" name="MyMap" lazy-init="false"/>

When I add the listener to injected map from Java code, it works fine: 当我将侦听器添加到从Java代码注入的映射中时,它可以正常工作:

@Autowired
private IMap myMap;

myMap.addEntryListener((MapListener)new MyMapListener(), true);

What did I do wrong? 我做错了什么?

Change 更改

<hz:map id="myMap" instance-ref="instance" name="MyMap" lazy-init="false"/>

to

<hz:map id="myMap" instance-ref="instance" name="myMap" lazy-init="false"/>

The id is the bean name, the name is the map name. id是bean名称, name是地图名称。

In the top section of the original code, the listener here 在原始代码的顶部,这里的监听器

<hz:map name="myMap">
   <hz:entry-listeners>

is added to a map named " myMap " and the bean at the bottom references a map named " MyMap ". 将被添加到名为“ myMap ”的地图,底部的Bean引用了名为“ MyMap ”的地图。 So two different maps due to the capitalisation of M on one and not the other. 因此,由于M在一个而不是另一个上的大写,因此产生了两个不同的图。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM