(带有 MultiBus 的 Masstransit Saga)如何从 Saga 向另一辆公共汽车发布消息?
(Masstransit Saga with MultiBus) How can i publish message to another bus from Saga?
来自
我尝试将 saga 与多总线一起使用。但是当我将 ISecondBus
注入 Saga 时。
出了点问题。我的程序卡住了。
public class TestSaga : MassTransitStateMachine<TestState>
{
public TestSaga(ISecondBus secondBus)
{
if (secondBus is null)
{
throw new ArgumentNullException(nameof(secondBus));
}
}
}
program.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);
});
}));
});
您不能将运行时依赖项注入 saga 状态机。如果您想从状态机发布到另一条总线,您需要创建一个自定义 activity 并从您的状态机行为中调用它。
https://masstransit-project.com/usage/sagas/automatonymous.html#custom
来自
我尝试将 saga 与多总线一起使用。但是当我将 ISecondBus
注入 Saga 时。
出了点问题。我的程序卡住了。
public class TestSaga : MassTransitStateMachine<TestState>
{
public TestSaga(ISecondBus secondBus)
{
if (secondBus is null)
{
throw new ArgumentNullException(nameof(secondBus));
}
}
}
program.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);
});
}));
});
您不能将运行时依赖项注入 saga 状态机。如果您想从状态机发布到另一条总线,您需要创建一个自定义 activity 并从您的状态机行为中调用它。
https://masstransit-project.com/usage/sagas/automatonymous.html#custom