次のようなキャメルルートがあります。
<routeContext id="rollover-route" xmlns="http://camel.apache.org/schema/spring">
<route id="pickUpEntries">
<from uri="jpa://cameltest.model.CamelTest?consumer.namedQuery=unconsumedEntries&?consumeDelete=false&persistenceUnit=persistenceProvider&consumeLockEntity=true"/>
<split executorServiceRef="rolloverProfile">
<simple>${body}</simple>
<setProperty propertyName="taskId">
<simple>${body.taskId}</simple>
</setProperty>
<setProperty propertyName="providerId">
<simple>${body.providerId}</simple>
</setProperty>
<setProperty propertyName="intakeId">
<simple>${body.intakeId}</simple>
</setProperty>
<setProperty propertyName="consumed">
<simple>${body.consumed}</simple>
</setProperty>
<to uri="jpa://cameltest.model.CamelTest?persistenceUnit=persistenceProvider"/>
<process ref="JPAToMCS"/>
<process ref="MCSRequest"/>
<process ref="MCSToJPA"/>
<to uri="jpa://cameltest.model.CamelTest?persistenceUnit=persistenceProvider"/>
</split>
</route>
</routeContext>
CamelTest JPA エンティティは次のとおりです。
package cameltest.model;
import java.io.Serializable;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.NamedQuery;
import javax.persistence.Table;
import org.apache.camel.component.jpa.Consumed;
import org.springframework.transaction.annotation.Transactional;
@Entity
@Table(name="CamelTestTable")
@NamedQuery(name = "unconsumedEntries", query = "select c from CamelTest c where c.consumed = 0")
public class CamelTest implements Serializable {
private static final long serialVersionUID = 5608716486854758950L;
@Id
private Integer taskId;
private Integer providerId;
private Integer intakeId;
private Integer consumed;
private Integer complete;
public CamelTest()
{}
public CamelTest(Integer taskId, Integer providerId, Integer intakeId,
Integer consumed, Integer complete) {
super();
this.taskId = taskId;
this.providerId = providerId;
this.intakeId = intakeId;
this.consumed = consumed;
this.complete = complete;
}
public Integer getComplete() {
return complete;
}
public void setComplete(Integer complete) {
this.complete = complete;
}
public Integer getConsumed() {
return consumed;
}
public void setConsumed(Integer consumed) {
this.consumed = consumed;
}
public Integer getTaskId() {
return taskId;
}
public void setTaskId(Integer taskId) {
this.taskId = taskId;
}
public Integer getProviderId() {
return providerId;
}
public void setProviderId(Integer providerId) {
this.providerId = providerId;
}
public Integer getIntakeId() {
return intakeId;
}
public void setIntakeId(Integer intakeId) {
this.intakeId = intakeId;
}
@Override
public String toString() {
return "CamelTest [taskId=" + taskId + ", providerId=" + providerId
+ ", intakeId=" + intakeId + "]";
}
@Consumed
public void markAsConsumed()
{
setConsumed(getConsumed() + 1);
}
}
Camel ルートが終了前に消費列のステータスを強制的にコミットするにはどうすればよいですか? 中間プロセッサには多くの時間がかかります。完了する前にデータベースにコミットされて消費されたという事実が必要です (そしてそれがマークされます)。