【发布时间】:2021-11-24 14:39:37
【问题描述】:
我已经从 Github 存储库下载了最新的源代码,并成功构建了 ABP 框架和 Azure 事件总线示例代码。我配置了 azure 连接字符串、主题名称和订阅。当我运行该项目时,它会引发堆栈溢出异常。我调试了代码,发现如下问题。
public async Task PublishAsync(
Type eventType,
object eventData,
bool onUnitOfWorkComplete = true,
bool useOutbox = true)
{
if (onUnitOfWorkComplete && UnitOfWorkManager.Current != null)
{
AddToUnitOfWork(
UnitOfWorkManager.Current,
new UnitOfWorkEventRecord(eventType, eventData, EventOrderGenerator.GetNext(), useOutbox)
);
return;
}
if (useOutbox)
{
if (await AddToOutboxAsync(eventType, eventData))
{
return;
}
}
await PublishToEventBusAsync(eventType, eventData);
}
在上面的代码中,UnitOfWorkManager.Current的值为null,所以跳转到第二个条件,执行AddToOutboxAsync方法。
private async Task<bool> AddToOutboxAsync(Type eventType, object eventData)
{
var unitOfWork = UnitOfWorkManager.Current;
if (unitOfWork == null)
{
return false;
}
foreach (var outboxConfig in AbpDistributedEventBusOptions.Outboxes.Values)
{
if (outboxConfig.Selector == null || outboxConfig.Selector(eventType))
{
var eventOutbox = (IEventOutbox)unitOfWork.ServiceProvider.GetRequiredService(outboxConfig.ImplementationType);
var eventName = EventNameAttribute.GetNameOrDefault(eventType);
await eventOutbox.EnqueueAsync(
new OutgoingEventInfo(
GuidGenerator.Create(),
eventName,
Serialize(eventData),
Clock.Now
)
);
return true;
}
}
return false;
}
同样,在上述方法中,它检查工作单元是否为 null,因此它返回 false 并且 PublishToEventBusAsync 正在执行,并且该方法再次调用第一个发布方法,因此代码执行进入循环并引发堆栈溢出异常。
我还尝试阅读链接重定向到 404 页面的 azure 事件总线上的文档。
https://docs.abp.io/en/abp/5.0/Distributed-Event-Bus-Azure-Integration
获取工作单元对象的配置中是否缺少某些内容?
谢谢 伊姆兰汉
【问题讨论】:
-
由于您已经在 GitHub 上打开了一个问题,因此添加参考以帮助其他社区成员。可以参考Message is not publishing in Azure service bus samples code
-
由于您已经按照GitHub comment 解决了这个问题,我建议您在此处添加答案并接受它,以便对可能面临相同问题的其他社区成员有所帮助.
标签: azureservicebus abp event-bus