Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 09517e59a3 | |||
| 7992e3de0f | |||
| 47bede52d1 | |||
| 30726d7aa1 |
@ -26,9 +26,9 @@
|
|||||||
"enum": [
|
"enum": [
|
||||||
"Clean",
|
"Clean",
|
||||||
"Compile",
|
"Compile",
|
||||||
|
"CreateAndPushGitTag",
|
||||||
"Pack",
|
"Pack",
|
||||||
"Publish",
|
"Publish",
|
||||||
"Restore",
|
|
||||||
"Test"
|
"Test"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
@ -103,6 +103,10 @@
|
|||||||
"allOf": [
|
"allOf": [
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"BuildNumber": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Build number override"
|
||||||
|
},
|
||||||
"Configuration": {
|
"Configuration": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
|
"description": "Configuration to build - Default is 'Debug' (local) or 'Release' (server)",
|
||||||
@ -111,6 +115,20 @@
|
|||||||
"Release"
|
"Release"
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"GiteaNugetSourceName": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Gitea Nuget package source name"
|
||||||
|
},
|
||||||
|
"GiteaPackageOwnerPassword": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Gitea package owner password",
|
||||||
|
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
|
||||||
|
},
|
||||||
|
"GiteaPackageOwnerUser": {
|
||||||
|
"type": "string",
|
||||||
|
"description": "Gitea package owner user",
|
||||||
|
"default": "Secrets must be entered via 'nuke :secrets [profile]'"
|
||||||
|
},
|
||||||
"NuGetApiKey": {
|
"NuGetApiKey": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"description": "NuGet API key"
|
"description": "NuGet API key"
|
||||||
|
|||||||
85
README.md
85
README.md
@ -1,3 +1,82 @@
|
|||||||
# RedisStreamsInOrleans
|
# Universley.OrleansContrib.StreamsProvider.Redis
|
||||||
This is a project that demonstrates how to create a custom Redis Stream Provider for Orleans.
|
|
||||||
https://swacblooms.com/custom-redis-streams-provider-for-orleans/
|
## Summary
|
||||||
|
This library provides an integration of Redis Streams with Microsoft Orleans, allowing you to use Redis as a streaming provider within your Orleans applications. It enables seamless communication and data streaming between Orleans grains and external clients using Redis Streams.
|
||||||
|
|
||||||
|
## How to Use the Redis Provider with Orleans
|
||||||
|
|
||||||
|
### 1. With Grain as a Client
|
||||||
|
To use Redis Streams with a grain as a client, follow these steps:
|
||||||
|
|
||||||
|
1. Install the necessary NuGet packages:
|
||||||
|
```sh
|
||||||
|
dotnet add package Orleans.Streaming.Redis
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Configure the Redis stream provider in your Orleans silo configuration:
|
||||||
|
```csharp
|
||||||
|
var host = new SiloHostBuilder()
|
||||||
|
.AddRedisStreams("RedisProvider", options =>
|
||||||
|
{
|
||||||
|
options.ConnectionString = "your_redis_connection_string";
|
||||||
|
})
|
||||||
|
.Build();
|
||||||
|
```
|
||||||
|
|
||||||
|
3. In your grain, use the stream provider to send and receive messages:
|
||||||
|
```csharp
|
||||||
|
public class MyGrain : Grain, IMyGrain
|
||||||
|
{
|
||||||
|
private IAsyncStream<string> _stream;
|
||||||
|
|
||||||
|
public override async Task OnActivateAsync()
|
||||||
|
{
|
||||||
|
var streamProvider = GetStreamProvider("RedisProvider");
|
||||||
|
_stream = streamProvider.GetStream<string>(this.GetPrimaryKey(), "streamNamespace");
|
||||||
|
await base.OnActivateAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task SendMessage(string message)
|
||||||
|
{
|
||||||
|
await _stream.OnNextAsync(message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public async Task ReceiveMessages()
|
||||||
|
{
|
||||||
|
var handle = await _stream.SubscribeAsync((message, token) =>
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Received message: {message}");
|
||||||
|
return Task.CompletedTask;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### 2. With External Client
|
||||||
|
To use Redis Streams with an external client, follow these steps:
|
||||||
|
|
||||||
|
1. Install the StackExchange.Redis package:
|
||||||
|
```sh
|
||||||
|
dotnet add package StackExchange.Redis
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Connect to the Redis server and interact with the stream:
|
||||||
|
```csharp
|
||||||
|
using StackExchange.Redis;
|
||||||
|
|
||||||
|
var redis = ConnectionMultiplexer.Connect("your_redis_connection_string");
|
||||||
|
var db = redis.GetDatabase();
|
||||||
|
|
||||||
|
// Add a message to the stream
|
||||||
|
var messageId = await db.StreamAddAsync("mystream", "message", "Hello, Redis!");
|
||||||
|
|
||||||
|
// Read messages from the stream
|
||||||
|
var messages = await db.StreamReadAsync("mystream", "0-0");
|
||||||
|
foreach (var message in messages)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Message ID: {message.Id}, Values: {string.Join(", ", message.Values)}");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Credit
|
||||||
|
This library is based on the original repository by [sammychinedu2ky](https://github.com/sammychinedu2ky/RedisStreamsInOrleans).
|
||||||
@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
|||||||
# Visual Studio Version 17
|
# Visual Studio Version 17
|
||||||
VisualStudioVersion = 17.10.34928.147
|
VisualStudioVersion = 17.10.34928.147
|
||||||
MinimumVisualStudioVersion = 10.0.40219.1
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "Server\Server.csproj", "{35E441B1-DDF7-4497-B1D9-BBD9248690E9}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Server", "example\Server\Server.csproj", "{35E441B1-DDF7-4497-B1D9-BBD9248690E9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "Client\Client.csproj", "{B7477618-DE9C-4586-98D2-46CFF1CB0C74}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Client", "example\Client\Client.csproj", "{B7477618-DE9C-4586-98D2-46CFF1CB0C74}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Universley.OrleansContrib.StreamsProvider.Redis", "Provider\Universley.OrleansContrib.StreamsProvider.Redis.csproj", "{70F8E685-F662-4225-A60C-D318E0C6ED18}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Universley.OrleansContrib.StreamsProvider.Redis", "Universley.OrleansContrib.StreamsProvider.Redis\Universley.OrleansContrib.StreamsProvider.Redis.csproj", "{70F8E685-F662-4225-A60C-D318E0C6ED18}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisStreamsProvider.UnitTests", "RedisStreamsProvider.UnitTests\RedisStreamsProvider.UnitTests.csproj", "{DF927C2B-A141-4476-86CF-3B4DC8ECB4DE}"
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "RedisStreamsProvider.UnitTests", "RedisStreamsProvider.UnitTests\RedisStreamsProvider.UnitTests.csproj", "{DF927C2B-A141-4476-86CF-3B4DC8ECB4DE}"
|
||||||
EndProject
|
EndProject
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Provider\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
<ProjectReference Include="..\Universley.OrleansContrib.StreamsProvider.Redis\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@ -101,7 +101,7 @@ class Build : NukeBuild
|
|||||||
{
|
{
|
||||||
|
|
||||||
DotNetTasks.DotNetPack(s => s
|
DotNetTasks.DotNetPack(s => s
|
||||||
.SetProject(SourceDirectory / "Provider" / $"{LibraryProjectName}.csproj")
|
.SetProject(SourceDirectory / "Universley.OrleansContrib.StreamsProvider.Redis" / $"{LibraryProjectName}.csproj")
|
||||||
.SetConfiguration(Configuration)
|
.SetConfiguration(Configuration)
|
||||||
.SetOutputDirectory(NuGetPackagesDirectory)
|
.SetOutputDirectory(NuGetPackagesDirectory)
|
||||||
.SetVersion(Version)
|
.SetVersion(Version)
|
||||||
@ -113,12 +113,19 @@ class Build : NukeBuild
|
|||||||
.DependsOn(Pack, CreateAndPushGitTag)
|
.DependsOn(Pack, CreateAndPushGitTag)
|
||||||
.Executes(() =>
|
.Executes(() =>
|
||||||
{
|
{
|
||||||
DotNetTasks.DotNetNuGetAddSource(c => c
|
try
|
||||||
.EnableStorePasswordInClearText()
|
{
|
||||||
.SetUsername(GiteaPackageOwnerUser)
|
DotNetTasks.DotNetNuGetAddSource(c => c
|
||||||
.SetPassword(GiteaPackageOwnerPassword)
|
.EnableStorePasswordInClearText()
|
||||||
.SetName("Gitea")
|
.SetUsername(GiteaPackageOwnerUser)
|
||||||
.SetSource($"{GiteaNugetSourceName}/index.json"));
|
.SetPassword(GiteaPackageOwnerPassword)
|
||||||
|
.SetName("Gitea")
|
||||||
|
.SetSource($"{GiteaNugetSourceName}/index.json"));
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.Warning("Error adding Gitea source: {e}", e);
|
||||||
|
}
|
||||||
|
|
||||||
DotNetTasks.DotNetNuGetPush(s => s
|
DotNetTasks.DotNetNuGetPush(s => s
|
||||||
.SetSource($"{GiteaNugetSourceName}/symbols")
|
.SetSource($"{GiteaNugetSourceName}/symbols")
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Provider\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
<ProjectReference Include="..\..\Universley.OrleansContrib.StreamsProvider.Redis\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
@ -14,7 +14,7 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ProjectReference Include="..\Provider\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
<ProjectReference Include="..\..\Universley.OrleansContrib.StreamsProvider.Redis\Universley.OrleansContrib.StreamsProvider.Redis.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
x
Reference in New Issue
Block a user