【问题标题】:Problem Deserializing Hazelcast Aggregator Response反序列化 Hazelcast 聚合器响应的问题
【发布时间】:2021-08-16 14:51:18
【问题描述】:

我编写了这个自定义聚合器,它的聚合响应是一个 HashMap。我在客户端反序列化器上遇到问题,在下面给出的错误中失败。任何线索可能是什么问题?

public class CountFixtureBySportAggregator extends Aggregator<HashMap.Entry<TraderVWFixtureKey, TraderVWFixture>, HashMap<Integer, Integer>> {

    private static final long serialVersionUID = 1L;

    private final HashMap<Integer, Set<String>> countBySportIdMap;

    public CountFixtureBySportAggregator() {countBySportIdMap = new HashMap<>();}

    @Override
    public void accumulate(HashMap.Entry<TraderVWFixtureKey, TraderVWFixture> input) {
        TraderVWFixture inputValue = input.getValue();
        Integer sportId = inputValue.getSportId();
        Set<String> matchIds = countBySportIdMap.getOrDefault(sportId, new HashSet<>());
        if (inputValue.getOutrightId() == null) {
            matchIds.add(inputValue.getMatchId());
        } else {
            matchIds.add(inputValue.getOutrightId());
        }
        countBySportIdMap.put(sportId, matchIds);
    }

    @Override
    public void combine(Aggregator aggregator) {
        CountFixtureBySportAggregator countFixtureBySportAggregator = (CountFixtureBySportAggregator) aggregator;
        Map<Integer, Set<String>> sportCountMap = countFixtureBySportAggregator.getCountBySportIdMap();
        for (Map.Entry<Integer, Set<String>> entry : sportCountMap.entrySet()) {
            Integer key = entry.getKey();
            countBySportIdMap.computeIfAbsent(key, integer -> new HashSet<>());
            countBySportIdMap.get(key).addAll(entry.getValue());
        }
    }

    @Override
    public HashMap<Integer, Integer> aggregate() {
        return new HashMap(countBySportIdMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getKey, v -> v.getValue().size())));
    }

    public HashMap<Integer, Set<String>> getCountBySportIdMap() { return countBySportIdMap; }
}

客户端反序列化错误:

com.hazelcast.nio.serialization.HazelcastSerializationException: There is no suitable de-serializer for type -322. This exception is likely to be caused by differences in the serialization configuration between members or between clients and members.
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.newHazelcastSerializationException(AbstractSerializationService.java:238)
    at com.hazelcast.internal.serialization.impl.AbstractSerializationService.toObject(AbstractSerializationService.java:182)
    at com.hazelcast.client.spi.ClientProxy.toObject(ClientProxy.java:102)
    at com.hazelcast.client.proxy.ClientMapProxy.aggregate(ClientMapProxy.java:1543)

【问题讨论】:

标签: java serialization hazelcast hazelcast-jet


【解决方案1】:

我发现了问题所在。我正在使用不支持 HashMap 序列化的 hazelcast:3.12.3 依赖项,请参阅:Hazelcast 3.12 Documentation。 问题是服务器有hazelcast.jet:hazelcast-jet:3.2 依赖,所以对于服务器端的HashMap 序列化,它使用了这个被标记为-322 类型的序列化器:com.hazelcast.jet.impl.serialization.HashMapHook。但是由于客户端不依赖 hazelcast jet 模块,它没有找到这个序列化器,因此在反序列化获取的响应时会抛出这个错误。

解决方案是在客户端添加 jet 依赖。替代方法也可以将 hazelcast 版本增加到 4.x.x,因为该版本支持 HashMap 序列化。

【讨论】:

    猜你喜欢
    • 2014-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多