Results 1 to 9 of 9

Thread: Can we Open new Direct Channel instance for new requests?

  1. #1
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Question Can we Open new Direct Channel instance for new requests?

    Hi,

    I am building a client-server model using Spring Integration.
    I am using direct channel.
    My system works as:

    1.Receive request on servlet
    2.Get the message channel
    3.Write response in servlet response channel.

    The problem arises when i receive multiple requests at the same time.
    Spring Integration processes the request one by one.

    It takes the first request, processes it, writes the response and then picks up the next request.My request channel is getting locked.

    My servlet code is as follows:

    Code:
    private void doSpringIntegrationHandling(HttpServletRequest request, HttpServletResponse response)
    			throws IOException
    	{
    		ApplicationContext applicationContext = WebApplicationContextUtils
    				.getRequiredWebApplicationContext(getServletContext());
    
    			String data = readBody(request);
    			readQueryString(request);
    
    			MessageChannel requestChannel = (MessageChannel) applicationContext
    					.getBean("deviceRequestChannel");
    
    			MessageBuilder<?> messageBuilder = MessageBuilder.withPayload(data).setHeader("response", response);
    			log.info("RESPONSE OBJECT -- "+response);
    			requestChannel.send(messageBuilder.build());
    Only one instance of the request channel is created.
    My config is as follows:

    Code:
    <int:channel id="deviceRequestChannel" />
    <int:channel id="deviceResponseChannel" >
    I used httpinboundgateway but faced some issues while reading the data written in request.

    I don't want to use a queue here.Need to open a new channel for each request?
    Is it possible?Please help.

    Thanks in advance.

    Regards,
    Annuk
    Last edited by annuk; Jun 11th, 2012 at 06:36 AM.

  2. #2
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Default

    Hi,

    Has anybody faced similar issue?

    Regards,
    Annuk

  3. #3
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    Why not use an ExecutorChannel? This way you can go back to using HttpInboundGateway and it would take care of all the correlation of the request to response?

  4. #4
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Default

    Hi Oleg,

    Thanks for your reply.
    I want my system to execute client requests simultaneously.But in current scenario, the request channel is getting locked and my system processes request one by one.

    Please help.

    Thanks in advance.

    Regards,
    Annuk

  5. #5
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    As I said, why not use ExecutorChannel instead of DirectChannel? PLease read this section, its all explained there http://static.springsource.org/sprin...ingle/#channel

  6. #6
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Default

    Hi Oleg,

    Just wanted to know whether, Spring Integration channels are synchronized?
    Tried the solution suggested by you.
    I received simultaneous requests with the executor, but was not able to write my response in my servlet response object.


    please help.

    Regards,

    Annuk.

  7. #7
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    As I said, you don't need a custom servlet. Just use HttpInboundGateway where correlation of request/response is already taken care of.
    Essentially you are trying to write your own HttpInboundGateway and if so why not use existing one which will do everything you described so far

  8. #8
    Join Date
    May 2011
    Location
    Mumbai, India
    Posts
    93

    Default

    Hi Oleg,

    Thanks again for your reply.

    We had earlier used HttpInboundgateway, but we were not getting the output in the desired format.

    When we tried reading the data in the request body, the return type of the object was not consistent.
    We were writing json in the request, but we got two different outputs.
    Once we got json, the other time as bytearray.

    thus we wrote our own httpinboundgateway.are message channels synchronised?

    Thanks.
    Annuk

  9. #9
    Join Date
    Jan 2008
    Location
    Mohnton, PA USA (that's near Philadelphia)
    Posts
    2,148

    Default

    You can manage the request-payload-type with the attribute that has the same name.
    HttpInboundGateway comes with quite a few configuration parameters to address the issues you are describing, so I would suggest to study it and learn what and how it does things before trying to implement your own since in the end you'll end up doing the same thing while also being responsible for maintaining it.

    Please go thorough this documentation and let us know what's missing http://static.springsource.org/sprin.../#http-inbound

Tags for this Thread

Posting Permissions

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