0

I have two spring-boot services that talk to each other through a caching layer ( because of reasons not related with the issue ). I am using JCache (jsr-107) api to abstract away the actual cache provider, in this case Hazelcast. I am manually registering a few cache event listeners (update, create and delete ) and consuming those events to perform some actions.

A simple use case would be service A consuming a CacheEntryUpdatedListener event that service B created by pushing some data to a particular cache. When I start service A. it's starts correctly and creates it's own Hazelcast cluster node. When service B is attempting to join that Hazelcast node, it finds it correctly but then gets immediately disconnected, and I get a java.io.NotSerializableException:c.i.c.e.i.b.ws.m.cache.listener.MarketStateRefreshListener, MarketStateRefreshListener is a cache event listener, why would Hazelcast attempt to persist it, those listeners make no sense outside of service B, there is no point in them being saved to the IMDG ? Am I fundamentally missunderstanding how Hazelcast clusters work ?

Here is the hazelcast config ( used by both services ):

<hazelcast
        xsi:schemaLocation="http://www.hazelcast.com/schema/config hazelcast-config-3.10.xsd"
        xmlns="http://www.hazelcast.com/schema/config" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

    <group>
        <name>cache_group_name</name>
    </group>

    <network>
        <port>5701</port>
        <join>
            <multicast/>
        </join>
    </network>

    <cache name="cache_name_1">
        <!--<management-enabled>true</management-enabled>-->
        <!--<backup-count>3</backup-count>-->
    </cache>
    <cache name="cache_name_2"/>
    <cache name="cache_name_3"/>
</hazelcast>

I am using JCache so the update cache events are handled by a javax.cache.event.CacheEntryUpdatedListener instance . One such a class is :

@Slf4j
@Component
@AllArgsConstructor
public class MarketSummaryStateUpdatedListener implements CacheEntryUpdatedListener<String, MarketSummaryState> {

    private CacheEventService eventService;

    @Override
    public void onUpdated(Iterable<CacheEntryEvent<? extends String, ? extends MarketSummaryState>> events)
            throws CacheEntryListenerException {
        events.forEach( event -> {
           eventService.fireEvent(MARKET_STATE, event.getEventType(), EventData.of(event.getValue()));
        });
    }

}

The even listener is a spring @Component and so is private CacheEventService eventService;

Regards,
Peter

pmanolov
  • 623
  • 1
  • 6
  • 19

0 Answers0