Andrzej Więcław created AMQ-4476:
------------------------------------

             Summary: ActiveMQ WebSphere 7 JMS Provider - MBD - message 
consumed even though transaction marked for rollback
                 Key: AMQ-4476
                 URL: https://issues.apache.org/jira/browse/AMQ-4476
             Project: ActiveMQ
          Issue Type: Bug
          Components: JMS client
    Affects Versions: 5.8.0, 5.7.0, 5.6.0
         Environment: Windows Server 2008 R2
            Reporter: Andrzej Więcław


I have an EAR that is deployed to Websphere 7.
It includes EJB module containing a couple of MDBs that are listening on 
Message Listener Port, pointing to connection factory and queue exposed by 
custom ActiveMQ JMS Provider.

ActiveMQ JMS Provider configuration script (JACL):
{code}
import sys

jmsProviderUrl = "tcp://x.x.x.x:61616"    
# Retrieve cell name
cell = AdminControl.getCell()
scope = "Cell=" + cell
jmsProviderName = "ActiveMQ"
node = sys.argv[0]
server = sys.argv[1]

# ----------------
# Add JMS Provider
# ----------------
attributes = [["description", "ActiveMQ JMS Provider"], \
              ["propertySet", [["resourceProperties", [ \
                                                       [["name", 
"java.naming.connectionFactoryNames"], ["type", "java.lang.String"], ["value", 
"ConnectionFactory,XAConnectionFactory"]], \
                                                       [["name", 
"java.naming.queue.MXITEMIN"], ["type", "java.lang.String"], ["value", 
"MX.ITEM.IN"]] \
                                                       ] \
                                ]] \
               ]]
AdminJMS.createJMSProviderAtScope(scope, jmsProviderName, \
                                  
"org.apache.activemq.jndi.ActiveMQWASInitialContextFactory", \
                                  jmsProviderUrl, attributes)

# ----------------------
# Add Connection Factory
# ----------------------
attributes = [["description", "ActiveMQ Queue Connection Factory"], \
              ["type", "UNIFIED"], \
              ["connectionPool", [ \
                                  ["connectionTimeout", "1800"], \
                                  ["maxConnections", "6"], \
                                  ["minConnections", "0"], \
                                  ["reapTime", "180"], \
                                  ["unusedTimeout", "1800"], \
                                  ["agedTimeout", "1800"], \
                                  ["purgePolicy", "EntirePool"] \
                                  ] \
               ], \
              ["sessionPool", [ \
                                  ["connectionTimeout", "1800"], \
                                  ["maxConnections", "1"], \
                                  ["minConnections", "0"], \
                                  ["reapTime", "10"], \
                                  ["unusedTimeout", "1800"], \
                                  ["agedTimeout", "1800"], \
                                  ["purgePolicy", "EntirePool"] \
                                  ] \
            ]]
AdminJMS.createGenericJMSConnectionFactoryAtScope(scope, jmsProviderName, 
"ACTIVEMQCF", \
                                                  "if/maximo/activemq/cf", 
"XAConnectionFactory", \
                                                  attributes)

# ----------------------
# Add Queues
# ----------------------
# 1. MX.ASSET.IN
attributes = [["description", "ActiveMQ ASSET Queue"], ["type", "QUEUE"]]
AdminJMS.createGenericJMSDestinationAtScope(scope, jmsProviderName, 
"MAXIMO04IN", \
                                            "if/maximo/activemq/q04cin", 
"MXASSETIN", \
                                            attributes) 


# ---------------------------------------
# Create IF-server Message Listener Ports 
# ---------------------------------------
# PORTMAXIMO01IN
attributes = [["description", "ActiveMQ Item"]]
AdminServerManagement.configureListenerPortForMessageListenerService(node, 
server, "PORTMAXIMO01IN", \
                                                                     
"if/maximo/activemq/cf", \
                                                                     
"if/maximo/activemq/q01cin", \
                                                                     1, 5, 1, 
attributes)
{code}


MDB code:
{code}
public class MQQueueListener implements MessageListener, MessageDrivenBean {
        
    protected MessageDrivenContext beanCtx;

    public void setMessageDrivenContext(MessageDrivenContext ctx)
            throws EJBException {
        // Set the bean context.
        beanCtx = ctx;
    }

    public void ejbCreate() throws EJBException {
        [...]
    }

    public void ejbRemove() throws EJBException {
        [...]
    }

    public void onMessage(Message message) {
        [...]
        try {
            [...]
        } catch (Exception e) {
            // Rollback message to external queue.
            beanCtx.setRollbackOnly();
        }

    }
}
{code}

When something goes wrong with the message processing and Exception is thrown 
regardless if beanCtx.setRollbackOnly(); is executed or not message is not 
returned back to the queue - it simply disappears. 

The same applies if Exception is re-thrown as RuntimeException instead of 
beanCtx.setRollbackOnly() call.

------------------
Expected behavior:
------------------
Message that could not be processed is returned to the ActiveMQ queue and 
available for reprocessing (according to WebSphere reprocessing policy)

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to