java-如何在具有多个服务器的同一数据库上使用骆驼JPA组件?
作者:互联网
我目前正在设置我的骆驼项目,并且无法使JPA poller在多个并发服务器上工作.
这是我的骆驼路线:
public class TicketPoller extends RouteBuilder {
/** The uri. */
private final String uri = "jpa://Ticket?consumeDelete=false&consumeLockEntity=true&consumer.SkipLockedEntity=true&consumer.query=select t from Ticket t where t.state=1";
@Override
public void configure() {
from(uri).to("log:input");
}
}
当我在Hibernate实体中直接进行轮询时,我使用@Consumed批注来更改票证状态:
@Entity
@Table(name = "TICKET", schema = "TEIKITEL")
public class Ticket implements Serializable {
private static final long serialVersionUID = 1L;
@Id
@Column(name = "TICKET_ID")
private String ticketId;
@Column(name = "STATE")
private int state;
...
@Consumed
public void changeTicketState() {
this.state = 2;
}
@Override
public String toString() {
return "Ticket@ticketId=" + this.ticketId;
}
}
当我从Eclipse在一台Tomcat服务器(Tomcat 8)上启动它时,它工作正常.
但是,当我在同一数据库上启动2个服务器轮询时,在TICKET表中插入一些行时会出现以下错误:
在我的第一台服务器上,我可以看到:
Hibernate: select TICKET_ID from TEIKITEL.TICKET where TICKET_ID =? for update nowait
2016-04-05 15:04:56,796 INFO [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] input(180) - Exchange[ExchangePattern: InOnly, BodyType: com.teikitel.model.entity.Ticket, Body: Ticket@ticketId=TICKET1]
Hibernate: select TICKET_ID from TEIKITEL.TICKET where TICKET_ID =? for update nowait
2016-04-05 15:04:56,812 INFO [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] input(180) - Exchange[ExchangePattern: InOnly, BodyType: com.teikitel.model.entity.Ticket, Body: Ticket@ticketId=TICKET2]
在我的第二台服务器上:
Hibernate: select TICKET_ID from TEIKITEL.TICKET where TICKET_ID =? for update nowait
2016-04-05 15:04:56,859 WARN [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] o.h.e.j.spi.SqlExceptionHelper(144) - SQL Error: 54, SQLState: 61000
2016-04-05 15:04:56,859 ERROR [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] o.h.e.j.spi.SqlExceptionHelper(146) - ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
Hibernate: select TICKET_ID from TEIKITEL.TICKET where TICKET_ID =? for update nowait
2016-04-05 15:04:56,874 WARN [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] o.h.e.j.spi.SqlExceptionHelper(144) - SQL Error: 54, SQLState: 61000
2016-04-05 15:04:56,874 ERROR [Camel (camel-1) thread #0 - jpa://com.teikitel.model.entity.Ticket] o.h.e.j.spi.SqlExceptionHelper(146) - ORA-00054: resource busy and acquire with NOWAIT specified or timeout expired
有人遇到过同样的问题吗?
洛伊奇
解决方法:
没有错误!
这些错误日志来自Hibernate,而不是Camel.
Camel执行其Job并跳过锁定在数据库中的元素(您触发的日志操作仅在一个实例上执行一次),但是它使用Hibernate执行其非阻塞选择请求. Hibernate抛出一个异常,该异常已被Camel BUT成功忽略,但在日志输出中显示了该错误.这就是您所看到的.
解决您的问题的方法是将Hibernate日志设置为更高的级别.
对于像这样的问题(synchro),请不要犹豫在骆驼中使用delay方法来更好地理解:
public class TicketPoller extends RouteBuilder {
/** The uri. */
private final String uri = "jpa://Ticket?consumeDelete=false&consumeLockEntity=true&consumer.SkipLockedEntity=true&consumer.query=select t from Ticket t where t.state=1";
@Override
public void configure() {
from(uri).delay(10000).to("log:input"); //wait 10sec
}
}
标签:jpa,hibernate,tomcat,apache-camel,java 来源: https://codeday.me/bug/20191118/2031255.html