Apache Ignite:客户端和服务器配置
Apache Ignite : Client and Server Configuration
我有一个基于https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/examples/ServerNode/Program.cs
中提到的示例的服务器节点
同样在另一个过程中,我有一个“ClientMode = true”的客户端,如下所示。
return new IgniteConfiguration(GetServerNodeConfiguration())
{
ClientMode = true
};
缓存将保存“Employee”的信息class,我正在使用 IBinarySerializer 序列化“Employee”和“Address”classes,并将序列化器添加到IgniteConfiguration 如下...
IgniteConfiguration.BinaryConfiguration = new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration>
{
new(typeof(Employee)){Serializer = new EmployeeSerializer()},
new(typeof(Address)){Serializer = new AddressSerializer()},
}
}
我的问题是...
- 我们是否需要在服务器和客户端代码中都包含“员工”和“地址”class?或者我只是在客户端提及它们?
- 我们是否需要在服务器和客户端代码上的 ignite BinaryConfiguration 中使用 IBinarySerializer 序列化程序?还是我只是在客户端提及它们?
员工
public class Employee
{
public Guid EmployeeId { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
地址
public class Address
{
public string Street { get; set; }
public string Zip { get; set; }
}
IBinarySerializer 实现
public sealed class EmployeeSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var employee = (Employee)obj;
writer.WriteGuid("employeeId", employee.EmployeeId );
writer.WriteString("name", employee.Name);
writer.WriteObject("address", employee.Address);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var employee = (employee)obj;
employee.EmployeeId = reader.ReadObject<Guid>("employeeId");
employee.Name = reader.ReadString("name");
employee.Address = reader.ReadObject<Address>("address");
}
}
public sealed class AddressSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var address = (Address)obj;
writer.WriteString("street", address.Street);
writer.WriteString("zip", address.Zip);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var address = (Address)obj;
address.Street = reader.ReadString("street");
address.Zip = reader.ReadString("zip");
}
}
简而言之,是的,您需要每个节点上的此信息。
双方都必须知道如何正确反序列化和序列化记录。
尽管可以使用 BinaryObjectBuilder
在没有显式模型定义的情况下直接在二进制模式下工作。定义自定义 IBinarySerializer
也不是强制性的,除非您有一些定义了数十个字段的大型模型,否则内部序列化程序将足够好。
我有一个基于https://github.com/apache/ignite/blob/master/modules/platforms/dotnet/examples/ServerNode/Program.cs
中提到的示例的服务器节点同样在另一个过程中,我有一个“ClientMode = true”的客户端,如下所示。
return new IgniteConfiguration(GetServerNodeConfiguration())
{
ClientMode = true
};
缓存将保存“Employee”的信息class,我正在使用 IBinarySerializer 序列化“Employee”和“Address”classes,并将序列化器添加到IgniteConfiguration 如下...
IgniteConfiguration.BinaryConfiguration = new BinaryConfiguration
{
TypeConfigurations = new List<BinaryTypeConfiguration>
{
new(typeof(Employee)){Serializer = new EmployeeSerializer()},
new(typeof(Address)){Serializer = new AddressSerializer()},
}
}
我的问题是...
- 我们是否需要在服务器和客户端代码中都包含“员工”和“地址”class?或者我只是在客户端提及它们?
- 我们是否需要在服务器和客户端代码上的 ignite BinaryConfiguration 中使用 IBinarySerializer 序列化程序?还是我只是在客户端提及它们?
员工
public class Employee
{
public Guid EmployeeId { get; set; }
public string Name { get; set; }
public Address Address { get; set; }
}
地址
public class Address
{
public string Street { get; set; }
public string Zip { get; set; }
}
IBinarySerializer 实现
public sealed class EmployeeSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var employee = (Employee)obj;
writer.WriteGuid("employeeId", employee.EmployeeId );
writer.WriteString("name", employee.Name);
writer.WriteObject("address", employee.Address);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var employee = (employee)obj;
employee.EmployeeId = reader.ReadObject<Guid>("employeeId");
employee.Name = reader.ReadString("name");
employee.Address = reader.ReadObject<Address>("address");
}
}
public sealed class AddressSerializer : IBinarySerializer
{
public void WriteBinary(object obj, IBinaryWriter writer)
{
var address = (Address)obj;
writer.WriteString("street", address.Street);
writer.WriteString("zip", address.Zip);
}
public void ReadBinary(object obj, IBinaryReader reader)
{
var address = (Address)obj;
address.Street = reader.ReadString("street");
address.Zip = reader.ReadString("zip");
}
}
简而言之,是的,您需要每个节点上的此信息。 双方都必须知道如何正确反序列化和序列化记录。
尽管可以使用 BinaryObjectBuilder
在没有显式模型定义的情况下直接在二进制模式下工作。定义自定义 IBinarySerializer
也不是强制性的,除非您有一些定义了数十个字段的大型模型,否则内部序列化程序将足够好。