Skip to content

Commit

Permalink
chore: adding prefix to retry
Browse files Browse the repository at this point in the history
  • Loading branch information
ext.joao.veloso committed Oct 25, 2023
1 parent 366e938 commit 2edaf95
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 19 deletions.
29 changes: 24 additions & 5 deletions src/KafkaFlow.Retry.API/AppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,34 +18,53 @@ this IApplicationBuilder appBuilder
.ApplicationServices
.GetService(typeof(IRetryDurableQueueRepositoryProvider)) as IRetryDurableQueueRepositoryProvider;

appBuilder.UseRetryEndpoints(retryDurableQueueRepositoryProvider);
appBuilder.UseRetryEndpoints(retryDurableQueueRepositoryProvider, string.Empty);

return appBuilder;
}

public static IApplicationBuilder UseKafkaFlowRetryEndpoints(
this IApplicationBuilder appBuilder,
string endpointPrefix
)
{
var retryDurableQueueRepositoryProvider =
appBuilder
.ApplicationServices
.GetService(typeof(IRetryDurableQueueRepositoryProvider)) as IRetryDurableQueueRepositoryProvider;

appBuilder.UseRetryEndpoints(retryDurableQueueRepositoryProvider, endpointPrefix);

return appBuilder;
}

public static IApplicationBuilder UseRetryEndpoints(
this IApplicationBuilder appBuilder,
IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider
IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider,
string endpointPrefix
)
{
appBuilder.UseMiddleware<RetryMiddleware>(
new GetItemsHandler(
retryDurableQueueRepositoryProvider,
new GetItemsRequestDtoReader(),
new GetItemsInputAdapter(),
new GetItemsResponseDtoAdapter()));
new GetItemsResponseDtoAdapter(),
endpointPrefix));

appBuilder.UseMiddleware<RetryMiddleware>(
new PatchItemsHandler(
retryDurableQueueRepositoryProvider,
new UpdateItemsInputAdapter(),
new UpdateItemsResponseDtoAdapter()));
new UpdateItemsResponseDtoAdapter(),
endpointPrefix));

appBuilder.UseMiddleware<RetryMiddleware>(
new PatchQueuesHandler(
retryDurableQueueRepositoryProvider,
new UpdateQueuesInputAdapter(),
new UpdateQueuesResponseDtoAdapter()));
new UpdateQueuesResponseDtoAdapter(),
endpointPrefix));

return appBuilder;
}
Expand Down
23 changes: 20 additions & 3 deletions src/KafkaFlow.Retry.API/Handlers/GetItemsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ internal class GetItemsHandler : RetryRequestHandlerBase
private readonly IGetItemsRequestDtoReader getItemsRequestDtoReader;
private readonly IGetItemsResponseDtoAdapter getItemsResponseDtoAdapter;
private readonly IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider;
private readonly string endpointPrefix;

public GetItemsHandler(
IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider,
IGetItemsRequestDtoReader getItemsRequestDtoReader,
IGetItemsInputAdapter getItemsInputAdapter,
IGetItemsResponseDtoAdapter getItemsResponseDtoAdapter)
IGetItemsResponseDtoAdapter getItemsResponseDtoAdapter,
string endpointPrefix)
{
Guard.Argument(retryDurableQueueRepositoryProvider, nameof(retryDurableQueueRepositoryProvider)).NotNull();
Guard.Argument(getItemsRequestDtoReader, nameof(getItemsRequestDtoReader)).NotNull();
Expand All @@ -29,10 +31,9 @@ public GetItemsHandler(
this.retryDurableQueueRepositoryProvider = retryDurableQueueRepositoryProvider;
this.getItemsRequestDtoReader = getItemsRequestDtoReader;
this.getItemsResponseDtoAdapter = getItemsResponseDtoAdapter;
this.endpointPrefix = endpointPrefix;
}

protected override string ResourcePath => base.ResourcePath.ExtendResourcePath("items");

protected override HttpMethod HttpMethod => HttpMethod.GET;

protected override async Task HandleRequestAsync(HttpRequest request, HttpResponse response)
Expand All @@ -54,5 +55,21 @@ protected override async Task HandleRequestAsync(HttpRequest request, HttpRespon
await this.WriteResponseAsync(response, ex, (int)HttpStatusCode.InternalServerError).ConfigureAwait(false);
}
}

protected override string ResourcePath
{
get
{
string baseResourcePath = base.ResourcePath;
if (string.IsNullOrEmpty(endpointPrefix))
{
return baseResourcePath.ExtendResourcePath("items");
}
else
{
return baseResourcePath.ExtendResourcePath($"{endpointPrefix}/items");
}
}
}
}
}
22 changes: 20 additions & 2 deletions src/KafkaFlow.Retry.API/Handlers/PatchItemsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ internal class PatchItemsHandler : RetryRequestHandlerBase
private readonly IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider;
private readonly IUpdateItemsInputAdapter updateItemsInputAdapter;
private readonly IUpdateItemsResponseDtoAdapter updateItemsResponseDtoAdapter;
private readonly string endpointPrefix;

public PatchItemsHandler(
IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider,
IUpdateItemsInputAdapter updateItemsInputAdapter,
IUpdateItemsResponseDtoAdapter updateItemsResponseDtoAdapter)
IUpdateItemsResponseDtoAdapter updateItemsResponseDtoAdapter,
string endpointPrefix)
{
this.retryDurableQueueRepositoryProvider = retryDurableQueueRepositoryProvider;
this.updateItemsInputAdapter = updateItemsInputAdapter;
this.updateItemsResponseDtoAdapter = updateItemsResponseDtoAdapter;
this.endpointPrefix = endpointPrefix;
}

