[jboss-jira] [JBoss JIRA] (WFLY-4633) CMT MDB response is not part of the transaction

JN JNC (JIRA) issues at jboss.org
Fri May 22 02:49:19 EDT 2015


     [ https://issues.jboss.org/browse/WFLY-4633?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

JN JNC updated WFLY-4633:
-------------------------
    Steps to Reproduce: 
MDB code

@TransactionManagement(TransactionManagementType.CONTAINER)
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue") })
public class SimpleRequestReplyListener implements MessageListener {

    @Resource
    private MessageDrivenContext messageDrivenContext;

    @Resource(mappedName = "java:/ConnectionFactory")
    public ConnectionFactory     connectfactory;
    @Resource(mappedName = "java:/queue/testReplyQueue")
    public Queue                 replyQueue;

    public void onMessage(Message message) {
        try {
            String messageText = ((TextMessage) message).getText();

            Connection conn = connectfactory.createConnection();
            conn.start();

            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            TextMessage messageResponse = session.createTextMessage();
            messageResponse.setText(messageText + " - OK DONE");
            messageResponse.setJMSCorrelationID(message.getJMSCorrelationID());

            MessageProducer producer = session.createProducer(replyQueue);
            producer.send(messageResponse);

            session.close();

            System.out.println("Wait a while before returning");

            if (messageText.contains("ROLLBACK")) {
                messageDrivenContext.setRollbackOnly();
            }

        } catch (Exception e) {
            throw new EJBException("Exception : " + e.getMessage());
        } catch (Throwable e) {
            throw new EJBException("Throwable Exception : " + e.getMessage());
        }
    }

}


Test case

  @Test
    public void testRequestReplyListener() throws NamingException, JMSException, InterruptedException {
        
        Properties env1 = new Properties();
        env1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        env1.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
        Context initialContext = new InitialContext(env1);

        ConnectionFactory jmsCF = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
        assertNotNull(jmsCF);

        final Object queue = initialContext.lookup("jms/queue/testQueue");
        assertNotNull(queue);
        assertTrue(queue instanceof Queue);
        
        final Object replyQueue = initialContext.lookup("jms/queue/testReplyQueue");
        assertNotNull(replyQueue);
       assertTrue(replyQueue instanceof Queue);
        final Connection connection = jmsCF.createConnection();
       connection.start();
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        final MessageProducer outgoing = session.createProducer((Destination) queue);
        TextMessage message = session.createTextMessage("DO SOMETHING");
        long time = System.currentTimeMillis();
        String corId = "testRequestReply_correlationID" + time;
        message.setJMSCorrelationID(corId);
       outgoing.send(message);
       
        MessageConsumer incoming = session.createConsumer((Destination) replyQueue, "JMSCorrelationID='" + corId + "'");
        Message response = incoming.receive(10000);
        assertNotNull(response);
        String text = ((TextMessage) response).getText();
        assertEquals("Error response doesnt contains expected message: " + text, "DO SOMETHING - OK DONE", text);
        
        message = session.createTextMessage("DO SOMETHING BUT ROLLBACK");
        time = System.currentTimeMillis();
       corId = "testRequestReply_correlationID" + time;
       message.setJMSCorrelationID(corId);
       outgoing.send(message);
      
       incoming = session.createConsumer((Destination) replyQueue, "JMSCorrelationID='" + corId + "'");
       response = incoming.receive(10000);
       connection.close();
       assertNull("Response is not null: " + ((TextMessage) response).getText(), response);       
}

  was:
MDB code

@TransactionManagement(TransactionManagementType.CONTAINER)
@MessageDriven(activationConfig = { @ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"), @ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/testQueue") })
public class SimpleRequestReplyListener implements MessageListener {

    @Resource
    private MessageDrivenContext messageDrivenContext;

    @Resource(mappedName = "java:/ConnectionFactory")
    public ConnectionFactory     connectfactory;
    @Resource(mappedName = "java:/queue/testReplyQueue")
    public Queue                 replyQueue;

    public void onMessage(Message message) {
        try {
            String messageText = ((TextMessage) message).getText();

            Connection conn = connectfactory.createConnection();
            conn.start();

            Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
            TextMessage messageResponse = session.createTextMessage();
            messageResponse.setText(messageText + " - OK DONE");
            messageResponse.setJMSCorrelationID(message.getJMSCorrelationID());

            MessageProducer producer = session.createProducer(replyQueue);
            producer.send(messageResponse);

            session.close();

            System.out.println("Wait a while before returning");

            if (messageText.contains("ROLLBACK")) {
                messageDrivenContext.setRollbackOnly();
            }

        } catch (Exception e) {
            throw new EJBException("Exception : " + e.getMessage());
        } catch (Throwable e) {
            throw new EJBException("Throwable Exception : " + e.getMessage());
        }
    }

}


Test case

  @Test
    public void testRequestReplyListener() throws NamingException, JMSException, InterruptedException {

        Properties env1 = new Properties();
        env1.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        env1.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
        Context initialContext = new InitialContext(env1);

        ConnectionFactory jmsCF = (ConnectionFactory) initialContext.lookup("jms/RemoteConnectionFactory");
        assertNotNull(jmsCF);

        final Object queue = initialContext.lookup("jms/queue/testQueue");
        assertNotNull(queue);
        assertTrue(queue instanceof Queue);

        final Object replyQueue = initialContext.lookup("jms/queue/testReplyQueue");
        assertNotNull(replyQueue);
        assertTrue(replyQueue instanceof Queue);

        final Connection connection = jmsCF.createConnection();
        connection.start();
        final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        final MessageProducer outgoing = session.createProducer((Destination) queue);
        TextMessage message = session.createTextMessage("DO SOMETHING");
        long time = System.currentTimeMillis();
        String corId = "testRequestReply_correlationID" + time;
        message.setJMSCorrelationID(corId);
        outgoing.send(message);

        MessageConsumer incoming = session.createConsumer((Destination) replyQueue, "JMSCorrelationID='" + corId + "'");
        Message response = incoming.receive(10000);

        assertNotNull(response);
        String text = ((TextMessage) response).getText();
        assertEquals("Error response doesnt contains expected message: " + text, "DO SOMETHING - OK DONE", text);

        message = session.createTextMessage("DO SOMETHING BUT ROLLBACK");
        time = System.currentTimeMillis();
        corId = "testRequestReply_correlationID" + time;
        message.setJMSCorrelationID(corId);
        outgoing.send(message);

        incoming = session.createConsumer((Destination) replyQueue, "JMSCorrelationID='" + corId + "'");
        response = incoming.receive(10000);
        connection.close();
        
        assertNull("Response is not null: " + ((TextMessage) response).getText(), response);       
    }



> CMT MDB response is not part of the transaction
> -----------------------------------------------
>
>                 Key: WFLY-4633
>                 URL: https://issues.jboss.org/browse/WFLY-4633
>             Project: WildFly
>          Issue Type: Bug
>          Components: EJB, JMS
>    Affects Versions: JBoss AS7 7.2.0.Final, 8.2.0.Final
>            Reporter: JN JNC
>            Assignee: Jeff Mesnil
>
> My application uses container managed MDB to process client request received on a queue and to send them response on a reply queue.
> It seems the response which is sent within the onMessage method scope is being received by the client before onMessage completion and outside same transaction scope.
> This is an issue as transaction could be rollbacked and client will receive a success status to its request.
> The MDB implementation below illustrate the issue, response is effectively sent even with a rollback only.



--
This message was sent by Atlassian JIRA
(v6.3.15#6346)


More information about the jboss-jira mailing list