使用依赖注入时的消息分区器?
message partitioner when using dependency injection?
如何在通过依赖注入 (autofac) 注册消费者时设置消息分区,就像这样
cfg.ReceiveEndpoint(host, c =>
{
c.LoadFrom(context);
c.Durable = true;
});
所有消息都是同一个标记接口
IDomainEvent<Guid>
我希望所有消息都按该接口的 ID 属性 进行分区。
我正在考虑尝试这样的事情:
c.Consumer<SomeViewConsumer>(context,ConfigurePartition<SomeViewConsumer>(partitioner));
c.Consumer<SomeOtherViewConsumer>(context,ConfigurePartition<SomeOtherViewConsumer>(partitioner));
private static Action<IConsumerConfigurator<TConsumer>> ConfigurePartition<TConsumer>(IPartitioner partitioner) where TConsumer : class
{
return n => n.Message<IDomainEvent<Guid>>(k => k.UsePartitioner(partitioner, consumeContext => consumeContext.Message.Id));
}
这行得通吗?
没有自动执行此操作的方法,因为必须知道消息类型才能配置 returns 分区键的分区程序委托。
我还担心在单个接收端点上使用太多不同的消息类型,方法是使用 .LoadFrom()
.
自动从容器中提取它们
如何在通过依赖注入 (autofac) 注册消费者时设置消息分区,就像这样
cfg.ReceiveEndpoint(host, c =>
{
c.LoadFrom(context);
c.Durable = true;
});
所有消息都是同一个标记接口
IDomainEvent<Guid>
我希望所有消息都按该接口的 ID 属性 进行分区。
我正在考虑尝试这样的事情:
c.Consumer<SomeViewConsumer>(context,ConfigurePartition<SomeViewConsumer>(partitioner));
c.Consumer<SomeOtherViewConsumer>(context,ConfigurePartition<SomeOtherViewConsumer>(partitioner));
private static Action<IConsumerConfigurator<TConsumer>> ConfigurePartition<TConsumer>(IPartitioner partitioner) where TConsumer : class
{
return n => n.Message<IDomainEvent<Guid>>(k => k.UsePartitioner(partitioner, consumeContext => consumeContext.Message.Id));
}
这行得通吗?
没有自动执行此操作的方法,因为必须知道消息类型才能配置 returns 分区键的分区程序委托。
我还担心在单个接收端点上使用太多不同的消息类型,方法是使用 .LoadFrom()
.