我希望在Windows 10上使用C#和Apache Ignite 2.4来实现多个复制节点,每个节点都有一个自定义CacheStoreFactory。我希望每当缓存条目更改时都将调用每个节点的CacheStoreFactory。下面的代码示例将输出为我期望的CacheMode.Partitioned行为。对于CacheMode.Replicated,我希望每个cache.Put操作都有两条输出线(因为正在运行两个节点)。我怎样才能做到这一点?
输出
Node count: 2
Started..
Write 0-0 by 63642613
Write 1-1 by 12036987
Write 2-2 by 63642613
Write 3-3 by 12036987
Write 4-4 by 63642613
Write 5-5 by 63642613
Write 6-6 by 12036987
Write 7-7 by 63642613
Write 8-8 by 12036987
Write 9-9 by 12036987
Finished count1:10 count2:10
样例代码
class Program
{
static void Main(string[] args)
{
var config = new IgniteConfiguration()
{
IgniteInstanceName = "A",
CacheConfiguration = new List<CacheConfiguration>
{
new CacheConfiguration("mycache",new QueryEntity(typeof(int), typeof(int)))
{
CacheMode = CacheMode.Replicated,
WriteThrough = true,
CacheStoreFactory = new StoreFactory(),
},
},
};
var ignite1 = Ignition.Start(config);
config.IgniteInstanceName = "B";
var ignite2 = Ignition.Start(config);
Console.WriteLine("Node count: " + ignite1.GetCluster().GetNodes().Count);
ignite1.GetCluster().SetActive(true);
var mycache1 = ignite1.GetCache<int, int>("mycache");
var mycache2 = ignite2.GetCache<int, int>("mycache");
Console.WriteLine("Started..");
for (int i = 0; i < 10; i++)
{
mycache1.Put(i, i);
}
Console.WriteLine($"Finished count1:{mycache1.Count()} count2:{mycache2.Count()}");
Console.ReadLine();
ignite1.Dispose();
ignite2.Dispose();
}
相关分类