Hazelcast EntryProcessor 不适用于 CompactSerialization

问题描述 投票:0回答:0

我正在尝试将 EntryProcessor 与 CompactSerialization 与 Hazelcast 5.2 版本一起使用,但出现以下错误:

Hazelcast.Protocol.RemoteException:'com.hazelcast.internal.serialization.impl.compact.DeserializedGenericRecord 无法转换为 com.hazelcast.map.EntryProcessor'

你能帮我指导一下我在这里缺少什么吗?是否需要从 hazelcast.config 端进行配置?

我的 .NET 客户端:

public class MyTest
{
    public int ID { get; set; }
    public bool IsGroupLevel { get; set; }
    public int ItemFormContext { get; set; }
    public MyTest() { }
    public MyTest(int id, bool isGroupLevel, int itemFormContext)
    {
        this.ID = id;
        this.IsGroupLevel = isGroupLevel;
        this.ItemFormContext = itemFormContext;
    }
}
public class MyTestSerializer : ICompactSerializer\<MyTest\>
{
    public string TypeName => "MyTest";

    public MyTest Read(ICompactReader reader)
    {
        var ID = reader.ReadInt32("ID");
        var IsGroupLevel = reader.ReadBoolean("IsGroupLevel");
        var ItemFormContext = reader.ReadInt32("ItemFormContext");
        return new MyTest(ID, IsGroupLevel, ItemFormContext);
    }

    public void Write(ICompactWriter writer, MyTest value)
    {
        writer.WriteInt32("ID", value.ID);
        writer.WriteBoolean("IsGroupLevel", value.IsGroupLevel);
        writer.WriteInt32("ItemFormContext", value.ItemFormContext);
    }
}

public class UpdateEntryProcessor : MyTestSerializer, IEntryProcessor<MyTest>
{
    private MyTest value;
    public UpdateEntryProcessor(MyTest value = null)
    {
        this.value = value;
    }
}

public class Program
{
    //Creating client
    var options = new HazelcastOptionsBuilder()
    .With(args)
    .WithDefault("hazelcast.networking.addresses.0", "\<ip address\>")   //Read Hazelcast server address from config file
    .WithDefault("hazelcast.clustername", "local")
    .WithDefault("hazelcast.socket.receive.buffer.size", "128")
    .WithDefault("hazelcast.socket.client.receive.buffer.size", "128")
    .WithDefault("hazelcast.socket.send.buffer.size", "128")
    .Build();
    options.Networking.ReconnectMode = Hazelcast.Networking.ReconnectMode.ReconnectSync;
    options.Serialization.Compact.AddSerializer(new MyTestSerializer());

    IHazelcastClient client = HazelcastClientFactory.StartNewClientAsync(options).GetAwaiter().GetResult();

    var vpmap = client.GetMapAsync\<int, MyTest\>("vpMap").GetAwaiter().GetResult();
    vpmap.SetAsync(1, new MyTest(1, false, 100)).GetAwaiter().GetResult();

    var r1 = vpmap.GetAsync(1).GetAwaiter().GetResult();

    //update using entry processor
    vpmap.ExecuteAsync(new UpdateEntryProcessor(r1), r1.ID).GetAwaiter().GetResult();
}

你能帮我指导一下我在这里缺少什么吗?是否需要从 hazelcast.config 端进行配置?

hazelcast hazelcast.net
© www.soinside.com 2019 - 2024. All rights reserved.