适用于 ABP 框架的 Azure 服务总线

Azure Service Bus for ABP framework

我已经从 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;
    }

同样,在上面的方法中,它检查工作单元是空的,所以它 returns false 并且 PublishToEventBusAsync 正在执行,并且该方法再次调用第一个发布方法所以代码执行到循环中并且抛出堆栈溢出异常。

我还尝试阅读 azure 事件总线上的文档,link 重定向到 404 页面。

https://docs.abp.io/en/abp/5.0/Distributed-Event-Bus-Azure-Integration

获取工作单元对象的配置中是否缺少某些内容?

谢谢 伊姆兰克汗

我检查了最新的更改,问题已解决。