structuremap - MassTransit 消费者 IContainer 有效负载未由 StructureMapConsumerScopeProvider 设置
问题描述
我正在尝试为我的消费者实现 MassTransit 中间件,我需要从 IoC 容器中获取一个对象的实例(使用 StructureMap),但该容器似乎没有在有效负载上设置。
public class MyMessageFilter : IFilter<ConsumeContext<T>> where T : class {
public void Probe(ProbeContext context) { /* Do nothing */ }
public async Task Send(ConsumeContext<T> context, IPipe<ConsumeContext<T>> next)
{
_logger.Information("IContainer: " + context.TryGetPayload<IContainer>(out var container)); // logs "IContainer: False" where I was expecting it to have been added to the payload
...
await next.Send(context);
}
}
我已经配置了以下内容,我认为这可以解决问题。我已经确认正在创建和使用这些类的实例。
For(typeof(IConsumerFactory<>)).Use(typeof(ScopeConsumerFactory<>));
For<IConsumerScopeProvider>().Use<StructureMapConsumerScopeProvider>();
我的 MassTransit 配置如下所示
cfg.UseTransaction();
cfg.ReceiveEndpoint("some-queue", e => {
e.UseMyMessageFilter();
e.Consumer<MyConsumer>(container);
});
更新将上面的代码从 e.Consumer(container.GetInstance>) 更改为 e.Consumer(container)
对此的任何帮助将不胜感激。
解决方案
推荐阅读
- python - 如何实现具有周期性边界条件的 ODE 解?
- amazon-web-services - 如何从 CloudFormation 中的父模板“导出”子网和 VPCId
- javascript - Flask 获取表单数据到 celery 任务队列
- javascript - Javascript 从原始 JSON 创建自定义格式的 JSON
- stata - 与多个命令一起使用时,捕获不起作用
- python - 如果一列包含指定列表中的某些值,如何在熊猫数据框中删除行
- python - Pytest 使用夹具参数化测试
- c++ - 无法将 std::array 容器拆分为 2 个子部分
- amazon-web-services - 用于生产 EC2 的 Docker
- c++ - 作为 `const&` 轻量级对象传递