This repository has been archived by the owner on Nov 8, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 145
/
Program.cs
127 lines (125 loc) · 5.11 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Orleans;
using Orleans.Configuration;
using Orleans.Hosting;
using Ray.Core;
using Ray.EventBus.RabbitMQ;
using Ray.Grain;
using Ray.Grain.EventHandles;
using Ray.Storage.Mongo;
using Ray.Storage.MySQL;
using Ray.Storage.PostgreSQL;
namespace Ray.MongoHost
{
class Program
{
static int Main(string[] args)
{
return RunMainAsync().Result;
}
private static async Task<int> RunMainAsync()
{
try
{
using (var host = await StartSilo())
{
while (true)
{
Console.WriteLine("Input any key to stop");
Console.ReadLine();
await host.StopAsync();
Console.WriteLine("Input any key to Start");
Console.ReadLine();
await host.StartAsync();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex);
return 1;
}
}
private static async Task<ISiloHost> StartSilo()
{
var builder = new SiloHostBuilder()
.UseLocalhostClustering()
.UseDashboard()
.AddRay<Configuration>()
.Configure<EndpointOptions>(options => options.AdvertisedIPAddress = IPAddress.Loopback)
.ConfigureApplicationParts(parts => parts.AddApplicationPart(typeof(Account).Assembly).WithReferences())
.ConfigureServices((context, servicecollection) =>
{
//注册postgresql为事件存储库
servicecollection.AddPostgreSQLStorage(config =>
{
config.ConnectionDict.Add("core_event", "Server=127.0.0.1;Port=5432;Database=Ray;User Id=postgres;Password=extop;Pooling=true;MaxPoolSize=20;");
});
servicecollection.AddPostgreSQLTxStorage(options =>
{
options.ConnectionKey = "core_event";
options.TableName = "Transaction_TemporaryRecord";
});
servicecollection.PSQLConfigure();
//注册mysql作为事件存储库
//servicecollection.AddMySQLStorage(config =>
//{
// config.ConnectionDict.Add("core_event", "Server=127.0.0.1;Port=3306;Database=ray;User Id=root;Password=extop;Pooling=true;MaxPoolSize=20;");
//});
//servicecollection.AddMySQLTxStorage(options =>
//{
// options.ConnectionKey = "core_event";
// options.TableName = "Transaction_TemporaryRecord";
//});
//servicecollection.MySQLConfigure();
//注册mongodb为事件存储库
//servicecollection.AddMongoDBStorage(config =>
//{
// config.ConnectionDict.Add("core", "mongodb://127.0.0.1:27017");
//});
//servicecollection.AddMongoTransactionStorage(options =>
//{
// options.ConnectionKey = "core";
// options.CollectionName = "Transaction_TemporaryRecord";
//});
//servicecollection.MongoConfigure();
servicecollection.AddRabbitMQ(config =>
{
config.UserName = "admin";
config.Password = "admin";
config.Hosts = new[] { "127.0.0.1:5672" };
config.MaxPoolSize = 100;
config.VirtualHost = "/";
});
//servicecollection.AddRabbitMQ(config =>
//{
// config.UserName = "admin";
// config.Password = "admin";
// config.Hosts = new[] { "127.0.0.1:5672" };
// config.MaxPoolSize = 100;
// config.VirtualHost = "/";
//}, async container =>
//{
// await container.CreateEventBus<Account>("Account", "account", 5).DefaultConsumer<long>();
//});
})
.Configure<GrainCollectionOptions>(options =>
{
options.CollectionAge = TimeSpan.FromMinutes(5);
})
.ConfigureLogging(logging =>
{
logging.SetMinimumLevel(LogLevel.Information);
logging.AddConsole(options => options.IncludeScopes = true);
});
var host = builder.Build();
await host.StartAsync();
return host;
}
}
}