我有一条Camel路线,如下所示:
<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路由在结束前提交使用列的状态?中间处理器需要花费大量时间,而且我希望它在数据库完成之前已经被使用(并标记了)。
答案 0 :(得分:1)
我发现这样做的一种方法是将JPA对象路由到一个单独的线程来保持它,而另一个线程进行处理:
<route id="pickUpEntries">
<from
uri="jpa:/batchprocessor.model.BatchProcess?consumer.namedQuery=unconsumedEntries&?consumeDelete=false&persistenceUnit=persistenceProvider&consumeLockEntity=true" />
<process ref="Consume" />
<multicast parallelProcessing="true">
<to
uri="jpa://batchprocessor.model.BatchProcess?persistenceUnit=persistenceProvider" />
<to uri="direct:process" />
</multicast>
</route>
不完全令人满意,但在这种情况下完成工作。我还必须删除@Consumed。令人困惑的是,它在路线完成后处理,而不是在处理物品时处理。