-
Notifications
You must be signed in to change notification settings - Fork 300
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 #5136 from Particular/aspv4
- Loading branch information
Showing
93 changed files
with
1,933 additions
and
43 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
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 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<TargetFramework>net48</TargetFramework> | ||
<LangVersion>7.3</LangVersion> | ||
<RootNamespace>ASP_3</RootNamespace> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<PackageReference Include="NServiceBus.Persistence.AzureTable" Version="4.0.0-alpha.335" /> | ||
</ItemGroup> | ||
</Project> |
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,79 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using NServiceBus; | ||
using NServiceBus.Persistence.AzureTable; | ||
using NServiceBus.Pipeline; | ||
|
||
#region ITransportReceiveContextBehavior | ||
class PartitionKeyTransportReceiveContextBehavior | ||
: Behavior<ITransportReceiveContext> | ||
{ | ||
public override async Task Invoke(ITransportReceiveContext context, Func<Task> next) | ||
{ | ||
context.Extensions.Set(new TableEntityPartitionKey("PartitionKeyValue")); | ||
|
||
await next().ConfigureAwait(false); | ||
} | ||
} | ||
#endregion | ||
|
||
#region IIncomingLogicalMessageContextBehavior | ||
class PartitionKeyIncomingLogicalMessageContextBehavior | ||
: Behavior<IIncomingLogicalMessageContext> | ||
{ | ||
public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next) | ||
{ | ||
context.Extensions.Set(new TableEntityPartitionKey("PartitionKeyValue")); | ||
|
||
await next().ConfigureAwait(false); | ||
} | ||
} | ||
#endregion | ||
|
||
#region InsertBeforeLogicalOutbox | ||
public class RegisterMyBehavior : RegisterStep | ||
{ | ||
public RegisterMyBehavior() : | ||
base(stepId: nameof(PartitionKeyIncomingLogicalMessageContextBehavior), | ||
behavior: typeof(PartitionKeyIncomingLogicalMessageContextBehavior), | ||
description: "Determines the PartitionKey from the logical message", | ||
factoryMethod: b => new PartitionKeyIncomingLogicalMessageContextBehavior()) | ||
{ | ||
InsertBeforeIfExists(nameof(LogicalOutboxBehavior)); | ||
} | ||
} | ||
#endregion | ||
|
||
#region CustomTableNameUsingITransportReceiveContextBehavior | ||
|
||
class ContainerInfoTransportReceiveContextBehavior | ||
: Behavior<ITransportReceiveContext> | ||
{ | ||
public override async Task Invoke(ITransportReceiveContext context, Func<Task> next) | ||
{ | ||
context.Extensions.Set( | ||
new TableInformation( | ||
tableName: "tableName")); | ||
|
||
await next().ConfigureAwait(false); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
#region CustomTableNameUsingIIncomingLogicalMessageContextBehavior | ||
|
||
class ContainerInfoLogicalReceiveContextBehavior | ||
: Behavior<IIncomingLogicalMessageContext> | ||
{ | ||
public override async Task Invoke(IIncomingLogicalMessageContext context, Func<Task> next) | ||
{ | ||
context.Extensions.Set( | ||
new TableInformation( | ||
tableName: "tableName")); | ||
|
||
await next().ConfigureAwait(false); | ||
} | ||
} | ||
|
||
#endregion |
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,45 @@ | ||
using Microsoft.Azure.Cosmos.Table; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NServiceBus; | ||
using NServiceBus.Persistence.AzureTable; | ||
|
||
#region CustomClientProvider | ||
|
||
class CustomTableClientProvider | ||
: IProvideCloudTableClient | ||
{ | ||
// get fully configured via DI container | ||
public CustomTableClientProvider(CloudTableClient tableClient) | ||
{ | ||
Client = tableClient; | ||
} | ||
public CloudTableClient Client { get; } | ||
} | ||
|
||
// optionally when subscriptions used | ||
class CustomSubscriptionTableClientProvider | ||
: IProvideCloudTableClientForSubscriptions | ||
{ | ||
// get fully configured via DI container | ||
public CustomSubscriptionTableClientProvider(CloudTableClient tableClient) | ||
{ | ||
Client = tableClient; | ||
} | ||
public CloudTableClient Client { get; } | ||
} | ||
#endregion | ||
|
||
class CustomClientProviderRegistration | ||
{ | ||
public CustomClientProviderRegistration(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region CustomClientProviderRegistration | ||
|
||
endpointConfiguration.RegisterComponents(services => services.AddSingleton<CustomTableClientProvider>()); | ||
|
||
// optionally when subscriptions used | ||
endpointConfiguration.RegisterComponents(services => services.AddSingleton<CustomSubscriptionTableClientProvider>()); | ||
|
||
#endregion | ||
} | ||
} |
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,106 @@ | ||
using System; | ||
using System.Threading.Tasks; | ||
using Microsoft.Azure.Cosmos.Table; | ||
using NServiceBus; | ||
using NServiceBus.Persistence.AzureTable; | ||
|
||
class MyMessage | ||
{ | ||
public string ItemId { get; set; } | ||
} | ||
|
||
class UsageHandler : IHandleMessages<MyMessage> | ||
{ | ||
#region HandlerSharedTransaction | ||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
var session = context.SynchronizedStorageSession.AzureTablePersistenceSession(); | ||
|
||
var test1 = new ToDoActivity { PartitionKey = session.PartitionKey, RowKey = Guid.NewGuid().ToString() }; | ||
var test2 = new ToDoActivity { PartitionKey = session.PartitionKey, RowKey = Guid.NewGuid().ToString() }; | ||
var test3 = new ToDoActivity { PartitionKey = session.PartitionKey, RowKey = Guid.NewGuid().ToString() }; | ||
var test4 = new ToDoActivity { PartitionKey = session.PartitionKey, RowKey = Guid.NewGuid().ToString() }; | ||
|
||
session.Batch.Add(TableOperation.Insert(test1)); | ||
session.Batch.Add(TableOperation.Replace(test2)); | ||
session.Batch.Add(TableOperation.InsertOrReplace(test3)); | ||
session.Batch.Add(TableOperation.Delete(test4)); | ||
|
||
return Task.CompletedTask; | ||
} | ||
#endregion | ||
} | ||
|
||
#region TransactionalBatchRegisteredWithDependencyInjectionResolvedInHandler | ||
|
||
public class ToDoActivity : TableEntity | ||
{ | ||
public string Description { get; set; } | ||
} | ||
|
||
class MyHandler : IHandleMessages<MyMessage> | ||
{ | ||
public MyHandler(IAzureTableStorageSession storageSession) | ||
{ | ||
this.storageSession = storageSession; | ||
} | ||
|
||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
var entity = new ToDoActivity | ||
{ | ||
PartitionKey = storageSession.PartitionKey, | ||
RowKey = "RowKey" | ||
}; | ||
|
||
storageSession.Batch.Add(TableOperation.Insert(entity)); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private readonly IAzureTableStorageSession storageSession; | ||
} | ||
|
||
#endregion | ||
|
||
#region TransactionalBatchRegisteredWithDependencyInjectionResolvedInCustomType | ||
|
||
class MyCustomDependency | ||
{ | ||
public MyCustomDependency(IAzureTableStorageSession storageSession) | ||
{ | ||
this.storageSession = storageSession; | ||
} | ||
|
||
public void DeleteInAzureTable(string itemId) | ||
{ | ||
var entity = new ToDoActivity | ||
{ | ||
PartitionKey = storageSession.PartitionKey, | ||
RowKey = itemId | ||
}; | ||
|
||
storageSession.Batch.Add(TableOperation.Insert(entity)); | ||
} | ||
|
||
private readonly IAzureTableStorageSession storageSession; | ||
} | ||
|
||
class MyHandlerWithCustomDependency : IHandleMessages<MyMessage> | ||
{ | ||
public MyHandlerWithCustomDependency(MyCustomDependency customDependency) | ||
{ | ||
this.customDependency = customDependency; | ||
} | ||
|
||
public Task Handle(MyMessage message, IMessageHandlerContext context) | ||
{ | ||
customDependency.DeleteInAzureTable(message.ItemId); | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
private readonly MyCustomDependency customDependency; | ||
} | ||
|
||
#endregion |
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,116 @@ | ||
using System; | ||
using NServiceBus; | ||
|
||
class Usage | ||
{ | ||
Usage(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region PersistenceWithAzure | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("DefaultEndpointsProtocol=https;AccountName=[ACCOUNT];AccountKey=[KEY];"); | ||
|
||
#endregion | ||
|
||
#region RegisterLogicalBehavior | ||
|
||
endpointConfiguration.Pipeline.Register(new RegisterMyBehavior()); | ||
|
||
#endregion | ||
} | ||
|
||
#region PersistenceWithAzureHost | ||
|
||
public class EndpointConfig : IConfigureThisEndpoint | ||
{ | ||
public void Customize(EndpointConfiguration endpointConfiguration) | ||
{ | ||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("DefaultEndpointsProtocol=https;AccountName=[ACCOUNT];AccountKey=[KEY];"); | ||
} | ||
} | ||
|
||
#endregion | ||
|
||
void CustomizingAzurePersistenceAllConnections(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region AzurePersistenceAllConnectionsCustomization | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("connectionString"); | ||
|
||
#endregion | ||
} | ||
|
||
void CustomizingAzurePersistenceSubscriptions(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region AzurePersistenceSubscriptionsCustomization | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence, StorageType.Subscriptions>(); | ||
persistence.ConnectionString("connectionString"); | ||
persistence.TableName("tableName"); | ||
|
||
// Added in Version 1.3 | ||
persistence.CacheFor(TimeSpan.FromMinutes(1)); | ||
|
||
#endregion | ||
} | ||
|
||
void CustomizingAzurePersistenceSagas(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region AzurePersistenceSagasCustomization | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence, StorageType.Sagas>(); | ||
persistence.ConnectionString("connectionString"); | ||
|
||
endpointConfiguration.EnableInstallers(); | ||
|
||
#endregion | ||
} | ||
|
||
void CustomizingDefaultTableName(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region SetDefaultTable | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("connectionString"); | ||
persistence.DefaultTable("TableName"); | ||
|
||
endpointConfiguration.EnableInstallers(); | ||
|
||
#endregion | ||
} | ||
|
||
void EnableInstallersConfiguration(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region EnableInstallersConfiguration | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("connectionString"); | ||
persistence.DefaultTable("TableName"); | ||
|
||
endpointConfiguration.EnableInstallers(); | ||
|
||
#endregion | ||
} | ||
|
||
void EnableInstallersConfigurationOptingOutFromTableCreation(EndpointConfiguration endpointConfiguration) | ||
{ | ||
#region EnableInstallersConfigurationOptingOutFromTableCreation | ||
|
||
var persistence = endpointConfiguration.UsePersistence<AzureTablePersistence>(); | ||
persistence.ConnectionString("connectionString"); | ||
persistence.DefaultTable("TableName"); | ||
|
||
// make sure the table name specified in the DefaultTable exists when calling DisableTableCreation | ||
endpointConfiguration.EnableInstallers(); | ||
persistence.DisableTableCreation(); | ||
|
||
#endregion | ||
} | ||
} | ||
|
||
// to avoid host reference | ||
interface IConfigureThisEndpoint | ||
{ | ||
} |
Empty file.
Oops, something went wrong.