Announcement Announcement Module
Collapse
No announcement yet.
InboundChannelAdapter - RC2 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • InboundChannelAdapter - RC2

    One of my inbound channel adapters is not working. Is it possible that an outbound channel adapter sends a message to a method(target) and the same method(target) can send a message to a inboundchannel adapter i.e.act as a message source. Inother words one method acting as message source as well as message target?Would appreciate help!

    GIDIntegration.xml
    Code:
    <!-- Polling the sending of requests to Spring WS -->			
    <inbound-channel-adapter ref="source" method="checkForChange" channel="requestChannel">
    <poller>
        <interval-trigger interval="30" time-unit="SECONDS" fixed-rate="true" initial-delay="10"/>
    </poller>
      </inbound-channel-adapter>
    <beans:bean id="source" class="springintegrationGID.GIDIntegration"/> 
    
    <!-- WebService fetches data-->		         
    <channel id="requestChannel"/>
    <ws:outbound-gateway id="gateway"
    				         request-channel="requestChannel" 
    				         reply-channel="replyChannel"
    				         uri="http://localhost:8080/SpringWS_GID/"/>
    				         
    				        
    
    <!--Response from Web Service:Fetched data sent to receive method for comparing-->
    <outbound-channel-adapter id="replyChannel" ref="receivebean" method="receive"/>
    <beans:bean id="receivebean" class="springintegrationGID.GIDIntegration"/>
    
    <!--  Receiving Changed Data and printing in console-->
    //Only this inbound channel adapter not working!!!
    <inbound-channel-adapter ref="notify" method="receive" channel="AlertChannel"/>
    <beans:bean id="notify" class="springintegrationGID.GIDIntegration"/> 
    
    <stream:stdout-channel-adapter  append-newline="true" id="AlertChannel"/>

    Code:
    public class GIDIntegration {
    	
    	boolean received=false;
    	Message<String> temp1=null;
    	Message<String> temp2=null;
    	
    	
    public Message<String> checkForChange(){
    			
    String requestXml =
    		"<divisionRequest xmlns=\"http://gid.com/div/schemas\">FETCHDATA</divisionRequest>" ;
    Message<String> message = MessageBuilder.withPayload(requestXml)
    	.setHeader("http://gid.com/div/schemas",requestXml)
    	.build();
    		return message;
    }
    
    //CAN THE BELOW METHOD ACT BOTH AS MESSAGE SOURCE AND MESSAGE TARGET???
    public Message<String> receive(Message<String>receivedmessage){
    	Message<String>RESULT=null;
    	
    //	System.out.println("Receiving message ------> "+receivedmessage.getPayload());
    			
    			if(received==false)
    			{
    				temp1=receivedmessage;
    				temp2=null;
    				received=true;
    				
    		    }//if
    			   else
    			        {
    			         temp2=receivedmessage;
    		             if(!temp1.getPayload().equals(temp2.getPayload()))
    			                  {
    		            	 System.out.println("Change occured in Division ! "+temp2);
    		  		       
    	                     temp1=temp2;
                             temp2=null;
     	                    RESULT=temp1;
    			                  }//if
    		            
    			        
    			        }//else
    			
    			
    			System.out.println("Result from Class: "+RESULT);	
                return RESULT;
    		//Upto this everything works fine
    }//method		 
    
    
    }//class

  • #2
    Why would you ever want to do this? I suspect from your code that what you want is to receive a message and send a response, which is the service activator pattern. The channel adapter is designed for message in or message out scenarios not both at the same time.

    Also your code is not thread safe due to your use of instance variable.

    Comment


    • #3
      Hi Jonas, Thank u so much for the idea.I used the service activator and it worked!

      Comment

      Working...
      X