Skip to content

Commit

Permalink
Minor fixes. (#66)
Browse files Browse the repository at this point in the history
  • Loading branch information
chullybun authored May 5, 2023
1 parent 3befc85 commit 74f5cb2
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

Represents the **NuGet** versions.

## v2.10.1
- *Fixed:* `EventOutboxHostedService` updated so when a new `IServiceScope` is created that `ExecutionContext.Reset` is invoked to ensure existing `ServiceProvider` is not reused.
- *Fixed:* `EventDataFormatter` defaults `PartitionKey` and `TenantId` properties, where not already set, from the value where implements `IPartitionKey` and `ITenantId` respectively.

## v2.10.0
- *Enhancement:* Added `IServiceBusSubscriber` with following properties: `AbandonOnTransient` (perform an Abandon versus bubbling exception), `MaxDeliveryCount` (max delivery count check within subscriber), `RetryDelay` (basic transient retry specification) and `MaxRetryDelay` (defines upper bounds of retry delay). These are defaulted from corresponding `IConfiguration` settings. Both the `ServiveBusSubscriber` and `ServiveBusOrchestratedSubscriber` implement; related logic within `ServiceBusSubscriberInvoker`.
- *Enhancement:* Added `RetryAfterSeconds` to `TransientException` to allow overriding; defaults to `120` seconds.
Expand Down
2 changes: 1 addition & 1 deletion Common.targets
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>2.10.0</Version>
<Version>2.10.1</Version>
<LangVersion>preview</LangVersion>
<Authors>Avanade</Authors>
<Company>Avanade</Company>
Expand Down
2 changes: 1 addition & 1 deletion src/CoreEx.Azure/ServiceBus/ServiceBusSender.cs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public Task SendAsync(IEnumerable<EventSendData> events, CancellationToken cance
{
var n = qitem.Key == _unspecifiedQueueOrTopicName ? null : qitem.Key;
var key = $"{GetType().Name}_QueueOrTopicName{(n is null ? "" : $"_{n}")}";
var qn = Settings.GetValue($"{GetType().Name}:QueueOrTopicName{(n is null ? "" : $"_{n}")}", defaultValue: n) ?? throw new EventSendException(PrependStats("'{key}' configuration setting must have a non-null value.", totalCount, unsentEvents.Count), unsentEvents);
var qn = Settings.GetValue($"{GetType().Name}:QueueOrTopicName{(n is null ? "" : $"_{n}")}", defaultValue: n) ?? throw new EventSendException(PrependStats($"'{key}' configuration setting must have a non-null value.", totalCount, unsentEvents.Count), unsentEvents);
var queue = qitem.Value;
var sentIds = new List<string>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ protected override async Task SynchronizedExecuteAsync(IServiceProvider scopedSe
{
// As we want to tight loop the execution where there mey be more in the queue, a new 'Scope' is used to ensure new instances of dependencies are used otherwise a disposed error may occur for the underlying transaction.
using var scope = scopedServiceProvider.CreateScope();
ExecutionContext.Reset();
var eod = EventOutboxDequeueFactory(scope.ServiceProvider) ?? throw new InvalidOperationException($"The {nameof(EventOutboxDequeueFactory)} function must return an instance of {nameof(EventOutboxDequeueBase)}.");
sent = await eod.DequeueAndSendAsync(MaxDequeueSize, PartitionKey, Destination, cancellationToken).ConfigureAwait(false);
}
Expand Down
24 changes: 22 additions & 2 deletions src/CoreEx/Events/EventDataFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,16 @@ public class EventDataFormatter
/// <remarks>This is applied after <see cref="ETagDefaultFromValue"/>.</remarks>
public bool ETagDefaultGenerated { get; set; } = false;

/// <summary>
/// Indicates whether to default the <see cref="EventDataBase.PartitionKey"/> to the <see cref="EventData.Value"/> value where it implements <see cref="IPartitionKey"/>.
/// </summary>
public bool PartitionKeyDefaultFromValue { get; set; } = true;

/// <summary>
/// Indicates whether to default the <see cref="EventDataBase.TenantId"/> to the <see cref="EventData.Value"/> value where it implements <see cref="ITenantId"/>.
/// </summary>
public bool TenantIdDefaultFromValue { get; set; } = true;

/// <summary>
/// Gets or sets the <see cref="IJsonSerializer"/>.
/// </summary>
Expand Down Expand Up @@ -189,10 +199,20 @@ public virtual void Format(EventData @event)
else
@event.CorrelationId = null;

if (!PropertySelection.HasFlag(EventDataProperty.TenantId))
if (PropertySelection.HasFlag(EventDataProperty.TenantId))
{
if (@event.TenantId is null && TenantIdDefaultFromValue && value is not null && value is ITenantId tid)
@event.TenantId = tid.TenantId;
}
else
@event.TenantId = null;

if (!PropertySelection.HasFlag(EventDataProperty.PartitionKey))
if (PropertySelection.HasFlag(EventDataProperty.PartitionKey))
{
if (@event.PartitionKey is null && PartitionKeyDefaultFromValue && value is not null && value is IPartitionKey pk)
@event.PartitionKey = pk.PartitionKey;
}
else
@event.PartitionKey = null;

if (PropertySelection.HasFlag(EventDataProperty.ETag))
Expand Down
1 change: 1 addition & 0 deletions src/CoreEx/Hosting/TimerHostedServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ private async Task ScopedExecuteAsync(CancellationToken cancellationToken)
{
// Create a scope in which to perform the execution.
using var scope = ServiceProvider.CreateScope();
ExecutionContext.Reset();

try
{
Expand Down

0 comments on commit 74f5cb2

Please sign in to comment.