Skip to content

Commit

Permalink
feat(server,connector): add test code for acknowledgements
Browse files Browse the repository at this point in the history
  • Loading branch information
gingters authored and thomashilzendegen committed Aug 22, 2023
1 parent 86fb3c5 commit d72eb2f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/docker/Thinktecture.Relay.Connector.Docker/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using Microsoft.AspNetCore.Http.Extensions;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Thinktecture.Relay.Acknowledgement;
using Thinktecture.Relay.Connector.Targets;
using Thinktecture.Relay.Transport;

Expand Down Expand Up @@ -62,6 +65,13 @@ public async Task<TargetResponse> HandleAsync(ClientRequest request, Cancellatio
}
}

// Test: If we wait with ack for a completed target request, delay a bit to be able to restart rabbit
var url = $"http://localhorst/{request.Url}";
if (TimeSpan.TryParse(HttpUtility.ParseQueryString(new Uri(url).Query).Get("delay"), out var delay))
{
await Task.Delay(delay, cancellationToken);
}

var response = request.CreateResponse();

response.HttpStatusCode = HttpStatusCode.OK;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System.Threading;
using System.Threading.Tasks;
using Thinktecture.Relay.Acknowledgement;
using Thinktecture.Relay.Server.Interceptor;
using Thinktecture.Relay.Server.Transport;
using Thinktecture.Relay.Transport;

namespace Thinktecture.Relay.Server.Docker.Interceptors;

public class ConnectorFinishedAcknowledgementModeInterceptor : IClientRequestInterceptor<ClientRequest, TargetResponse>
{
public Task OnRequestReceivedAsync(IRelayContext<ClientRequest, TargetResponse> context,
CancellationToken cancellationToken = default)
{
context.ClientRequest.AcknowledgeMode = AcknowledgeMode.Manual;
return Task.CompletedTask;
}
}

0 comments on commit d72eb2f

Please sign in to comment.