-
Notifications
You must be signed in to change notification settings - Fork 48
Add support for RPC over Redis. #698
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
LukeButters
wants to merge
9
commits into
main
Choose a base branch
from
local-execution-mode
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
75b3543
Add local execution mode for queue-based RPC without TCP
LukeButters 941c327
Add conditional compilation directive for .NET 8.0+ to LocalExecution…
LukeButters 88fb6a0
Restore SimplePollingExample test to HalibutExamplesFixture
LukeButters 2ab6dda
.
LukeButters 5a584c0
Expose InMemoryConnectionLog max events as public static readonly field
LukeButters d923006
Make InMemoryConnectionLog class public
LukeButters 12c1a29
.
LukeButters 77160c7
.
LukeButters 4e7bf15
.
LukeButters File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,46 @@ | ||
| using System; | ||
| using System.Threading.Tasks; | ||
| using Halibut.ServiceModel; | ||
| using Halibut.Tests.Support; | ||
| using Halibut.Tests.TestServices; | ||
| using Halibut.Tests.TestServices.Async; | ||
| using Halibut.TestUtils.Contracts; | ||
| using NUnit.Framework; | ||
|
|
||
| namespace Halibut.Tests | ||
| { | ||
| public class HalibutExamplesFixture : BaseTest | ||
| { | ||
| [Test] | ||
| public async Task SimplePollingExample() | ||
| { | ||
| var services = GetDelegateServiceFactory(); | ||
| await using (var client = new HalibutRuntimeBuilder() | ||
| .WithServerCertificate(Certificates.Octopus) | ||
| .WithHalibutTimeoutsAndLimits(new HalibutTimeoutsAndLimitsForTestsBuilder().Build()) | ||
| .Build()) | ||
| await using (var pollingService = new HalibutRuntimeBuilder() | ||
| .WithServerCertificate(Certificates.TentaclePolling) | ||
| .WithServiceFactory(services) | ||
| .WithHalibutTimeoutsAndLimits(new HalibutTimeoutsAndLimitsForTestsBuilder().Build()) | ||
| .Build()) | ||
| { | ||
| var octopusPort = client.Listen(); | ||
| client.Trust(Certificates.TentaclePollingPublicThumbprint); | ||
|
|
||
| pollingService.Poll(new Uri("poll://alice"), new ServiceEndPoint("https://localhost:" + octopusPort, Certificates.OctopusPublicThumbprint, client.TimeoutsAndLimits), CancellationToken); | ||
|
|
||
| var echo = client.CreateAsyncClient<IEchoService, IAsyncClientEchoService>(new ServiceEndPoint("poll://alice", null, client.TimeoutsAndLimits)); | ||
|
|
||
| await echo.SayHelloAsync("World"); | ||
| } | ||
| } | ||
|
|
||
| static DelegateServiceFactory GetDelegateServiceFactory() | ||
| { | ||
| var services = new DelegateServiceFactory(); | ||
| services.Register<IEchoService, IAsyncEchoService>(() => new AsyncEchoService()); | ||
| return services; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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,102 @@ | ||
| #if NET8_0_OR_GREATER | ||
| using System; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using FluentAssertions; | ||
| using Halibut.Diagnostics; | ||
| using Halibut.Logging; | ||
| using Halibut.Queue; | ||
| using Halibut.Queue.Redis; | ||
| using Halibut.Queue.Redis.RedisDataLossDetection; | ||
| using Halibut.Queue.Redis.RedisHelpers; | ||
| using Halibut.ServiceModel; | ||
| using Halibut.Tests.Queue.Redis.Utils; | ||
| using Halibut.Tests.Support; | ||
| using Halibut.Tests.Support.Logging; | ||
| using Halibut.Tests.TestServices; | ||
| using Halibut.Tests.TestServices.Async; | ||
| using Halibut.TestUtils.Contracts; | ||
| using NUnit.Framework; | ||
| using DisposableCollection = Halibut.Util.DisposableCollection; | ||
|
|
||
| namespace Halibut.Tests | ||
| { | ||
| public class LocalExecutionModeFixture : BaseTest | ||
| { | ||
| [RedisTest] | ||
| [Test] | ||
| public async Task SimpleLocalExecutionExample() | ||
| { | ||
| var services = GetDelegateServiceFactory(); | ||
| var timeoutsAndLimits = new HalibutTimeoutsAndLimitsForTestsBuilder().Build(); | ||
| timeoutsAndLimits = new HalibutTimeoutsAndLimits(); | ||
|
|
||
| // Use a shared queue factory so client and worker share the same queue | ||
| var queueFactory = new PendingRequestQueueFactoryAsync(timeoutsAndLimits, new LogFactory()); | ||
|
|
||
| var logFactory = new CachingLogFactory(new TestContextLogCreator("", LogLevel.Trace)); | ||
|
|
||
| var log = new TestContextLogCreator("Redis", LogLevel.Fatal); | ||
|
|
||
| var preSharedGuid = Guid.NewGuid(); | ||
|
|
||
| await using var disposables = new DisposableCollection(); | ||
|
|
||
| await using var client = new HalibutRuntimeBuilder() | ||
| .WithServerCertificate(Certificates.Octopus) | ||
| .WithPendingRequestQueueFactory(RedisFactory()) | ||
| .WithHalibutTimeoutsAndLimits(timeoutsAndLimits) | ||
| .Build(); | ||
|
|
||
| await using var worker = new HalibutRuntimeBuilder() | ||
| .WithServerCertificate(Certificates.TentaclePolling) | ||
| .WithServiceFactory(services) | ||
| .WithPendingRequestQueueFactory(RedisFactory()) | ||
| .WithHalibutTimeoutsAndLimits(timeoutsAndLimits) | ||
| .Build(); | ||
|
|
||
| // Start worker polling for local://test-worker | ||
| using var workerCts = new CancellationTokenSource(); | ||
| var pollingTask = Task.Run(async () => | ||
| { | ||
| //await Task.Delay(TimeSpan.FromSeconds(10)); | ||
| await worker.PollLocalAsync(new Uri("local://test-worker"), workerCts.Token); | ||
| }, workerCts.Token); | ||
|
|
||
| // Client creates proxy to local://test-worker and makes request | ||
| var echo = client.CreateAsyncClient<IEchoService, IAsyncClientEchoService>( | ||
| new ServiceEndPoint("local://test-worker", null, client.TimeoutsAndLimits)); | ||
|
|
||
| var result = await echo.SayHelloAsync("World"); | ||
| result.Should().Be("World..."); | ||
|
|
||
| await workerCts.CancelAsync(); | ||
|
|
||
| Func<QueueMessageSerializer, IPendingRequestQueueFactory> RedisFactory() | ||
| { | ||
| return msgSer => | ||
| { | ||
| var redisFacade = RedisFacadeBuilder.CreateRedisFacade(prefix: preSharedGuid); | ||
| disposables.AddAsyncDisposable(redisFacade); | ||
| var watchForRedisLosingAllItsData = new WatchForRedisLosingAllItsData(redisFacade, log.CreateNewForPrefix("watcher")); | ||
| disposables.AddAsyncDisposable(watchForRedisLosingAllItsData); | ||
|
|
||
| return new RedisPendingRequestQueueFactory(msgSer, | ||
| new InMemoryStoreDataStreamsForDistributedQueues(), | ||
| watchForRedisLosingAllItsData, | ||
| new HalibutRedisTransport(redisFacade), | ||
| new HalibutTimeoutsAndLimitsForTestsBuilder().Build(), | ||
| logFactory); | ||
| }; | ||
| } | ||
| } | ||
|
|
||
| static DelegateServiceFactory GetDelegateServiceFactory() | ||
| { | ||
| var services = new DelegateServiceFactory(); | ||
| services.Register<IEchoService, IAsyncEchoService>(() => new AsyncEchoService()); | ||
| return services; | ||
| } | ||
| } | ||
| } | ||
| #endif |
This file contains hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this since we lack simple examples of how to use halibit.