oracle – JMS setTimeToLive

我正在使用JMS主题发布消息.在消息生成器上我设置了setTimeToLive.我希望在16小时后删除消息.但即使在16个小时之后,消息仍然存在于数据库和主题中.有什么想法吗?我错过了什么吗?

private static final long DEFAULT_TIME_TO_LIVE = 16 * 60 * 60 * 1000;
....
session = getSession(jndiContext);
MessageProducer mp = createTopicMessageProducer(session, jndiContext, topicName);
mp.setTimeToLive(DEFAULT_TIME_TO_LIVE);
Message msg = session.createObjectMessage(obj);
....

我的oracele-jdbc2-service.xml有以下查询

<mbean code="org.jboss.mq.pm.jdbc2.PersistenceManager"
  name="jboss.mq:service=JDBCPersistenceManager">
    <depends optional-attribute-name="ConnectionManager">jboss.jca:service=DataSourceBinding,name=OracleDS</depends>
    <attribute name="SqlProperties">
      INSERT_EMPTY_BLOB = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, MESSAGEBLOB, TXID, TXOP) VALUES(?,?,EMPTY_BLOB(),?,?)
      LOCK_EMPTY_BLOB = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID = ? AND DESTINATION = ? FOR UPDATE
      BLOB_TYPE=BINARYSTREAM_BLOB
      INSERT_TX = INSERT INTO JMS_TRANSACTIONS (TXID) values(?)
      INSERT_MESSAGE = INSERT INTO JMS_MESSAGES (MESSAGEID, DESTINATION, MESSAGEBLOB, TXID, TXOP) VALUES(?,?,?,?,?)
      SELECT_ALL_UNCOMMITED_TXS = SELECT TXID FROM JMS_TRANSACTIONS
      SELECT_MAX_TX = SELECT MAX(TXID) FROM (SELECT MAX(TXID) AS TXID FROM JMS_TRANSACTIONS UNION SELECT MAX(TXID) AS TXID FROM JMS_MESSAGES)
      DELETE_ALL_TX = DELETE FROM JMS_TRANSACTIONS
      SELECT_MESSAGES_IN_DEST = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE DESTINATION=?
      SELECT_MESSAGE_KEYS_IN_DEST = SELECT MESSAGEID FROM JMS_MESSAGES WHERE DESTINATION=?
      SELECT_MESSAGE = SELECT MESSAGEID, MESSAGEBLOB FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?
      MARK_MESSAGE = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE MESSAGEID=? AND DESTINATION=?
      UPDATE_MESSAGE = UPDATE JMS_MESSAGES SET MESSAGEBLOB=? WHERE MESSAGEID=? AND DESTINATION=?
      UPDATE_MARKED_MESSAGES = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=?
      UPDATE_MARKED_MESSAGES_WITH_TX = UPDATE JMS_MESSAGES SET TXID=?, TXOP=? WHERE TXOP=? AND TXID=?
      DELETE_MARKED_MESSAGES_WITH_TX = DELETE FROM JMS_MESSAGES MESS WHERE TXOP=? AND EXISTS (SELECT TXID FROM JMS_TRANSACTIONS TX WHERE TX.TXID = MESS.TXID)
      DELETE_TX = DELETE FROM JMS_TRANSACTIONS WHERE TXID = ?
      DELETE_MARKED_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXID=? AND TXOP=?
      DELETE_TEMPORARY_MESSAGES = DELETE FROM JMS_MESSAGES WHERE TXOP='T'
      DELETE_MESSAGE = DELETE FROM JMS_MESSAGES WHERE MESSAGEID=? AND DESTINATION=?
      CREATE_MESSAGE_TABLE = CREATE TABLE JMS_MESSAGES ( MESSAGEID INTEGER NOT NULL, \
         DESTINATION VARCHAR(255) NOT NULL, TXID INTEGER, TXOP CHAR(1), \
         MESSAGEBLOB BLOB, PRIMARY KEY (MESSAGEID, DESTINATION) )
      CREATE_IDX_MESSAGE_TXOP_TXID = CREATE INDEX JMS_MESSAGES_TXOP_TXID ON JMS_MESSAGES (TXOP, TXID)
      CREATE_IDX_MESSAGE_DESTINATION = CREATE INDEX JMS_MESSAGES_DESTINATION ON JMS_MESSAGES (DESTINATION)
      CREATE_TX_TABLE = CREATE TABLE JMS_TRANSACTIONS ( TXID INTEGER, PRIMARY KEY (TXID) )
      CREATE_TABLES_ON_STARTUP = TRUE
    </attribute>
    <!-- Uncomment to override the transaction timeout for recovery per queue/subscription, in seconds -->
    <!--attribute name="RecoveryTimeout">0</attribute-->
    <!-- The number of blobs to load at once during message recovery -->
    <attribute name="RecoverMessagesChunk">0</attribute>
  </mbean>

最佳答案 JMS规范不要求提供程序删除该消息.有些提供商会很快删除过期的邮件.有些人在浏览或获取操作评估消息到期之前不会删除它们.无论客户端是否尝试浏览或获取消息,有些人都会经常随意删除消息.保持后台任务存活以快速删除过期的消息显然会消耗资源,因此大多数提供商会选择某种程度的“懒惰”到期.

有趣的是,JMS规范还声明“客户端不应该接收已过期的消息;但是,JMS并不保证不会发生这种情况.”大多数提供商都能很好地防止过期消息被传递,但这并不是一项艰难的要求.

所以答案是尽管在到期后看到DB中或队列/主题上的消息可能不是直观的“预期”行为,但它在规范内.更重要的问题是所述消息是否已发送到您的应用程序.希望它不是 – 但即使它是,规范也不排除这一点.

点赞