[英](Masstransit Saga with MultiBus) How can i publish message to another bus from Saga?
From Is it possible to have a MassTransit Saga react to events that come from more that one bus (multibus)?来自是否有可能让 MassTransit Saga 对来自不止一个总线(多总线)的事件做出反应?
I try to use saga with multibus.我尝试将 saga 与多总线一起使用。 But when I inject ISecondBus
into Saga.但是当我将ISecondBus
注入 Saga 时。 Something is wrong.出了点问题。 my program is stuck.我的程序卡住了。
public class TestSaga : MassTransitStateMachine<TestState>
{
public TestSaga(ISecondBus secondBus)
{
if (secondBus is null)
{
throw new ArgumentNullException(nameof(secondBus));
}
}
}
program.cs程序.cs
services.AddMassTransit(x =>
{
x.AddSagaStateMachine<TestSaga, TestState>()
.RedisRepository(redisCfg =>
{
redisCfg.DatabaseConfiguration("127.0.0.1:6379,password=");
});
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("rabbitmq://127.0.0.1:5672/A", hostConfig =>
{
hostConfig.Username("xxxx");
hostConfig.Password("xxxx");
});
cfg.ReceiveEndpoint("some-queue", e =>
{
e.PrefetchCount = 1;
e.UseInMemoryOutbox();
e.ConfigureSaga<TestState>(provider);
});
}));
});
services.AddMassTransit<ISecondBus>(x =>
{
x.AddSagaStateMachine<TestSaga, TestState>()
.RedisRepository(redisCfg =>
{
redisCfg.DatabaseConfiguration("127.0.0.1:6379,password=");
});
x.AddBus(provider => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
cfg.Host("rabbitmq://127.0.0.1:5672/B", hostConfig =>
{
hostConfig.Username("xxx");
hostConfig.Password("xxx");
});
cfg.ReceiveEndpoint("some-queue", e =>
{
e.PrefetchCount = 1;
e.UseInMemoryOutbox();
e.ConfigureSaga<TestState>(provider);
});
}));
});
You can't inject runtime dependencies into the saga state machine.您不能将运行时依赖项注入 saga state 机器。 If you want to publish to another bus from a state machine, you'll need to create a custom activity and call that from your state machine behavior.如果你想从 state 机器发布到另一条总线,你需要创建一个自定义活动并从你的 state 机器行为中调用它。
https://masstransit-project.com/usage/sagas/automatonymous.html#custom https://masstransit-project.com/usage/sagas/automatonymous.html#custom
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.