protected override string ResourcePath => base.ResourcePath.ExtendResourcePath("items");

protected override HttpMethod HttpMethod => HttpMethod.PATCH;

Expand Down Expand Up @@ -65,5 +67,21 @@ protected override async Task HandleRequestAsync(HttpRequest request, HttpRespon
await this.WriteResponseAsync(response, ex, (int)HttpStatusCode.InternalServerError).ConfigureAwait(false);
}
}

protected override string ResourcePath
{
get
{
string baseResourcePath = base.ResourcePath;
if (string.IsNullOrEmpty(endpointPrefix))
{
return base.ResourcePath.ExtendResourcePath("items");
}
else
{
return baseResourcePath.ExtendResourcePath($"{endpointPrefix}/items");
}
}
}
}
}
21 changes: 19 additions & 2 deletions src/KafkaFlow.Retry.API/Handlers/PatchQueuesHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ internal class PatchQueuesHandler : RetryRequestHandlerBase
private readonly IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider;
private readonly IUpdateQueuesInputAdapter updateQueuesInputAdapter;
private readonly IUpdateQueuesResponseDtoAdapter updateQueuesResponseDtoAdapter;
private readonly string endpointPrefix;

public PatchQueuesHandler(
IRetryDurableQueueRepositoryProvider retryDurableQueueRepositoryProvider,
IUpdateQueuesInputAdapter updateQueuesInputAdapter,
IUpdateQueuesResponseDtoAdapter updateQueuesResponseDtoAdapter)
IUpdateQueuesResponseDtoAdapter updateQueuesResponseDtoAdapter,
string endpointPrefix)
{
this.retryDurableQueueRepositoryProvider = retryDurableQueueRepositoryProvider;
this.updateQueuesInputAdapter = updateQueuesInputAdapter;
this.updateQueuesResponseDtoAdapter = updateQueuesResponseDtoAdapter;
this.endpointPrefix = endpointPrefix;
}

protected override string ResourcePath => base.ResourcePath.ExtendResourcePath("queues");

protected override HttpMethod HttpMethod => HttpMethod.PATCH;

Expand Down Expand Up @@ -65,5 +67,20 @@ protected override async Task HandleRequestAsync(HttpRequest request, HttpRespon
await this.WriteResponseAsync(response, ex, (int)HttpStatusCode.InternalServerError).ConfigureAwait(false);
}
}
protected override string ResourcePath
{
get
{
string baseResourcePath = base.ResourcePath;
if (string.IsNullOrEmpty(endpointPrefix))
{
return base.ResourcePath.ExtendResourcePath("queues");
}
else
{
return baseResourcePath.ExtendResourcePath($"{endpointPrefix}/queues");
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ public async Task GetItemsHandler_HandleAsync_Success()
retryDurableQueueRepositoryProvider.Object,
mockGetItemsRequestDtoReader.Object,
mockGetItemsInputAdapter.Object,
mockGetItemsResponseDtoReader.Object
mockGetItemsResponseDtoReader.Object,
string.Empty
);

// Act
Expand Down Expand Up @@ -93,7 +94,8 @@ public async Task GetItemsHandler_HandleAsync_WithException_ReturnsExpectedStatu
retryQueueDataProvider,
getItemsRequestDtoReader,
getItemsInputAdapter,
getItemsResponseDtoAdapter
getItemsResponseDtoAdapter,
string.Empty
);

// Act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public async Task PatchItemsHandler_HandleAsync_Success()
var handler = new PatchItemsHandler(
retryQueueDataProvider.Object,
mockUpdateItemsInputAdapter.Object,
mockUpdateItemsResponseDtoAdapter.Object
mockUpdateItemsResponseDtoAdapter.Object,
string.Empty
);

// Act
Expand Down Expand Up @@ -103,7 +104,8 @@ public async Task PatchItemsHandler_HandleAsync_WithErrorInDeserialization()
var handler = new PatchItemsHandler(
Mock.Of<IRetryDurableQueueRepositoryProvider>(),
Mock.Of<IUpdateItemsInputAdapter>(),
Mock.Of<IUpdateItemsResponseDtoAdapter>()
Mock.Of<IUpdateItemsResponseDtoAdapter>(),
string.Empty
);

// act
Expand All @@ -129,7 +131,8 @@ public async Task PatchItemsHandler_HandleAsync_WithException_ReturnsExpectedSta
var handler = new PatchItemsHandler(
retryQueueDataProvider,
updateItemsInputAdapter,
updateItemsResponseDtoAdapter
updateItemsResponseDtoAdapter,
string.Empty
);

// act
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ public async Task PatchQueuesHandler_HandleAsync_Success()
var handler = new PatchQueuesHandler(
retryQueueDataProvider.Object,
mockUpdateQueuesInputAdapter.Object,
mockUpdateQueuesResponseDtoAdapter.Object
mockUpdateQueuesResponseDtoAdapter.Object,
string.Empty
);

// Act
Expand Down Expand Up @@ -83,7 +84,8 @@ public async Task PatchQueuesHandler_HandleAsync_WithException_ReturnsExpectedSt
var handler = new PatchQueuesHandler(
retryQueueDataProvider,
updateQueuesInputAdapter,
updateQueuesResponseDtoAdapter
updateQueuesResponseDtoAdapter,
string.Empty
);

// act
Expand Down

0 comments on commit 2edaf95

Please sign in to comment.