以下是我在我的传奇类“ MassTransitStateMachine”上遇到的错误。我不确定为什么切换到内存传奇数据库时会出现此错误,因为它正在工作。错误:MassTransit.Messages警告:0:R-RETRY rabbitmq:// localhost / IMembersLoginSaga 7c2d0000-8af1-d8cb-0f3a-08d6e7b9f5b1元素“ _id”与ct.members.domain.Models.MemberLoginStateInstance类的任何字段或属性都不匹配。,System.FormatException:元素'_id'与ct.members.domain.Models.MemberLoginStateInstance.MassTransit.Messages类的任何字段或属性都不匹配:0:R-FAULT rabbitmq:// localhost / IMembersLoginSaga 7c2d0000-8af1- d8cb-0f3a-08d6e7b9f5b1 ct.component.abstraction.Consumer.Members.IMemberLoginResponse ct.members.domain.Models.MemberLoginStateInstance(00:00:00.0045448)元素'_id'与ct.members.domain类的任何字段或属性都不匹配.Models.MemberLoginStateInstance。,System.FormatException:元素“ _id”与ct.members.domain.Models.MemberLoginStateInstance类的任何字段或属性都不匹配。
InstanceState(s => s.CurrentState);
Event(() => Create, x =>
x.CorrelateById(ml => ml.CorrelationId, context => context.Message.CorrelationId));
Event(() => Response, x => x.CorrelateById(context => context.Message.CorrelationId));
Initially(
When(Create)
.Then(context =>
{
context.Instance.CorrelationId = context.Data.CorrelationId;
context.Instance.EmailAddress = context.Data.EmailAddress;
context.Instance.Password = context.Data.Password;
context.Instance.Created = DateTime.Now;
})
.ThenAsync(context => Console.Out.WriteLineAsync($"member email is {context.Instance.EmailAddress}"))
.Publish(context => new MemberloginPublish(context.Instance))
.TransitionTo(Approve)
);
During(Approve,
When(Response)
.Then(context =>
{
context.Instance.CorrelationId = context.Data.CorrelationId;
context.Instance.Token = context.Data.Token;
})
.ThenAsync(context => Console.Out.WriteLineAsync($"Token: {context.Data.Token} received"))
.Finalize());
SetCompletedWhenFinalized();
private Event<IMembersLoginSaga> Create { get; set; }
private Event<IMemberLoginResponse> Response { get; set; }
private State Approve { get; set; }
Startup class
opt.AddBus(context => Bus.Factory.CreateUsingRabbitMq(cfg =>
{
var host = cfg.Host(new Uri(MasstransitSettings["Server"]), hostConfigurator =>
{
hostConfigurator.Username(MasstransitSettings["UserName"]);
hostConfigurator.Password(MasstransitSettings["Password"]);
});
cfg.ReceiveEndpoint(host, nameof(IMembersLoginSaga), ep =>
{
ep.PrefetchCount = 16;
ep.UseMessageRetry(r => r.Interval(2, 100));
ep.ConfigureConsumers(context);
ep.StateMachineSaga(new MemberLoginStateMachine(),
new MongoDbSagaRepository<MemberLoginStateInstance>(dbconnection,new MongoDbSagaConsumeContextFactory())
//new InMemorySagaRepository<MemberLoginStateInstance>()
);
});
}));
答案 0 :(得分:0)
在传奇机器状态实例类中的mongoryId上装饰一个mongoDB属性,即BsonId()。这将解决问题