Announcement Announcement Module
Collapse
No announcement yet.
fire and forget void method gateways Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • fire and forget void method gateways

    I am wanting to implement a fire and forget gateway method.

    I assumed that just making the gateway method return "void" would do the trick, but in my tests, it seems this is not the case.

    XML config
    Code:
    <channel id="retrieveAssetsChannel"/>
    
    	<gateway id="assetGateway"  service-interface="com.foo.AssetGateway" />
    	
    	<beans:bean id="assetsIntegrator" class="com.foo.AssetsIntegrator" />
    	
    	<service-activator input-channel="retrieveAssetsChannel" ref="assetsIntegrator" method="process" />
    my gateway
    Code:
    public interface AssetGateway {
    	
    	@Gateway(requestChannel="retrieveAssetsChannel")
    	public void retrieveAssets(String applicationId);
    
    }
    my "service activator"
    Code:
    public class AssetsIntegrator {
    	
    	private Logger logger = LoggerFactory.getLogger(AssetsIntegrator.class);
    	
    	public void process(String applicationId) throws InterruptedException {
    		Thread.sleep(100000);
    		logger.debug("Retrieving assets for application: " + applicationId);
    	}
    
    }
    my "test"
    Code:
    assetGateway.retrieveAssets(applicationId);
    System.out.println("Gateway success");
    now, I would assume that the message "Gateway success" would print before the logger debug message, but this is not the case.

    I assume I am missing something in my thinking?

    Thanks in advance

  • #2
    The method is not invoked asynchronously just because it has a void return (which is useful in cases where you want to either complete or have an Exception thrown).

    However, you have a couple options...

    1. rely on Spring's Async support by adding @Async to the method (and enable async execution, e.g. via the <task> namespace).

    2. use an async channel as the request-channel for the gateway

    HTH,
    Mark

    Comment


    • #3
      Thanks for the reply Mark

      1. By enabling async execution, I assume you mean <task:annotation-driven/>
      2. This interests me too, but I can seem to find anything in the documentation regarding an async channel?

      I forgot to add, I am using SI 2.1.0.RELEASE

      Comment


      • #4
        Information about the @Async annotation can be found in the Spring Documentation
        This interests me too, but I can seem to find anything in the documentation regarding an async channel?
        Search for ExecutorChannel in the reference manual of Spring Integration.
        Last edited by Amol Nayak; Jun 2nd, 2012, 05:22 AM.

        Comment

        Working...
        X