|
| 1 | +using System; |
| 2 | +using System.Threading.Tasks; |
| 3 | +using Microsoft.Extensions.Hosting; |
| 4 | +using NServiceBus; |
| 5 | +using Raven.Client.Documents; |
| 6 | +using Raven.Client.Exceptions; |
| 7 | +using Raven.Client.ServerWide; |
| 8 | +using Raven.Client.ServerWide.Operations; |
| 9 | + |
| 10 | + |
| 11 | +Console.Title = "Server"; |
| 12 | + |
| 13 | +var builder = Host.CreateApplicationBuilder(args); |
| 14 | + |
| 15 | +#region Config |
| 16 | + |
| 17 | +var endpointConfiguration = new EndpointConfiguration("Samples.RavenDB.Server"); |
| 18 | +using var documentStore = new DocumentStore |
| 19 | +{ |
| 20 | + Urls = ["http://localhost:8080"], |
| 21 | + Database = "RavenSimpleSample", |
| 22 | +}; |
| 23 | + |
| 24 | +documentStore.Initialize(); |
| 25 | + |
| 26 | +var persistence = endpointConfiguration.UsePersistence<RavenDBPersistence>(); |
| 27 | +persistence.SetDefaultDocumentStore(documentStore); |
| 28 | + |
| 29 | +#endregion |
| 30 | + |
| 31 | +var outbox = endpointConfiguration.EnableOutbox(); |
| 32 | +outbox.SetTimeToKeepDeduplicationData(TimeSpan.FromMinutes(5)); |
| 33 | + |
| 34 | +var transport = new LearningTransport |
| 35 | +{ |
| 36 | + TransportTransactionMode = TransportTransactionMode.ReceiveOnly |
| 37 | +}; |
| 38 | +endpointConfiguration.UseSerialization<SystemJsonSerializer>(); |
| 39 | +endpointConfiguration.UseTransport(transport); |
| 40 | + |
| 41 | +await EnsureDatabaseExists(documentStore); |
| 42 | + |
| 43 | +Console.WriteLine("Starting..."); |
| 44 | + |
| 45 | +builder.UseNServiceBus(endpointConfiguration); |
| 46 | +await builder.Build().RunAsync(); |
| 47 | + |
| 48 | +static async Task EnsureDatabaseExists(DocumentStore documentStore) |
| 49 | +{ |
| 50 | + // create the database |
| 51 | + try |
| 52 | + { |
| 53 | + await documentStore.Maintenance.Server.SendAsync(new CreateDatabaseOperation(new DatabaseRecord(documentStore.Database))); |
| 54 | + } |
| 55 | + catch (ConcurrencyException) |
| 56 | + { |
| 57 | + // intentionally ignored |
| 58 | + } |
| 59 | +} |
0 commit comments