如何在 Wildfly AS 8 中为数据源实现 EJB 计时器服务

How to implement EJB timer service in Wildfly AS 8 for a datasource

我正在将 EAR 应用程序从 JBoss AS 6 迁移到 Wildfly AS 8.2.0。在这样做的同时,我面临着在 Wildfly AS 中为 standalone-full-ha.xml.

中定义的数据源 TestSybaseDB 实施 EJB timer service 的问题

仅供参考,以下是与 JBoss AS 6 相关的文件,这些文件与数据源 TestSybaseDB 的 EJB3 定时器服务实现相关。在 JBoss 6 AS 的以下文件中,定义了数据源名称,我相信这些更改足以在 JBoss 6 AS 中为数据库实现 EJB 计时器服务。

persistence.xml

path: ${JBOSS_HOME}\common\deploy\jboss-ejb3-timerservice-mk2.jar\META-INF\persistence.xml

<jta-data-source>java:/TestSybaseDB</jta-data-source>

ejb2-timer-service.xml

path: ${JBOSS_HOME}\server\default\deploy\ejb2-timer-service.xml

<depends>jboss.jdbc:datasource=TestSybaseDB,service=metadata</depends>
<depends optional-attribute-name="DataSource">jboss.jca:service=DataSourceBinding,name=TestSybaseDB</depends>


但是为了在Wildfly AS中实现,我已经根据Sybase DB转换了timer-sql.properties的内容。

计时器-sql.properties

path: ${JBOSS_HOME}\modules\system\layers\base\org\jboss\as\ejb3\main\timers\timer-sql.properties

create-table=CREATE TABLE JBOSS_EJB_TIMER (ID VARCHAR PRIMARY KEY NOT NULL, TIMED_OBJECT_ID VARCHAR NOT NULL, INITIAL_DATE DATETIME, REPEAT_INTERVAL BIGINT, NEXT_DATE DATETIME, PREVIOUS_RUN DATETIME, PRIMARY_KEY VARCHAR, INFO VARCHAR, TIMER_STATE VARCHAR, SCHEDULE_EXPR_SECOND VARCHAR, SCHEDULE_EXPR_MINUTE VARCHAR, SCHEDULE_EXPR_HOUR VARCHAR,SCHEDULE_EXPR_DAY_OF_WEEK VARCHAR, SCHEDULE_EXPR_DAY_OF_MONTH VARCHAR, SCHEDULE_EXPR_MONTH VARCHAR, SCHEDULE_EXPR_YEAR VARCHAR, SCHEDULE_EXPR_START_DATE VARCHAR, SCHEDULE_EXPR_END_DATE VARCHAR, SCHEDULE_EXPR_TIMEZONE VARCHAR, AUTO_TIMER SMALLINT, TIMEOUT_METHOD_NAME VARCHAR, TIMEOUT_METHOD_DECLARING_CLASS VARCHAR, TIMEOUT_METHOD_DESCRIPTOR VARCHAR, CALENDAR_TIMER SMALLINT, PARTITION_COL VARCHAR NOT NULL);
create-timer=INSERT INTO JBOSS_EJB_TIMER (ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER, PARTITION_COL) VALUES (, , , , , , , , , , , , , , , , , , , , , , , , );
update-timer=UPDATE JBOSS_EJB_TIMER SET NEXT_DATE=, PREVIOUS_RUN=, TIMER_STATE= WHERE TIMED_OBJECT_ID= and ID= AND PARTITION_COL=;
delete-timer=DELETE FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID= and ID= AND PARTITION_COL=;
load-all-timers=SELECT ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID= AND PARTITION_COL=;
load-timer=SELECT ID, TIMED_OBJECT_ID, INITIAL_DATE, REPEAT_INTERVAL, NEXT_DATE, PREVIOUS_RUN, PRIMARY_KEY, INFO, TIMER_STATE, SCHEDULE_EXPR_SECOND, SCHEDULE_EXPR_MINUTE, SCHEDULE_EXPR_HOUR, SCHEDULE_EXPR_DAY_OF_WEEK, SCHEDULE_EXPR_DAY_OF_MONTH, SCHEDULE_EXPR_MONTH, SCHEDULE_EXPR_YEAR, SCHEDULE_EXPR_START_DATE, SCHEDULE_EXPR_END_DATE, SCHEDULE_EXPR_TIMEZONE, AUTO_TIMER, TIMEOUT_METHOD_NAME, TIMEOUT_METHOD_DECLARING_CLASS, TIMEOUT_METHOD_DESCRIPTOR, CALENDAR_TIMER FROM JBOSS_EJB_TIMER WHERE TIMED_OBJECT_ID= and ID= AND PARTITION_COL=;
create-table.hsql=CREATE TABLE JBOSS_EJB_TIMER (ID VARCHAR PRIMARY KEY NOT NULL, TIMED_OBJECT_ID VARCHAR NOT NULL, INITIAL_DATE DATETIME, REPEAT_INTERVAL BIGINT, NEXT_DATE DATETIME, PREVIOUS_RUN DATETIME, PRIMARY_KEY VARCHAR, INFO VARCHAR, TIMER_STATE VARCHAR, SCHEDULE_EXPR_SECOND VARCHAR, SCHEDULE_EXPR_MINUTE VARCHAR, SCHEDULE_EXPR_HOUR VARCHAR,SCHEDULE_EXPR_DAY_OF_WEEK VARCHAR, SCHEDULE_EXPR_DAY_OF_MONTH VARCHAR, SCHEDULE_EXPR_MONTH VARCHAR, SCHEDULE_EXPR_YEAR VARCHAR, SCHEDULE_EXPR_START_DATE VARCHAR, SCHEDULE_EXPR_END_DATE VARCHAR, SCHEDULE_EXPR_TIMEZONE VARCHAR, AUTO_TIMER SMALLINT, TIMEOUT_METHOD_NAME VARCHAR, TIMEOUT_METHOD_DECLARING_CLASS VARCHAR, TIMEOUT_METHOD_DESCRIPTOR VARCHAR, CALENDAR_TIMER SMALLINT, PARTITION_COL VARCHAR NOT NULL);CREATE INDEX JBOSS_EJB_TIMER_IDENX ON JBOSS_EJB_TIMER (PARTITION_COL, TIMED_OBJECT_ID);

