1
1
using System ;
2
2
using System . IO ;
3
- using System . Threading . Tasks ;
4
3
using Microsoft . Data . SqlClient ;
5
4
using Microsoft . Extensions . Hosting ;
6
5
using NServiceBus ;
7
6
using NServiceBus . Transport . SqlServer ;
8
7
9
- class Program
10
- {
11
-
12
- public static async Task Main ( string [ ] args )
8
+ var host = Host . CreateDefaultBuilder ( args )
9
+ . ConfigureServices ( ( hostContext , services ) => { Console . Title = "Server" ; } )
10
+ . UseNServiceBus ( x =>
13
11
{
14
- await CreateHostBuilder ( args ) . Build ( ) . RunAsync ( ) ;
15
- }
12
+ Console . Title = "Receiver" ;
16
13
17
- public static IHostBuilder CreateHostBuilder ( string [ ] args ) =>
18
- Host . CreateDefaultBuilder ( args )
19
- . ConfigureServices ( ( hostContext , services ) =>
20
- {
21
- Console . Title = "Server" ;
22
- } ) . UseNServiceBus ( x =>
23
- {
24
- Console . Title = "Receiver" ;
14
+ //for local instance or SqlExpress
15
+ //string connectionString = @"Data Source=(localdb)\mssqllocaldb;Database=NsbSamplesSqlOutbox;Trusted_Connection=True;MultipleActiveResultSets=true";
16
+ var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlOutbox;User Id=SA;Password=yourStrong(!)Password;Max Pool Size=100;Encrypt=false" ;
25
17
26
- //for local instance or SqlExpress
27
- //string connectionString = @"Data Source=(localdb)\mssqllocaldb;Database=NsbSamplesSqlOutbox;Trusted_Connection=True;MultipleActiveResultSets=true" ;
28
- var connectionString = @"Server=localhost,1433;Initial Catalog=NsbSamplesSqlOutbox;User Id=SA;Password=yourStrong(!)Password;Max Pool Size=100;Encrypt=false" ;
18
+ var endpointConfiguration = new EndpointConfiguration ( "Samples.SqlOutbox.Receiver" ) ;
19
+ endpointConfiguration . EnableInstallers ( ) ;
20
+ endpointConfiguration . SendFailedMessagesTo ( "error" ) ;
29
21
30
- var endpointConfiguration = new EndpointConfiguration ( "Samples.SqlOutbox.Receiver" ) ;
31
- endpointConfiguration . EnableInstallers ( ) ;
32
- endpointConfiguration . SendFailedMessagesTo ( "error" ) ;
22
+ #region ReceiverConfiguration
33
23
34
- #region ReceiverConfiguration
24
+ var transport = new SqlServerTransport ( connectionString )
25
+ {
26
+ DefaultSchema = "receiver" ,
27
+ TransportTransactionMode = TransportTransactionMode . ReceiveOnly
28
+ } ;
29
+ transport . SchemaAndCatalog . UseSchemaForQueue ( "error" , "dbo" ) ;
30
+ transport . SchemaAndCatalog . UseSchemaForQueue ( "audit" , "dbo" ) ;
35
31
36
- var transport = new SqlServerTransport ( connectionString )
37
- {
38
- DefaultSchema = "receiver" ,
39
- TransportTransactionMode = TransportTransactionMode . ReceiveOnly
40
- } ;
41
- transport . SchemaAndCatalog . UseSchemaForQueue ( "error" , "dbo" ) ;
42
- transport . SchemaAndCatalog . UseSchemaForQueue ( "audit" , "dbo" ) ;
32
+ var routing = endpointConfiguration . UseTransport ( transport ) ;
33
+ routing . UseSchemaForEndpoint ( "Samples.SqlOutbox.Sender" , "sender" ) ;
43
34
44
- var routing = endpointConfiguration . UseTransport ( transport ) ;
45
- routing . UseSchemaForEndpoint ( "Samples.SqlOutbox.Sender" , "sender" ) ;
35
+ var persistence = endpointConfiguration . UsePersistence < SqlPersistence > ( ) ;
36
+ persistence . ConnectionBuilder (
37
+ connectionBuilder : ( ) => new SqlConnection ( connectionString )
38
+ ) ;
39
+ var dialect = persistence . SqlDialect < SqlDialect . MsSqlServer > ( ) ;
40
+ dialect . Schema ( "receiver" ) ;
41
+ persistence . TablePrefix ( "" ) ;
46
42
47
- var persistence = endpointConfiguration . UsePersistence < SqlPersistence > ( ) ;
48
- persistence . ConnectionBuilder (
49
- connectionBuilder : ( ) =>
50
- {
51
- return new SqlConnection ( connectionString ) ;
52
- } ) ;
53
- var dialect = persistence . SqlDialect < SqlDialect . MsSqlServer > ( ) ;
54
- dialect . Schema ( "receiver" ) ;
55
- persistence . TablePrefix ( "" ) ;
43
+ transport . Subscriptions . DisableCaching = true ;
44
+ transport . Subscriptions . SubscriptionTableName = new SubscriptionTableName (
45
+ table : "Subscriptions" ,
46
+ schema : "dbo"
47
+ ) ;
56
48
57
- transport . Subscriptions . DisableCaching = true ;
58
- transport . Subscriptions . SubscriptionTableName = new SubscriptionTableName (
59
- table : "Subscriptions" ,
60
- schema : "dbo" ) ;
49
+ endpointConfiguration . EnableOutbox ( ) ;
61
50
62
- endpointConfiguration . EnableOutbox ( ) ;
51
+ endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
63
52
64
- endpointConfiguration . UseSerialization < SystemJsonSerializer > ( ) ;
53
+ #endregion
65
54
66
- #endregion
67
- SqlHelper . CreateSchema ( connectionString , "receiver" ) ;
55
+ SqlHelper . CreateSchema ( connectionString , "receiver" ) ;
68
56
69
- SqlHelper . ExecuteSql ( connectionString , File . ReadAllText ( "Startup.sql" ) ) ;
70
- return endpointConfiguration ;
71
- } ) ;
57
+ SqlHelper . ExecuteSql ( connectionString , File . ReadAllText ( "Startup.sql" ) ) ;
58
+ return endpointConfiguration ;
59
+ } )
60
+ . Build ( ) ;
72
61
73
62
74
- }
63
+ await host . RunAsync ( ) ;
0 commit comments