Results 1 to 10 of 14

Thread: Http Inbound Gateway Problem

Hybrid View

  1. #1
    Join Date
    Aug 2007
    Posts
    15

    Default Http Inbound Gateway Problem

    Hi,

    I've a SI project with the following composition:

    Code:
    <int-http:inbound-gateway 
            request-channel="requestChannel"
    	name="/req"
    	supported-methods="GET"
    	mapped-request-headers="*" 			
    	reply-channel="responseChannel"/>
    
    	<int:channel id="requestChannel"/>
            <int:channel id="responseChannel"/>
    	
    	<int:chain input-channel="requestChannel" output-channel="messageSubscriber">
    		<int:transformer ref="requestTransformer" />
    		<int:header-enricher >
    			<int:header name="ad_correlation_id" expression="T(java.util.UUID).randomUUID().toString()" />
    		</int:header-enricher>
    	</int:chain>		
    				
    	<int:publish-subscribe-channel id="messageSubscriber" task-executor="executor" />
    	<task:executor id="executor" pool-size="6" />
    			
    	<int:service-activator input-channel="messageSubscriber" 
    				        output-channel="channelPreAggregation" 
    				        ref="service1"/>
    
    	<int:service-activator input-channel="messageSubscriber"
    				        output-channel="channelPreAggregation" 
    				        ref="service2"/>
    	
    	<int:channel id="channelPreAggregation"/>
    			
    	<int:chain input-channel="channelPreAggregation" output-channel="responseChannel">	
    		<int:aggregator correlation-strategy-expression="headers.get('ad_correlation_id')" release-strategy-expression="size() == 2" />		
    		<int:transformer ref="toStringlTransformer" />				
    	</int:chain>
    Everything seem to be working perfectly, no error and the expected message is arriving to my last toString transformer and is sent to the final response channel. The weird thing is that the gateway sometimes doesn't return the message, I get a 200 OK but nothing in the payload despite I can see in log file and debugging that I'm sending to the final response channel the right information.
    This only happens sometimes (always in the first call when I start the server), the rest of the times everything works fine.

    The problem seems to be in the task executor, because if I remove it, everything run ok, but I would like to call to the two services activator at the same time, not sequentially, so I need the task executor (or is there other possibility???).

    Any idea?? Maybe a problem with threads??

    Thanks in advance.

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

    Default

    What is the return value for service1 and service2?
    It seems to me that any one of these services can produce a reply to the gateway so whoever produces it first wins.

    There are probably better ways to configure what you want, but first I want to understand what's going on in service1 and 2

  3. #3
    Join Date
    Aug 2007
    Posts
    15

    Default

    Both services returns the same kind of object, it's just a DTO. After aggregation I have a transformer which select just one of these object (the one returned by service1 or the one returned by service2)

    Anyway I'm getting the same problem regardless of which of the object wins so I tend to think that the problem is not related to the services.

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

    Default

    Can you remove the reply-channel from the HTTP Inbound gateway (reply-channel="responseChannel"). You don't need it.
    And also in your chain, remove output-channel="responseChannel". You don't need that as well.

    Just as an FYI, the reply will go via default replyChannel which is auto-created by the gateway and injected into the message as header.

    This will simplify the configuration and hopefully allow us to determine what the problem is.

  5. #5
    Join Date
    Aug 2007
    Posts
    15

    Default

    Done! (and thanks for the useful info) but the bug is still there

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

    Default

    Ok, lets remove more stuff

    1. Remove header enricher
    2. Add apply-sequence="true" to the pub-sub channel (this will do pretty much what your header enricher did)
    3. Remove correlation-strategy-expression="headers.get('ad_correlation_id')" from the aggregator (it will rely on the default correlation ID which will be injected in the pub-sub channel based on apply-sequence="true")

    Let's try to simplify it as much as we can without loosing functionality first.

  7. #7
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    740

    Default

    Good evening!

    Can you explain what is the reason to use some custom correlation?
    Here is some snapshot of your flow:
    HTML Code:
    <gateway id="testGateway"
    			 service-interface="org.springframework.integration.handler.PublishSubscribeAggregationTests$TestGateway">
    		<method name="gateway" request-channel="subscriber"/>
    	</gateway>
    
    	<publish-subscribe-channel id="subscriber" task-executor="executor" apply-sequence="true"/>
    
    	<task:executor id="executor" pool-size="6"/>
    
    	<service-activator input-channel="subscriber" output-channel="aggregation" expression="payload.toUpperCase()"/>
    
    	<service-activator input-channel="subscriber" output-channel="aggregation" expression="payload.toLowerCase()"/>
    
    	<aggregator input-channel="aggregation"/>
    And the test class:
    Code:
    @ContextConfiguration
    @RunWith(SpringJUnit4ClassRunner.class)
    public class PublishSubscribeAggregationTests {
    
    	@Autowired
    	private TestGateway gateway;
    
    	@Test
    	public void testPublishSubscribeAggregation() {
    		String payload = "gGHdsdHrghdf";
    		for (int i = 0; i < 100; i++) {
    			List<String> result = gateway.gateway(payload);
    			assertEquals(2, result.size());
    			assertThat(result, Matchers.hasItems(payload.toUpperCase(), payload.toLowerCase()));
    		}
    	}
    
    	private static interface TestGateway {
    
    		List<String> gateway(String payload);
    
    	}
    }
    So, as Oleg said it seems like a problem of your services. Maybe it depends on request parameters which you are using in those services?
    Can you simplify them as I've shown above and test again?

    Cheers,
    Artem

Posting Permissions

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