Announcement Announcement Module
Collapse
No announcement yet.
Spring INtegration Headers - Urgent Help Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring INtegration Headers - Urgent Help

    Here is the flow

    1. Read from database - JDBC Inbound Adapter used
    2. To process read data - Service Activator
    3. If there is an error in the service activator the message is sent error channel.
    4. Before sending to error channel i create an error bean. now error bean is an object which holds error code and descriptions
    5. set the error bean in the headers
    which is all fine..

    when it is reading second message from the database and pass it to service activator - service activator is holding previous error object in the header map.

    How do i blank object everytime after reading from database.

  • #2
    Hi!

    Show your config, please.
    Heuristic tips might not have a power.

    Take care,
    Artem

    Comment


    • #3
      Thank you for your reply

      here it is
      Code:
              <int-jdbc:inbound-channel-adapter id="jdbcChannelInAdapter" channel="jdbc-inbound-channel" 
      		query="${int.inbound.poll.query}" update="${int.inbound.update.query}" 
      		row-mapper="mapper"	max-rows-per-poll="1"	data-source="dataSource" >
      		<int:poller max-messages-per-poll="1"  receive-timeout="5000" fixed-rate="50000"/>
      	</int-jdbc:inbound-channel-adapter>	 
      
      	<int:chain input-channel="jdbc-inbound-channel" output-channel="router-inbound-channel">
      		<int:header-enricher> 
      			<int:error-channel ref="rejectedMessagesChannel" />			 
      			<int:header name="errorCode"  ref="errorBean" /> 
      		</int:header-enricher> 	
      	  	<int:service-activator ref="jobInboundServiceActivator" method="launch" />
      	</int:chain>
      Last edited by Gary Russell; May 11th, 2013, 12:40 PM.

      Comment


      • #4
        A-ha!
        OK, I see.
        You want to have this one:
        HTML Code:
        <int:header name="errorCode" expression="@errorBean" /> 
        'ref' attribute is evaluated only once - on application context start up, as other dependency injections in the Spring for singleton beans.
        'expression' is evaluated on each Message.

        Good luck

        Comment


        • #5
          You are inserting 'errorBean' on every message! You are not showing 'errorBean' but if it's a singleton you'll get the same bean on every message.

          Why are you using a header-enricher to add the error-channel?

          You can simply declare an error-channel attribute on the inbound adapter.

          To communicate the reason for the problem simply throw an exception that contains the data.

          The ErrorMessage on the error-channel will have a 'MessagingException' payload which has 2 properties (failedMessage and cause), where cause is your exception.

          Comment


          • #6
            I am a fan of you Gary.

            thank you for your reply.

            i had the error bean as prototype. still when the message read from inbound adapter it was using same bean object.

            Comment


            • #7
              I did this way.... i am hoping this way i hold the new object
              Code:
                  <bean id="errorBean" class="com.XXX.ErrorEnricher" />
              	<int:chain input-channel="jdbc-inbound-channel" output-channel="router-inbound-channel">
              		<int:header-enricher> 
              			<int:error-channel ref="rejectedMessagesChannel" />			 
              			<int:header name="errorCode"  ref="errorBean" method="enrichHeader"/> 
              		</int:header-enricher> 	
              	  	<int:service-activator ref="jobInboundServiceActivator" method="launch" />
              	</int:chain>
              Enricher Class
              Code:
              public ErrorBean enrichHeader(Message<?> message) { 
              		ErrorBean errorBean = new ErrorBean ();
              		errorBean.setJobId(0);
              		return errorBean;
              
              	}
              With this way i get new message...
              Let me ask you Question.. after reading a message from jdbc inbound will the new instance of payload and headers are created ?
              in a multithreaded environment will each get their own payload and header?
              Last edited by Gary Russell; May 11th, 2013, 02:14 PM.

              Comment


              • #8
                Please tell me this

                After reading a message from jdbc inbound goes in to channel will the new instance of payload and headers are created ?
                in a multithreaded environment will each get their own payload and header? which means if header variables will be unique to that message?

                Comment


                • #9
                  Protoype doesn't make any difference the way you had it; that just means each time it's referenced in the context a new instance is created.

                  When posting code and config, please use [ code ] ... [ /code ] tags (no spaces in brackets). I edited your posts.

                  Yes, each message gets a brand new payload and headers, regardless of the threading.

                  Comment

                  Working...
                  X