Announcement Announcement Module
Collapse
No announcement yet.
Can we Open new Direct Channel instance for new requests? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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, 07:36 AM.

  • #2
    Hi,

    Has anybody faced similar issue?

    Regards,
    Annuk

    Comment


    • #3
      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?

      Comment


      • #4
        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

        Comment


        • #5
          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

          Comment


          • #6
            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.

            Comment


            • #7
              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

              Comment


              • #8
                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

                Comment


                • #9
                  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

                  Comment

                  Working...
                  X