2016-09-02 2 views
1

特定のメソッドを呼び出すときにMDBに送信するMapMessageを作成するStatelessSessionBeanがあります。 MDBメッセージの再配信を停止する

QueueConnection connection = null; 
QueueSession mSession = null; 
QueueSender messageProducer = null; 
try { 
    QueueConnectionFactory connectionFactory = (QueueConnectionFactory) home(session).getCTX().lookup(DocumentManagementTransactionUtil.QUEUE_CONNECTION_FACTORY); 
    connection = connectionFactory.createQueueConnection(); 
    mSession = connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE); 
    Queue dest = (Queue) home.getCTX().lookup(DocumentManagementTransactionUtil.QUEUE_DESTINATION); 
    messageProducer = mSession.createSender(dest); 
    messageProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT); 
    messageProducer.send(createJMSMessageFordocMessageReceiver(mSession, session, idnr, debugCode)); 
} catch (Exception ex) { 
    log.error("failed to start DocumentTransfer MDB", ex); 
    throw new AsaleException("failed to start DocumentTransfer MDB", ex); 
} finally { 
    try { if (messageProducer != null) messageProducer.close(); } catch (Exception e) { } 
    try { if (mSession != null) mSession.close(); } catch (Exception e) { } 
    try { if (connection != null) connection.stop(); connection.close(); } catch (Exception e) { } 
} 


は今私のMDBの私 onMessage方法で私はすべて私が私のメッセージから必要とそれを認める読み出します。

MapMessage msg = (MapMessage) message; 
project = msg.getLong("project"); 
Long lang = msg.getLong("lang"); 
int firm = msg.getInt("opFirm"); 
int sub = msg.getInt("opSub"); 
long user = msg.getLong("user"); 
int debugCode = msg.getInt("debugCode"); 

log.debug(project + prelog + "DocumentManagementMDBean... Retrieved Message: User: " + user + " Project: " + project + " JMS MessageID: " + message.getJMSMessageID() + " Redelivered: " + message.getJMSRedelivered()); 
message.acknowledge(); 


onMessageメソッドから戻ることなく(X分まで1)未定義の時間を要する長い動作が開始されます。

5分後、IDとredeliveredの状態から私のメッセージがわかるように、私が前にそれを認めたとしても、再配信されます。

私は間違ったことをしましたか、システムにメッセージを再配信しないように指示する方法がありますか?


編集:
@TransactionManagement(TransactionManagementType.BEAN) @MessageDriven(mappedName = DocumentManagementTransactionUtil.MAPPED_NAME, activationConfig = { @ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = DocumentManagementTransactionUtil.QUEUE_DESTINATION), @ActivationConfigProperty(propertyName = "dLQMaxResent", propertyValue = "0")})

+1

http://stackoverflow.com/questions/7362143/stop-message-being-redelivered-to-mdb –

答えて

1

メッセージ駆動型Beanについてのすべては、トランザクションです。

メッセージをキュー/トピックに配信できない場合、トランザクションは失敗し、ロールバックされます。

何らかの理由でメッセージを処理できない場合、MDBが実行されたトランザクションはロールバックされます。この場合、仕様では、コンテナがMDBへのメッセージ配信を再試行することが義務付けられています。

あなたのトランザクションはタイムアウトしているように見えます。トランザクション処理(データベースアクセスやEJB呼び出しなど)が失敗し、例外がスローされます。その後、コンテナはメッセージの処理を再試行します。

一般に、どのEJBメソッド(メッセージ駆動型Beanを含む)でも長期実行プロセスを実行しないでください。

wildflyとタグ付けしたので、Java EE 7実装を使用していると思います。このような場合は、JSR-352バッチ処理APIの使用を検討してください。

関連する問題