读取一批数据后,我想在服务中断时将数据返回到队列时遇到问题。如果我对amqp有所了解,可以使用认可,但是在Spring Bath文档中,我看不到任何信息。另外,我检查了AmqpItemReader的源代码,但没有看到任何可确认的流程。我需要使用此流程来实现自定义ItemReader还是错过了什么?
答案 0 :(得分:2)
typeof(SqlMapperExtensions).GetMethod(nameof(SqlMapperExtensions.Insert)).MakeGenericMethod(instance.GetType()).Invoke(null, new object[] { conn, instance, null, null});
使用简单的/// <summary>
/// Map list of SubquestionVM (SubquestionCurrentMapping) with data from current Component (EF model).
///
/// Why are we doing this?
/// Because when using the ExpressMapping to map 'SubQuestion' to 'SubQuestionVM', it creates a stack overflow error on the property 'SubquestionCurrentMapping'
/// which is caused by recursive VM.
/// I originaly tried alternative solution like:
/// changing 'List<SubQuestionVM>' for 'List<SubQuestionMappedVM>' but the website was not even loading (even with proper value in the new VM, and global.asax),
/// loading the faulty property later on, but any attempt to populate the object was resulting in an overflow at a moment or another.
/// Thankfully the manual mapping is proven to be effective and errorless!
/// </summary>
/// <param name="evaluationVM"></param>
/// <param name="component"></param>
private static void ManualMappingOfRecursiveSubquestionVM(CurrentEvaluationVM evaluationVM, Component component)
{
foreach (var subquestion in component?.Question?.SubQuestions)
{
//Find corresponding subquestionVM and manually map them
var subquestionVM = evaluationVM.CurrentComponent?.Question?.SubQuestions.Find(s => s.ID == subquestion.ID);
foreach (var subquestionMapping in subquestion.SubquestionCurrentMapping.ToList())
{
var tempSubquestionVM = new SubQuestionVM
{
ID = subquestionMapping.ID,
QuestionID = subquestionMapping.QuestionID,
Name = subquestionMapping.Name,
Clarification = subquestionMapping.Clarification,
Description = subquestionMapping.Description,
Index = subquestionMapping.Index,
CanSelectGoal = subquestionMapping.CanSelectGoal,
IsDate = subquestionMapping.IsDate,
Deprecated = subquestionMapping.Deprecated,
MultipleChoices = subquestionMapping.MultipleChoices.Map<ICollection<MultipleChoice>, List<MultipleChoiceVM>>(),
Answers = subquestionMapping.Answers.Map<ICollection<Answer>, List<AnswerVM>>()
};
subquestionVM.SubquestionCurrentMapping.Add(tempSubquestionVM);
}
}
}
操作,除非消息在事务中运行,否则该操作立即确认消息。
控制密码的唯一方法是使用事务(使用AmqpItemReader
)。
如果事务已分别提交或回滚,事务管理器将确认或重新排队消息。