本文介绍了骆驼JPA组件 - 迫使提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个骆驼的路线,看起来像这样:

I have a Camel route which looks like this:

<routeContext id="rollover-route" xmlns="http://camel.apache.org/schema/spring">
    <route id="pickUpEntries">
        <from uri="jpa://cameltest.model.CamelTest?consumer.namedQuery=unconsumedEntries&amp;?consumeDelete=false&amp;persistenceUnit=persistenceProvider&amp;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实体是:

The CamelTest JPA Entity is:

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);
    }

}

我怎么可以强制骆驼航线年底前提交消耗列的状态?中间的处理器需要花费大量的时间,我想,它已经被消耗提交到数据库,事实上,它已经完成之前(和标记)。

How can I force the Camel route to commit the status of the consume column before the end? The middle processor takes a lot of time and I want the fact that it has been consumed committed to the database before it has been completed (and that marked).

推荐答案

我发现这样做的一种方法是将路由JPA的目的是一个单独的线程来坚持它,而另一个线程做的处理:

One way I found of doing this is to route the JPA object to a separate thread to persist it, whilst the other thread does the processing:

        <route id="pickUpEntries">
        <from
            uri="jpa:/batchprocessor.model.BatchProcess?consumer.namedQuery=unconsumedEntries&amp;?consumeDelete=false&amp;persistenceUnit=persistenceProvider&amp;consumeLockEntity=true" />
        <process ref="Consume" />
        <multicast parallelProcessing="true">
            <to
                uri="jpa://batchprocessor.model.BatchProcess?persistenceUnit=persistenceProvider" />
            <to uri="direct:process" />
        </multicast>
    </route>

不完全满意,但做这项工作在这种情况下。我也不得不删除@Consumed。令人困惑的是它处理后的路线完成,而随着项目进行处理。

Not entirely satisfactory, but does the job in this case. I also had to remove the @Consumed. Confusingly it processes AFTER the routes are finished, rather that as the item is processed.

这篇关于骆驼JPA组件 - 迫使提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 01:00