我正在尝试:从端点获取消息。该消息将包含序列化的 MessageClass。只有当 MessageClass.MessageIdentifier 是唯一的时,我才想开始一个新的传奇。
我的传奇是这样的:
public class TrackingSaga:Saga<TrackingSagaData>,IAmStartedByMessages<InsertMessgae>,IHandleMessages<DeleteMessage>
{
private IBusinessService _trackingBusinessService;
public override void ConfigureHowToFindSaga()
{
ConfigureMapping<DeleteMessage>(s => s.ReferenceKey, p => p.ReferenceKey);
ConfigureMapping<InsertMessage>(s=>s.MessageIdentifier,p=>p.MessageIdentifier);
}
}
public void Handle(InsertMessage message)
{
Data=new TrackingSagaData(message.MessageClass)
{
MessageIdentifier = message.MessageClass.MessageIdentifier;
}
var trackingBusinessService = <<spring will provide me>> ;
trackingBusinessService.RecordNewMessage(message.MessageClass);
}
这是佐贺数据:
public class TrackingSagaData : ParentSagaData
{
public MessageClass MessageClass { private set; get; }
[Unique]
public Guid ReferenceKey { get { return MessageClass.ReferenceKey; } }
public string MessageIdentifier { get { return MessageClass.MessageIdentifier; } }
public bool IsMessageDeleted { set; get; }
public TrackingSagaData()
{
}
public TrackingSagaData(MessageClass messageClass)
{
MessageClass= messageClass;
IsMessageDeleted = false;
}
这是总线配置:
Configure.With()
.Log4Net()
.DefaultBuilder()
.XmlSerializer()
.RavenSubscriptionStorage()
.MsmqTransport()
.IsTransactional(true)
.PurgeOnStartup(false)
.RavenPersistence()
.UnicastBus();
当我运行我的端点时,控制台会显示警告:
2014-06-27 18:17:10,040 [Worker.14] WARN NServiceBus.Unicast.UnicastBus [(null)
] <(null)> - IncidentTrackingSaga failed handling message.
System.InvalidOperationException: Document 'trackingsagadata/1fcfd00d-6b97-4
dc2-aa09-18a1bd0631e2' no longer exists and was probably deleted
2014-06-27 18:17:10,070 [Worker.14] WARN NServiceBus.Unicast.Transport.Transact
ional.TransactionalTransport [(null)] - Failed raising 'transport message receiv
ed' event for message with ID=88d86af8-5925-4975-ac72-7e68885070ab\18218
NServiceBus.Unicast.Transport.TransportMessageHandlingFailedException: Exception
of type 'NServiceBus.Unicast.Transport.TransportMessageHandlingFailedException'
was thrown.
但是,如果我删除语句:
ConfigureMapping<InsertMessage>(s=>s.MessageIdentifier,p=>p.MessageIdentifier);
和
MessageIdentifier = message.MessageClass.MessageIdentifier;
然后整个应用程序运行良好,但新的 Saga 正在为相同的消息创建。我知道这一点,因为 RecordNewMessage() 将写入 DB,并且我看到同一 MessageClass.MessageIdentifier 的多个插入。