JBoss, Websphere MQ Transactional Behaviour
kakkarj Nov 26, 2010 7:29 AMHi All,
I'd appreciate if someone could help me with JBoss, Websphere MQ transactional behaviour.
Below are the code snippet & configurations.
Code: The code below look up QCF and Queue and send a message to the queue. Then wait for 5 sec and throw an error. I'd expect the first message to roll back and thus no message should be put to queue. However I can see the first message put to the queue.
boolean flag = true;
InitialContext ctx = new InitialContext();
            ConnectionFactory qcf = (ConnectionFactory) ctx
                    .lookup("java:realtimereportingqcf");
log.error("ConnectionFactory is " + qcf);
Queue queue = (Queue) ctx.lookup("realtimereporting");
            try {
                con = qcf.createConnection();
                s = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
                producer = s.createProducer(queue);
                producer.send(s.createTextMessage(" Test Message... "));
                
                try {
                    Thread.sleep(5000);
                    if(flag)
                        throw new RuntimeException();
                    
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                
                producer.send(s.createTextMessage("Test Message... "));
            } catch (JMSException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
Configurations
Jboss deploy/mq directory contains wmq.jmsra-ds.xml wmq.jmsra.rar
wmq.jmsra-ds.xml
<?xml version="1.0" encoding="UTF-8"?>
<connection-factories>
  <!-- ==================================================================== -->
  <!-- Websphere MQ service deployment                                      -->
  <!-- ==================================================================== -->
    <tx-connection-factory>
        <jndi-name>realtimereportingqcf</jndi-name>
        <local-transaction>true</local-transaction>
        <rar-name>wmq.jmsra.rar</rar-name>
        <connection-definition>javax.jms.ConnectionFactory</connection-definition>
        <config-property name="channel" type="java.lang.String">REPORT.SVRCONN</config-property>
        <config-property name="hostName" type="java.lang.String">xyz.uk.com</config-property>
        <config-property name="port" type="java.lang.String">1425</config-property>
        <config-property name="queueManager" type="java.lang.String">QM123</config-property>
        <config-property name="transportType" type="java.lang.String">CLIENT</config-property>
        <security-domain-and-application>JmsXARealm</security-domain-and-application>
        <max-pool-size>20</max-pool-size>
     </tx-connection-factory>
        <!-- Create queue for outbound messages -->
      <mbean code="org.jboss.resource.deployment.AdminObject" name="jca.wmq:name=realtimereporting">
        <depends optional-attribute-name="RARName">jboss.jca:service=RARDeployment,name='wmq.jmsra.rar'</depends>
        <attribute name="JNDIName">realtimereporting</attribute>
        <attribute name="Type">javax.jms.Queue</attribute>
        <attribute name="Properties">
            baseQueueManagerName=QM123
            baseQueueName=REPORT.QUEUE
        </attribute>
     </mbean>
</connection-factories>
ejb-jar.xml
     <session>
            <display-name>ServiceBean</display-name>
            <ejb-name>ServiceBean</ejb-name>
            <home>com.service.session.ServiceHome</home>
            <remote>com.service.session.Service</remote>
            <ejb-class>com.service.session.ServiceBean</ejb-class>
            <session-type>Stateless</session-type>
            <transaction-type>Container</transaction-type>
            <resource-ref>
                <description>The JMS TopicConnection Factory</description>
                <res-ref-name>realtimereportingqcf</res-ref-name>
                <res-type>javax.jms.QueueConnectionFactory</res-type>
                <res-auth>Container</res-auth>
            </resource-ref>
        </session>
     <container-transaction>
            <method>
                <ejb-name>ServiceBean</ejb-name>
                <method-name>entryProcess</method-name>
            </method>
            <trans-attribute>NotSupported</trans-attribute>
        </container-transaction>
jboss.xml
<session>
<ejb-name>ServiceBean</ejb-name>
<jndi-name>ServiceBean</jndi-name>
<resource-ref>
<res-ref-name>realtimereportingqcf</res-ref-name>
<jndi-name>realtimereportingqcf</jndi-name>
</resource-ref>
</session>
Thanks for your help and support
Regards
JK
 
    