-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
.Net: SK Process Cloud Events - Publish Interface abstractions scaffo…
…lding (#10222) ### Motivation and Context Initial change need for Cloud Event support, in particular the publishing events scenario. - Initial changes need in abstractions layer - min changes for Dapr Runtime - min changes for Local Runtime - UTs in Local and Dapr Runtime to ensure parity Coming up changes in separate PRs: - New abstractions to be used when creating sk ProcessBuilder - Additional internal plumbing needed - Samples/Demos with usage Fixes #9721 ### Description <!-- Describe your changes, the overall approach, the underlying design. These notes will help understanding how your code works. Thanks! --> ### Contribution Checklist <!-- Before submitting this PR, please make sure: --> - [x] The code builds clean without any errors or warnings - [x] The PR follows the [SK Contribution Guidelines](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md) and the [pre-submission formatting script](https://github.com/microsoft/semantic-kernel/blob/main/CONTRIBUTING.md#development-scripts) raises no violations - [x] All unit tests pass, and I have added new tests where possible - [x] I didn't break anyone 😄
- Loading branch information
1 parent
9655254
commit 10818c5
Showing
25 changed files
with
493 additions
and
18 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
dotnet/src/Experimental/Process.Abstractions/IKernelExternalProcessMessageChannel.cs
This file contains 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,32 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Threading.Tasks; | ||
|
||
namespace Microsoft.SemanticKernel; | ||
|
||
/// <summary> | ||
/// An interface that provides a channel for emitting external messages from a step. | ||
/// In addition provide common methods like initialization and Uninitialization | ||
/// </summary> | ||
public interface IExternalKernelProcessMessageChannel | ||
{ | ||
/// <summary> | ||
/// Initialization of the external messaging channel used | ||
/// </summary> | ||
/// <returns>A <see cref="ValueTask"/></returns> | ||
public abstract ValueTask Initialize(); | ||
|
||
/// <summary> | ||
/// Uninitialization of the external messaging channel used | ||
/// </summary> | ||
/// <returns>A <see cref="ValueTask"/></returns> | ||
public abstract ValueTask Uninitialize(); | ||
|
||
/// <summary> | ||
/// Emits the specified event from the step outside the SK process | ||
/// </summary> | ||
/// <param name="externalTopicEvent">name of the topic to be used externally as the event name</param> | ||
/// <param name="eventData">data to be transmitted externally</param> | ||
/// <returns></returns> | ||
public abstract Task EmitExternalEventAsync(string externalTopicEvent, object? eventData); | ||
} |
This file contains 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 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 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 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 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 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 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
63 changes: 63 additions & 0 deletions
63
...t/src/Experimental/Process.IntegrationTests.Resources/CloudEvents/MockCloudEventClient.cs
This file contains 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,63 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Collections.Generic; | ||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel; | ||
|
||
namespace SemanticKernel.Process.IntegrationTests.CloudEvents; | ||
/// <summary> | ||
/// Class used for testing purposes to mock emitting external cloud events | ||
/// </summary> | ||
public class MockCloudEventClient : IExternalKernelProcessMessageChannel | ||
{ | ||
/// <summary> | ||
/// Initialization counter for testing | ||
/// </summary> | ||
public int InitializationCounter { get; set; } = 0; | ||
/// <summary> | ||
/// Uninitialization counter for testing | ||
/// </summary> | ||
public int UninitializationCounter { get; set; } = 0; | ||
/// <summary> | ||
/// Captures cloud events emitted for testing | ||
/// </summary> | ||
public List<MockCloudEventData> CloudEvents { get; set; } = []; | ||
|
||
private static MockCloudEventClient? s_instance = null; | ||
|
||
/// <summary> | ||
/// Instance of <see cref="MockCloudEventClient"/> when used as singleton | ||
/// </summary> | ||
public static MockCloudEventClient Instance | ||
{ | ||
get | ||
{ | ||
return s_instance ??= new MockCloudEventClient(); | ||
} | ||
} | ||
|
||
/// <inheritdoc/> | ||
public Task EmitExternalEventAsync(string externalTopicEvent, object? eventData) | ||
{ | ||
if (eventData != null) | ||
{ | ||
this.CloudEvents.Add(new() { TopicName = externalTopicEvent, Data = (string)eventData }); | ||
} | ||
|
||
return Task.CompletedTask; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ValueTask Initialize() | ||
{ | ||
this.InitializationCounter++; | ||
return ValueTask.CompletedTask; | ||
} | ||
|
||
/// <inheritdoc/> | ||
public ValueTask Uninitialize() | ||
{ | ||
this.UninitializationCounter++; | ||
return ValueTask.CompletedTask; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
dotnet/src/Experimental/Process.IntegrationTests.Resources/CloudEvents/MockCloudEventData.cs
This file contains 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,19 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
namespace SemanticKernel.Process.IntegrationTests.CloudEvents; | ||
|
||
/// <summary> | ||
/// Mock cloud event data used for testing purposes only | ||
/// </summary> | ||
public class MockCloudEventData | ||
{ | ||
/// <summary> | ||
/// Name of the mock topic | ||
/// </summary> | ||
public required string TopicName { get; set; } | ||
|
||
/// <summary> | ||
/// Data emitted in the mock cloud event | ||
/// </summary> | ||
public string? Data { get; set; } | ||
} |
40 changes: 40 additions & 0 deletions
40
dotnet/src/Experimental/Process.IntegrationTests.Resources/ProcessCloudEventsResources.cs
This file contains 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,40 @@ | ||
// Copyright (c) Microsoft. All rights reserved. | ||
|
||
using System.Threading.Tasks; | ||
using Microsoft.SemanticKernel; | ||
|
||
namespace SemanticKernel.Process.IntegrationTests; | ||
|
||
#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member | ||
|
||
/// <summary> | ||
/// A step that emits messages externally | ||
/// </summary> | ||
public sealed class MockProxyStep : KernelProcessStep | ||
{ | ||
public static class FunctionNames | ||
{ | ||
public const string OnRepeatMessage = nameof(OnRepeatMessage); | ||
public const string OnEchoMessage = nameof(OnEchoMessage); | ||
} | ||
|
||
public static class TopicNames | ||
{ | ||
public const string RepeatExternalTopic = nameof(RepeatExternalTopic); | ||
public const string EchoExternalTopic = nameof(EchoExternalTopic); | ||
} | ||
|
||
[KernelFunction(FunctionNames.OnRepeatMessage)] | ||
public async Task OnRepeatMessageAsync(KernelProcessStepContext context, string message) | ||
{ | ||
await context.EmitExternalEventAsync(TopicNames.RepeatExternalTopic, message); | ||
} | ||
|
||
[KernelFunction(FunctionNames.OnEchoMessage)] | ||
public async Task OnEchoMessageAsync(KernelProcessStepContext context, string message) | ||
{ | ||
await context.EmitExternalEventAsync(TopicNames.EchoExternalTopic, message); | ||
} | ||
} | ||
|
||
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member |
This file contains 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
Oops, something went wrong.