I am trying to configure Hazelcast map to use entry listener using 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:
<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:
@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.
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 ". So two different maps due to the capitalisation of M on one and not the other.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.