-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #527 from Particular/native-pub-sub-2
Native pub sub 2
- Loading branch information
Showing
73 changed files
with
2,201 additions
and
807 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/NServiceBus.SqlServer.AcceptanceTests/EndpointConfigurationExtensions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
using NServiceBus; | ||
using NServiceBus.Configuration.AdvancedExtensibility; | ||
|
||
public static class EndpointConfigurationExtensions | ||
{ | ||
public static TransportExtensions<SqlServerTransport> ConfigureSqlServerTransport(this EndpointConfiguration endpointConfiguration) | ||
{ | ||
return new TransportExtensions<SqlServerTransport>(endpointConfiguration.GetSettings()); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...erver.AcceptanceTests/MultiCatalog/When_custom_catalog_configured_for_legacy_publisher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
namespace NServiceBus.SqlServer.AcceptanceTests.MultiCatalog | ||
{ | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using AcceptanceTesting.Customization; | ||
using Configuration.AdvancedExtensibility; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
using Transport.SQLServer; | ||
|
||
public class When_custom_catalog_configured_for_legacy_publisher : MultiCatalogAcceptanceTest | ||
{ | ||
static string PublisherConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus1"); | ||
static string SubscriberConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus2"); | ||
static string PublisherEndpoint => Conventions.EndpointNamingConvention(typeof(LegacyPublisher)); | ||
|
||
[Test] | ||
public Task Should_receive_event() | ||
{ | ||
return Scenario.Define<Context>() | ||
.WithEndpoint<LegacyPublisher>(b => b.When(c => c.Subscribed, session => session.Publish(new Event()))) | ||
.WithEndpoint<Subscriber>(b => b.When(c => c.EndpointsStarted, s => s.Subscribe(typeof(Event)))) | ||
.Done(c => c.EventReceived) | ||
.Run(); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool EventReceived { get; set; } | ||
public bool Subscribed { get; set; } | ||
} | ||
|
||
class LegacyPublisher : EndpointConfigurationBuilder | ||
{ | ||
public LegacyPublisher() | ||
{ | ||
EndpointSetup<DefaultPublisher>(c => | ||
{ | ||
var transport = c.UseTransport<SqlServerTransport>(); | ||
transport.ConnectionString(PublisherConnectionString); | ||
|
||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo", "nservicebus"); | ||
transport.SubscriptionSettings().DisableSubscriptionCache(); | ||
|
||
c.GetSettings().Set("SqlServer.DisableNativePubSub", true); | ||
c.OnEndpointSubscribed<Context>((s, context) => | ||
{ | ||
if (s.SubscriberEndpoint.Contains(Conventions.EndpointNamingConvention(typeof(Subscriber)))) | ||
{ | ||
context.Subscribed = true; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
class Subscriber : EndpointConfigurationBuilder | ||
{ | ||
public Subscriber() | ||
{ | ||
EndpointSetup<DefaultServer>(b => | ||
{ | ||
var transport = b.UseTransport<SqlServerTransport>(); | ||
transport.ConnectionString(SubscriberConnectionString); | ||
|
||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo", "nservicebus"); | ||
|
||
transport.UseCatalogForEndpoint(PublisherEndpoint, "nservicebus1"); | ||
transport.EnableMessageDrivenPubSubCompatibilityMode().RegisterPublisher(typeof(Event), PublisherEndpoint); | ||
}); | ||
} | ||
|
||
class EventHandler : IHandleMessages<Event> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public Task Handle(Event message, IMessageHandlerContext context) | ||
{ | ||
Context.EventReceived = true; | ||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
|
||
public class Event : IEvent | ||
{ | ||
} | ||
} | ||
} |
81 changes: 81 additions & 0 deletions
81
...ceptanceTests/MultiCatalog/When_custom_catalog_configured_for_publisher_and_subscriber.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
namespace NServiceBus.SqlServer.AcceptanceTests.MultiCatalog | ||
{ | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using Features; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
using Transport.SQLServer; | ||
|
||
public class When_custom_catalog_configured_for_publisher_and_subscriber : MultiCatalogAcceptanceTest | ||
{ | ||
static string PublisherConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus1"); | ||
static string SubscriberConnectionString => WithCustomCatalog(GetDefaultConnectionString(), "nservicebus2"); | ||
|
||
[Test] | ||
public Task Should_receive_event() | ||
{ | ||
return Scenario.Define<Context>() | ||
.WithEndpoint<Publisher>(b => b.When(c => c.Subscribed, session => session.Publish(new Event()))) | ||
.WithEndpoint<Subscriber>(b => b.When(c => c.EndpointsStarted, async (s, ctx) => | ||
{ | ||
await s.Subscribe(typeof(Event)).ConfigureAwait(false); | ||
ctx.Subscribed = true; | ||
})) | ||
.Done(c => c.EventReceived) | ||
.Run(); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool EventReceived { get; set; } | ||
public bool Subscribed { get; set; } | ||
} | ||
|
||
class Publisher : EndpointConfigurationBuilder | ||
{ | ||
public Publisher() | ||
{ | ||
EndpointSetup<DefaultPublisher>(b => | ||
{ | ||
var transport = b.UseTransport<SqlServerTransport>(); | ||
transport.ConnectionString(PublisherConnectionString); | ||
|
||
transport.SubscriptionSettings().DisableSubscriptionCache(); | ||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo", "nservicebus"); | ||
}); | ||
} | ||
} | ||
|
||
class Subscriber : EndpointConfigurationBuilder | ||
{ | ||
public Subscriber() | ||
{ | ||
EndpointSetup<DefaultServer>(c => | ||
{ | ||
var transport = c.UseTransport<SqlServerTransport>(); | ||
|
||
transport.ConnectionString(SubscriberConnectionString); | ||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo", "nservicebus"); | ||
|
||
c.DisableFeature<AutoSubscribe>(); | ||
}); | ||
} | ||
|
||
class EventHandler : IHandleMessages<Event> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public Task Handle(Event message, IMessageHandlerContext context) | ||
{ | ||
Context.EventReceived = true; | ||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
|
||
public class Event : IEvent | ||
{ | ||
} | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...lServer.AcceptanceTests/MultiSchema/When_custom_schema_configured_for_legacy_publisher.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
namespace NServiceBus.SqlServer.AcceptanceTests.MultiSchema | ||
{ | ||
using System.Threading.Tasks; | ||
using AcceptanceTesting; | ||
using AcceptanceTesting.Customization; | ||
using Configuration.AdvancedExtensibility; | ||
using NServiceBus.AcceptanceTests; | ||
using NServiceBus.AcceptanceTests.EndpointTemplates; | ||
using NUnit.Framework; | ||
using Transport.SQLServer; | ||
|
||
public class When_custom_schema_configured_for_legacy_publisher : NServiceBusAcceptanceTest | ||
{ | ||
[Test] | ||
public Task Should_receive_event() | ||
{ | ||
return Scenario.Define<Context>() | ||
.WithEndpoint<LegacyPublisher>(b => b.When(c => c.Subscribed, session => session.Publish(new Event()))) | ||
.WithEndpoint<Subscriber>(b => b.When(c => c.EndpointsStarted, s => s.Subscribe(typeof(Event)))) | ||
.Done(c => c.EventReceived) | ||
.Run(); | ||
} | ||
|
||
class Context : ScenarioContext | ||
{ | ||
public bool EventReceived { get; set; } | ||
public bool Subscribed { get; set; } | ||
} | ||
|
||
class LegacyPublisher : EndpointConfigurationBuilder | ||
{ | ||
public LegacyPublisher() | ||
{ | ||
EndpointSetup<DefaultPublisher>(c => | ||
{ | ||
var transport = c.UseTransport<SqlServerTransport>(); | ||
transport.DefaultSchema("sender"); | ||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo"); | ||
transport.SubscriptionSettings().DisableSubscriptionCache(); | ||
|
||
c.GetSettings().Set("SqlServer.DisableNativePubSub", true); | ||
c.OnEndpointSubscribed<Context>((s, context) => | ||
{ | ||
if (s.SubscriberEndpoint.Contains(Conventions.EndpointNamingConvention(typeof(Subscriber)))) | ||
{ | ||
context.Subscribed = true; | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
|
||
class Subscriber : EndpointConfigurationBuilder | ||
{ | ||
public Subscriber() | ||
{ | ||
EndpointSetup<DefaultServer>(b => | ||
{ | ||
var publisherEndpoint = Conventions.EndpointNamingConvention(typeof(LegacyPublisher)); | ||
|
||
var transport = b.UseTransport<SqlServerTransport>(); | ||
transport.DefaultSchema("receiver").UseSchemaForEndpoint(publisherEndpoint, "sender"); | ||
transport.SubscriptionSettings().SubscriptionTableName("SubscriptionRouting", "dbo"); | ||
|
||
transport.EnableMessageDrivenPubSubCompatibilityMode().RegisterPublisher(typeof(Event), Conventions.EndpointNamingConvention(typeof(LegacyPublisher))); | ||
}); | ||
} | ||
|
||
class EventHandler : IHandleMessages<Event> | ||
{ | ||
public Context Context { get; set; } | ||
|
||
public Task Handle(Event message, IMessageHandlerContext context) | ||
{ | ||
Context.EventReceived = true; | ||
return Task.FromResult(0); | ||
} | ||
} | ||
} | ||
|
||
public class Event : IEvent | ||
{ | ||
} | ||
} | ||
} |
Oops, something went wrong.