Announcement Announcement Module
Collapse
No announcement yet.
query for not losing the message Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • query for not losing the message

    Hi,
    I have a query , I am currently developing an application in which my I will read the data from the queue and will put
    the data on the channel, that I am doing through message listener in spring integration and after that a file need to
    be get created reading the message from that channel , That also I am doing through file generator in spring
    integration.

    Now for audit purpose I want while reading the message from the queue it should also be stored in database first and after
    that it should go for file creation.But in the scenerio let say if file doesn't get created in the end succesfully then
    in that case the message to be deleted means rollback from datbase and also that message again to be sent in to the
    queue again , what I was trying to achieve that message should not be lost, please guide me how to proceed for this scenerio..!!
    Thanks in advance...!

  • #2
    Originally posted by SARAL SAXENA View Post
    Hi,
    I have a query , I am currently developing an application in which my I will read the data from the queue and will put
    the data on the channel, that I am doing through message listener in spring integration and after that a file need to
    be get created reading the message from that channel , That also I am doing through file generator in spring
    integration.

    Now for audit purpose I want while reading the message from the queue it should also be stored in database first and after
    that it should go for file creation.But in the scenerio let say if file doesn't get created in the end succesfully then
    in that case the message to be deleted means rollback from datbase and also that message again to be sent in to the
    queue again , what I was trying to achieve that message should not be lost, please guide me how to proceed for this scenerio..!!I need to use transcation managers jta also for that......!!
    Thanks in advance...!
    Hi ,
    please advise me on this as I m currently using Apache Active MQ and I want to test it as a stand alone application..and I want to use JTA trnscation managers for that .!!
    Last edited by SARAL SAXENA; Nov 16th, 2011, 10:26 AM.

    Comment


    • #3
      Originally posted by SARAL SAXENA View Post
      Hi ,
      please advise me on this as I m currently using Apache Active MQ and I want to test it as a stand alone application...!!
      You are looking for distributed transaction where reading from the queue and update to the database happens in a transaction.
      You can have a message-driven-channel-adapter followed by a chain of an audit service activator and a file:outbound-channel-adapter as below.



      <!-- Direct Channels -->

      <integration:channel id="inChannel"/>
      <integration:channel id="outChannel"/>

      <!-- To receive messages over MQ -->
      <jms:message-driven-channel-adapter destination="someDestination" channel="inChannel" transaction-manager="txMgr"/>

      <integration:chain input-channel="inChannel" output-channel="outChannel">
      <integration:service-activator ref="auditBean" method="auditInDatabase"/>
      <file:outbound-channel-adapter directory="${output.directory}"/>
      </integration:chain>
      Your service activator will return the same message as that is passed to it's auditInDatabase method. If all goes file you will get a java.io.File payload in the message over the outChannel. If an exception is thrown in creating the file, the transaction will be rolled back and based on the redelivery policies of the Active MQ, the message will be redelivered.

      Comment


      • #4
        Originally posted by Amol Nayak View Post
        You are looking for distributed transaction where reading from the queue and update to the database happens in a transaction.
        You can have a message-driven-channel-adapter followed by a chain of an audit service activator and a file:outbound-channel-adapter as below.





        Your service activator will return the same message as that is passed to it's auditInDatabase method. If all goes file you will get a java.io.File payload in the message over the outChannel. If an exception is thrown in creating the file, the transaction will be rolled back and based on the redelivery policies of the Active MQ, the message will be redelivered.

        Hi Amol Nayak,

        Thanks a lot for this creative idea , this is what some where near to my imagination about the service activator what I was planning that service activator should have the code of inserting the message into the database in other words
        it will have the buisness logic of spring jdbc template and after that file creation process will start up
        and in file the same message will be writtenif some how because of any reason the file doesn't get created
        then in that case the same message should be removed from database and the same message should go again back to queue, message should not be lost
        so I need to two transcation managers for that one is of jdbc and other is of jms specific that will controls the message flow
        I am configuring my queue on apache active mq.

        please can you explain about the integration chain component and it's functionality ...in spring integration..!!
        and other thing is that about the redelivery policies of the Active MQ./.what are those policies..?

        Comment


        • #5
          Originally posted by Amol Nayak View Post
          You are looking for distributed transaction where reading from the queue and update to the database happens in a transaction.
          You can have a message-driven-channel-adapter followed by a chain of an audit service activator and a file:outbound-channel-adapter as below.





          Your service activator will return the same message as that is passed to it's auditInDatabase method. If all goes file you will get a java.io.File payload in the message over the outChannel. If an exception is thrown in creating the file, the transaction will be rolled back and based on the redelivery policies of the Active MQ, the message will be redelivered.



          Hi Amol Nayak,

          Thanks a lot for this creative idea , this is what some where near to my imagination about the service activator what I was planning that service activator should have the code of inserting the message into the database in other words
          it will have the business logic of spring jdbc template and after that file creation process will start up
          and in file the same message will be written if some how because of any reason the file doesn't get created
          then in that case the same message should be removed from database and the same message should go again back to queue, message should not be lost so I need to two transaction managers for that one is of jdbc and other is of jms specific that will controls the message flow I am configuring my queue on apache active mq.

          please can you explain about the integration chain component and it's functionality ...in spring integration..!!
          and other thing is that about the redelivery policies of the Active MQ.!!.what are those policies..?

          Comment


          • #6
            then in that case the same message should be removed from database and the same message should go again back to queue, message should not be lost
            Message is not put in database. It will be a normal insert that would insert into the audit table some attributes of the message, some other derived values or some application specific values, this could be done using plain old JDBC, use spring's JDBC template.

            The adapter provided by the MQ vendor is responsible for participating in the global transaction and according handle the de queuing of messages, redelivering the message (JMS Message) back in case of transaction rollback etc.

            so I need to two transaction managers for that one is of jdbc and other is of jms
            No, you use one JTA transaction manager.

            please can you explain about the integration chain component and it's functionality ...in spring integration..!!
            Spring integration has an easy to understand and helpful reference manual, the Message Handler Chain is explained here

            and other thing is that about the redelivery policies of the Active MQ.!!.what are those policies..?
            Search for Active MQ documentation, you should find it there.

            Comment


            • #7
              Originally posted by Amol Nayak View Post
              Message is not put in database. It will be a normal insert that would insert into the audit table some attributes of the message, some other derived values or some application specific values, this could be done using plain old JDBC, use spring's JDBC template.

              The adapter provided by the MQ vendor is responsible for participating in the global transaction and according handle the de queuing of messages, redelivering the message (JMS Message) back in case of transaction rollback etc.


              No, you use one JTA transaction manager.



              Spring integration has an easy to understand and helpful reference manual, the Message Handler Chain is explained here



              Search for Active MQ documentation, you should find it there.

              Hi Anmol,
              Thanks ,I have configured the settings as guided by you, please guide me how to configure the settings for transcation managers in the xml file , I want to configure the JTA specifice settings in this configuration file with respect to Apache Active Mq.

              Comment


              • #8
                Are you running the application locally or running it on an application server?

                Comment


                • #9
                  Originally posted by Amol Nayak View Post
                  Are you running the application locally or running it on an application server?
                  Hi Anmol,
                  I am configuring this on IBM websphere 6 ,I want to configure the JTA specifice settings in this configuration file , Please guide me all the configuration with respect to that ..!!

                  Comment


                  • #10
                    Have you referred to the Transaction Management section of the Spring Reference manual?

                    Comment


                    • #11
                      Originally posted by Amol Nayak View Post
                      Have you referred to the Transaction Management section of the Spring Reference manual?
                      Hi Anmol,
                      Yeah in the very begginig I begain with that , could you please provide some detailed configuration , that will be a great help..!!

                      Comment


                      • #12
                        Originally posted by SARAL SAXENA View Post
                        Hi Anmol,
                        Yeah in the very begginig I begain with that , could you please provide some detailed configuration , that will be a great help..!!
                        Well then i would suggest you read that again, as it is quiet straightforward and easy to understand. Just lookout for JTA transaction manager in it. Post the configurations you will implement here if it doesn't work.

                        Comment


                        • #13
                          Hi Saral

                          Please find the attached configuration file, it will solve your problem.
                          On any error occuring anywhere in the transaction, it will rollback the transaction from the database as well as it will send the JMS message to the error queue.

                          Make sure that the methods of the following two classes should partcipate in the transaction com.XXX.ods.test.service.MyMessageListener.java and
                          com.XXX.ods.test.dao.MyMessageListenerDAO

                          you can do so by annotating the methods with
                          @Transactional(propagation = Propagation.REQUIRED, rollbackForClassName = { "java.lang.Exception" })


                          and yes most importantly dont forget to configure your Queue Connection factory, Queue and Datasource on your Websphere server and use it in your xml using jndi as I have shown below.

                          and yes both the resource managers should be XA based.
                          If you want I can send you the configuration for Queue Configuration factory ,Queue and DS

                          <?xml version="1.0" encoding="UTF-8"?>
                          <beans xmlns="http://www.springframework.org/schema/beans"
                          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                          xmlns:int="http://www.springframework.org/schema/integration"
                          xmlns:jms="http://www.springframework.org/schema/jms"
                          xmlns:jee="http://www.springframework.org/schema/jee"
                          xmlns:int-file="http://www.springframework.org/schema/integration/file"
                          xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
                          xmlns:int-mail="http://www.springframework.org/schema/integration/mail"
                          xmlns:task="http://www.springframework.org/schema/task"
                          xmlns:tx="http://www.springframework.org/schema/tx"
                          xmlns:stream="http://www.springframework.org/schema/integration/stream"
                          xmlns:jdbc="http://www.springframework.org/schema/integration/jdbc"
                          xsi:schemaLocation="http://www.springframework.org/schema/beans
                          http://www.springframework.org/schem...ring-beans.xsd
                          http://www.springframework.org/schema/integration
                          http://www.springframework.org/schem...ration-2.0.xsd
                          http://www.springframework.org/schema/jms http://www.springframework.org/schem...ng-jms-2.5.xsd
                          http://www.springframework.org/schema/jee http://www.springframework.org/schem...spring-jee.xsd
                          http://www.springframework.org/schema/integration/file
                          http://www.springframework.org/schem...n-file-2.0.xsd
                          http://www.springframework.org/schema/integration/jms
                          http://www.springframework.org/schem...on-jms-2.0.xsd
                          http://www.springframework.org/schema/tx
                          http://www.springframework.org/schem...ing-tx-3.1.xsd
                          http://www.springframework.org/schema/task
                          http://www.springframework.org/schem...g-task-3.1.xsd
                          http://www.springframework.org/schem...gration/stream
                          http://www.springframework.org/schem...stream-1.0.xsd
                          http://www.springframework.org/schema/integration/mail
                          http://www.springframework.org/schem...n-mail-2.0.xsd
                          http://www.springframework.org/schema/integration/jdbc
                          http://www.springframework.org/schema/integration/jdbc/spring-integration-jdbc-2.0.xsd">


                          <bean id="placeholderConfig"
                          class="org.springframework.beans.factory.config.Pr opertyPlaceholderConfigurer">
                          <property name="location" value="classpath:config.properties">
                          </property>
                          </bean>

                          <jee:jndi-lookup id="queueConnectionFactory1" resource-ref="true"
                          jndi-name="jms/ODSQueue1" />

                          <jee:jndi-lookup id="InboundQueue1" resource-ref="true"
                          jndi-name="jms/Queue1" />

                          <jee:jndi-lookup id="queueConnectionFactory2" resource-ref="true"
                          jndi-name="jms/ODSQueue2" />

                          <jee:jndi-lookup id="InboundQueue2" resource-ref="true"
                          jndi-name="jms/Queue2" />


                          <!-- In Bound Process Configuration Starts -->

                          <int:channel id="dbupdateChannel"></int:channel>

                          <int:channel id="fileOutPutChannel"></int:channel>

                          <int-jms:message-driven-channel-adapter
                          id="mq-message-listner1" container="messageListenerContainer1"
                          channel="dbupdateChannel" />
                          <int-jms:message-driven-channel-adapter
                          id="mq-message-listner2" container="messageListenerContainer2"
                          channel="dbupdateChannel" />

                          <bean id="messageListenerContainer1"
                          class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
                          <property name="connectionFactory" ref="queueConnectionFactory1" />
                          <property name="destination" ref="InboundQueue1" />
                          <property name="messageListener" ref="MyMessageListenerService" />
                          <property name="sessionTransacted" value="false" />
                          <property name="cacheLevelName" value="CACHE_NONE" />
                          <property name="transactionManager" ref="myTxManager" />
                          </bean>

                          <bean id="messageListenerContainer2"
                          class="org.springframework.jms.listener.DefaultMes sageListenerContainer">
                          <property name="connectionFactory" ref="queueConnectionFactory2" />
                          <property name="destination" ref="InboundQueue2" />
                          <property name="messageListener" ref="MyMessageListenerService" />
                          <property name="sessionTransacted" value="false" />
                          <property name="cacheLevelName" value="CACHE_NONE" />
                          <property name="transactionManager" ref="myTxManager" />
                          </bean>

                          <int:service-activator id="updateDB" input-channel="dbupdateChannel"
                          output-channel="fileOutPutChannel" ref="MyMessageListenerServiceDAO"
                          method="updateDB">
                          </int:service-activator>

                          <bean id="myTxManager" class="org.springframework.transaction.jta.JtaTran sactionManager"/>



                          <bean id="MyMessageListenerService"
                          class="com.XXX.ods.test.service.MyMessageListener" >
                          <property name="myMessageListenerDAO" ref="MyMessageListenerServiceDAO"></property>
                          </bean>

                          <bean id="MyMessageListenerServiceDAO"
                          class="com.XXX.ods.test.dao.MyMessageListenerDAO">
                          <property name="jdbcTemplate" ref="jdbctemplate"></property>
                          </bean>

                          <bean id="jdbctemplate"
                          class="org.springframework.jdbc.core.JdbcTemplate" >
                          <property name="dataSource" ref="dataSource" />
                          </bean>

                          <bean id="dataSource"
                          class="org.springframework.jdbc.datasource.WebSphe reDataSourceAdapter">
                          <property name="targetDataSource">
                          <bean
                          class="org.springframework.jndi.JndiObjectFactoryB ean">
                          <property name="jndiName" value="jdbc/ods" />
                          </bean>
                          </property>
                          <property name="username" value="root" />
                          <property name="password" value="admin" />
                          </bean>


                          <int-file:outbound-channel-adapter
                          directory="${DirectoryForRequestFile}"
                          filename-generator-expression="headers.getCorrelationId()+'.xml'"
                          temporary-file-suffix="_swp" channel="fileOutPutChannel" />

                          <!-- In Bound Process Configuration Ends -->


                          </beans>


                          and yes when did you get the Senior Member position ...we'll discuss about it later

                          Comment

                          Working...
                          X