[jboss-user] [JBoss Messaging] - Re: Distributed Transaction using JMS, EJB and MDB

jessiezam do-not-reply at jboss.com
Fri Jul 11 22:39:43 EDT 2008


Thanks Tim for the immediate reply.

Listed below are the snippet of codes i use for the application (Error handling is remove)

The PaymentCollectionService is the one posting the payment topic. This is deployed on server1.


  | 
  | @Stateless
  | public class PaymentCollectionService implements IPaymentCollectionService {
  |     @PersistenceContext(unitName="paymentPU")
  |     private EntityManager em;
  |     
  |     @Resource(mappedName="java:/JmsXA")
  |     private TopicConnectionFactory connFactory;
  |     
  |     @Resource(mappedName="topic/PaymentTopic")
  |     private Topic paymentTopic;
  |     
  |     
  |     public void postPayment(String action, Receipt receipt) throws Exception {
  |         Connection conn = null;
  |         Session session = null;
  |         MessageProducer sender = null;
  |         
  |         try {
  |             conn = connFactory.createConnection();
  |             session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
  |             sender = session.createProducer(paymentTopic);
  |             ObjectMessage om = session.createObjectMessage();
  |             om.setJMSType(action);
  |             om.setObject((Serializable)receipt);
  |             sender.send(om);
  |         }
  |         catch (Exception e) {
  |             e.printStackTrace();
  |             throw e;
  |         } finally {
  |             if(sender != null ) try {sender.close();}catch(Exception ex){};
  |             if(session != null ) try {session.close();}catch(Exception ex){};
  |             if(conn != null ) try {conn.close();}catch(Exception ex){};
  |         }
  |     }
  | }
  | 
  | 


The ProvincePostPaymentListener listens on PaymentTopic. This is also deployed in server1.


  | 
  | @MessageDriven(
  | activationConfig = {
  |     @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
  |     @ActivationConfigProperty(propertyName="destination", propertyValue="topic/PaymentTopic"),
  |     @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="Auto-acknowledge")
  | }
  | )
  | public class ProvincePostPaymentMessageListener   implements MessageListener {
  |     
  |     @Resource
  |     private MessageDrivenContext mdbContext;
  |     
  |     @EJB
  |     private ICollectionService collectionService;
  |     
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     public void onMessage(Message message) {
  |         try {
  |             ObjectMessage msg = (ObjectMessage) message;
  |             Receipt receipt = (Receipt)msg.getObject();
  |             collectionService.postProvincePayment(receipt);
  |         } 
  |         catch (Exception ex) {
  |             mdbContext.setRollbackOnly();
  |         }
  |     }
  | }
  | 


The MunicipalityPostPaymentListener is deployed on the remote server2. This also listens to PaymentTopic.


  | @MessageDriven(
  | activationConfig = {
  |     @ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Topic"),
  |     @ActivationConfigProperty(propertyName="destination", propertyValue="topic/PaymentTopic"),
  |     @ActivationConfigProperty(propertyName="acknowledgeMode", propertyValue="Auto-acknowledge"),
  |     @ActivationConfigProperty(propertyName="providerAdapterJNDI", propertyValue="java:/ProvinceJMSProvider")
  | }
  | )
  | public class MunicipalityPostPaymentMessageListener   implements MessageListener {
  |     @EJB
  |     private IRPTCollectionService collectionService;
  |     
  |     @Resource
  |     private MessageDrivenContext context;
  |     
  |     @TransactionAttribute(TransactionAttributeType.REQUIRED)
  |     public void onMessage(Message message) {
  |             ObjectMessage msg = (ObjectMessage)message;
  |             Receipt receipt = (Receipt) msg.getObject();
  |             collectionService.postRemotePayment(receipt);
  |             throw new Exception("ROLLBACK TEST");  //test error to rollback the transaction 
  |         } 
  |         catch (Exception ex) {
  |             context.setRollbackOnly();
  |         }
  |     }
  |     
  |     
  |     
  | }
  | 
  | 


The persistence.xml description.

  | <?xml version="1.0" encoding="UTF-8"?>
  | <persistence xmlns="http://java.sun.com/xml/ns/persistence"
  | 		 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  | 		 xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd"
  | 		 version="1.0">
  | 
  | 	<persistence-unit name = "defaultPU">
  | 	  <provider>org.hibernate.ejb.HibernatePersistence</provider>
  | 	  <jta-data-source>java:/defaultDB</jta-data-source>
  | 	  <properties>
  | 		<property name="hibernate.dialect" value="org.hibernate.dialect.MySQL5InnoDBDialect"/>
  | 		<property name="hibernate.hbm2ddl.auto" value="update"/>
  | 		<property name="hibernate.show_sql" value="false"/>
  | 		<property name="hibernate.cache.provider_class" value="org.hibernate.cache.HashtableCacheProvider"/>
  | 		<property name="hibernate.transaction.manager_lookup_class" value="org.hibernate.transaction.JBossTransactionManagerLookup"/>
  | 	  </properties>
  | 	</persistence-unit>
  | </persistence>
  | 

I suspect there might be JBoss settings thats not done right and hopefully you can assist me with it. Thanks alot

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4163982#4163982

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4163982



More information about the jboss-user mailing list