standalone-full-ha.xml

中的定时器服务定义
<timer-service thread-pool-name="timer" default-data-store="clustered-store">
    <data-stores>
        <database-data-store name="clustered-store" datasource-jndi-name="java:/TestSybaseDB" partition="timer"/>
    </data-stores>
</timer-service>

我收到以下错误:

错误

ERROR [org.jboss.as.ejb3] (MSC service thread 1-2) JBAS014263: Cannot create table for timer persistence: com.sybase.jdbc4.jdbc.SybSQLException: There is already an object named 'JBOSS_EJB_TIMER' in the database.

at com.sybase.jdbc4.tds.Tds.a(Unknown Source)
at com.sybase.jdbc4.tds.Tds.nextResult(Unknown Source)
at com.sybase.jdbc4.jdbc.ResultGetter.nextResult(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.nextResult(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.updateLoop(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.executeUpdate(Unknown Source)
at com.sybase.jdbc4.jdbc.SybStatement.executeUpdate(Unknown Source)
at org.jboss.jca.adapters.jdbc.WrappedStatement.executeUpdate(WrappedStatement.java:375)
at org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence.runCreateTable(DatabaseTimerPersistence.java:150) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence.start(DatabaseTimerPersistence.java:117) [wildfly-ejb3-8.2.0.Final.jar:8.2.0.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]

根据上述错误,我认为 timer-sql.properties 中的 create-table 是导致问题的原因,因此,我尝试删除它但出现以下错误。

ERROR [org.jboss.msc.service.fail] (MSC service thread 1-8) MSC000001: Failed to start service jboss.ejb3.timerService.timerPersistence.clustered-store: org.jboss.msc.service.StartException in service jboss.ejb3.timerService.timerPersistence.clustered-store: Failed to start service
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1904) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_67]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_67]
at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]
Caused by: java.lang.NullPointerException
at org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence.runCreateTable(DatabaseTimerPersistence.java:146)
at org.jboss.as.ejb3.timerservice.persistence.database.DatabaseTimerPersistence.start(DatabaseTimerPersistence.java:117)
at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1948) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1881) [jboss-msc-1.2.2.Final.jar:1.2.2.Final]
... 3 more

ERROR [org.jboss.as.controller.management-operation] (Controller Boot Thread) JBAS014613: Operation ("add") failed - address: ([
("subsystem" => "ejb3"),
("service" => "timer-service"),
("database-data-store" => "clustered-store")
]) - failure description: {"JBAS014671: Failed services" => {"jboss.ejb3.timerService.timerPersistence.clustered-store" => "org.jboss.msc.service.StartException in service jboss.ejb3.timerService.timerPersistence.clustered-store: Failed to start service
Caused by: java.lang.NullPointerException"}}

JBAS014777:   Services which failed to start:      service jboss.ejb3.timerService.timerPersistence.clustered-store: org.jboss.msc.service.StartException in service jboss.ejb3.timerService.timerPersistence.clustered-store: Failed to start service  

谁能帮我解决错误并为 Wildfly AS 中定义的数据源配置 EJB 计时器服务。

我想你可以删除timer-sql.properties文件的最后一行。 如果这些语句在 Sybase 中运行良好,它应该可以运行。

我用过这个 article,它对我来说效果很好。我正在使用 Postgres 而不是 Sybase