Skip to content

Commit

Permalink
Merge branch 'rysweet-4745-bring-over-the-tests-from-pr-4405' of gith…
Browse files Browse the repository at this point in the history
…ub.com:microsoft/autogen into rysweet-4744-bring-over-the-tests-from-pr-4405
  • Loading branch information
bassmang committed Jan 21, 2025
2 parents 73373e0 + f1d868f commit 32652f8
Showing 1 changed file with 8 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,15 +216,6 @@ private async ValueTask DispatchEventAsync(CloudEvent evt)
var registry = _clusterClient.GetGrain<IRegistryGrain>(0);
//intentionally blocking
var targetAgentTypes = await registry.GetSubscribedAndHandlingAgents(evt.Source, evt.Type).ConfigureAwait(true);
//verify targetAgentTypes is not null
if (targetAgentTypes is null || targetAgentTypes.Count == 0)
{
_logger.LogWarning("No agents found registered for event {Event}.", evt);
}
else
{
await DispatchEventToAgentsAsync(targetAgentTypes, evt).ConfigureAwait(false);
}
// alternate path
// get the event type and then send to all agents that are subscribed to that event type
var eventType = evt.Type;
Expand All @@ -235,12 +226,10 @@ private async ValueTask DispatchEventAsync(CloudEvent evt)
if (_subscriptionsByTopic.TryGetValue(source, out var agentTypesList2)) { agentTypes.AddRange(agentTypesList2); }
if (_subscriptionsByTopic.TryGetValue(source + "." + eventType, out var agentTypesList3)) { agentTypes.AddRange(agentTypesList3); }
agentTypes = agentTypes.Distinct().ToList();
if (agentTypes.Count > 0)
{
await DispatchEventToAgentsAsync(agentTypes, evt: evt).ConfigureAwait(false);
}
targetAgentTypes.AddRange(agentTypes);

// instead of an exact match, we can also check for a prefix match where key starts with the eventType
else if (_subscriptionsByTopic.Keys.Any(key => key.StartsWith(eventType)))
if (_subscriptionsByTopic.Keys.Any(key => key.StartsWith(eventType)))
{
_subscriptionsByTopic.Where(
kvp => kvp.Key.StartsWith(eventType))
Expand All @@ -249,9 +238,13 @@ private async ValueTask DispatchEventAsync(CloudEvent evt)
.ToList()
.ForEach(async agentType =>
{
await DispatchEventToAgentsAsync(new List<string> { agentType }, evt).ConfigureAwait(false);
targetAgentTypes.Add(agentType);
});
}
if (targetAgentTypes is not null && targetAgentTypes.Any())
{
await DispatchEventToAgentsAsync(targetAgentTypes, evt).ConfigureAwait(false);
}
else
{
// log that no agent types were found
Expand Down

0 comments on commit 32652f8

Please sign in to comment.