Page 2 of 2 FirstFirst 12
Results 11 to 16 of 16

Thread: 2 way tcp socket adapter?

  1. #11
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    I don't believe anything is broken.

    That's why they are called collaborating channel adapters. The inbound message is not sent the TcpSendingMessageHandler (outbound-adapter); it's sent to the TcpReceivingChannelAdapter (inbound adapter).

    Regarding the header; the example I gave shows how to populate the header on an error channel.

    I need to understand more of your message flow, and what you are trying to do with your messages.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  2. #12
    Join Date
    Sep 2011
    Posts
    15

    Default

    I need 2 way asynchronous communication and request/reply communication on a socket. I need to be able to reply to incoming messages, which I'm already doing. But I need to initiate new messages to the client that is not a reply to a client message. My app has a loop that does work until the work is complete. Throughout the work loop some event happens that needs to notify the client of that event. This is out of band from the request/reply scenario.

  3. #13
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    OK; got it.

    What you need to do is capture the header from a good inbound message.

    If an inbound message is good and your app replies; it will contain the header.

    If the inbound message fails, you'll have to populate the header as I described in the error flow.

    For unsolicited outbound messages, you'll need to use the previously saved header. Something like this should work.

    Code:
    public class SaveHeader {
    
    	private volatile String header;
    
    	public String getHeader() {
    		return header;
    	}
    
    	public void setHeader(String header) {
    		this.header = header;
    	}
    
    }
    Code:
    	<int-ip:tcp-connection-factory 	id="crLfServer"
    		type="server"
    		port="11111"/>
    	
    	<int-ip:tcp-inbound-channel-adapter connection-factory="crLfServer"
    		channel="inbound"/>
    		
    	<int:recipient-list-router>
    		<int:recipient channel="saveHeader"/>
    		<int:recipient channel="doWork"/>
    	</int:recipient-list-router>
    	
    	<int:channel id="saveHeader" />
    	
    	<bean id="headerSav" class="foo.SaveHeader" />
    	
    	<int:chain input-channel="saveHeader" >
    		<int:transformer expression="headers.ip_connection_id"/>
    		<int:service-activator ref="headerSaver" method="setHeader"/>
    	</int:chain>
    	
    	<int:channel id="doWork" /> 
    	
    	<!-- Your main code here including error handling as above -->
    	
    	<!-- ##################################################### -->
    
    	<!-- Your unsolicited outbound -->
    	
    	<int:channel id="unsolicitedMessageChannel"/>
    	
    	<int:header-enricher input-channel="unsolicitedMessageChannel" 
    		output-channel="toOutboundAdapter">
    		<int:header name="ip_connection_id" expression="@headerSaver.header"/>
    	</int:header-enricher>
    Because the setHeader method returns void, that part of the flow ends and we then send the message to the next recipient (your code).

    The header enricher uses a SpEL expression to get the header value by calling the getHeader() method on the headerSaver.

    I haven't tested it, but hopefully you get the idea.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #14
    Join Date
    Oct 2011
    Posts
    3

    Default

    connection_id' header - that's how we know which connection to use. If the message originates from the inbound adapter, the header will already be filled in, but it you construct a new message, it needs the header.

    This is also true if you put an error channel on the inbound adapter, the error message won't have the header, but the failed message will. Here is an example of how to handle errors and send some response to the clientI gave shows how to populate the header on an error channel.

  5. #15
    Join Date
    Oct 2012
    Posts
    5

    Default

    Hi Gary,

    Thanks very much! for the explanation.

    I am following tcp-client-server-multiplex example in spring-integration-samples and I want to send new message to the client that is not a reply to a client message.
    I would like to know in case of tcp-client-server-multiplex example, how to save ip_connection_header and use it to send new message.

    Best Regards,
    Chary

  6. #16
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,020

    Default

    Post #13 above shows how to do that.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •