Announcement Announcement Module
Collapse
No announcement yet.
Spring batch with spring integration via http Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Spring batch with spring integration via http

    hi ..
    i am trying to configure the http adapters b/w spring batch and integration. my app (spring-batch-admin) exposes a lightweight spring integration context which launches jobs. the configs are as follows

    Code:
    <bean class="org.springframework.web.servlet.handler.BeanNameUrlHandlerMapping" />
    
    <int-http:inbound-channel-adapter 
    id="batchHttpAdapter" 
    name="/someJobs" 
    message-converters="stringMessageConverter" 
    channel="job-launches"	
    supported-methods="POST" />
    
    <bean id="stringMessageConverter"
    class="org.springframework.http.converter.StringHttpMessageConverter" />	
    
    <int:service-activator 
    input-channel="job-launches" 
    output-channel="batchJobRequests">
    <bean	class="org.springframework.batch.admin.integration.StringToJobLaunchRequestAdapter">
       <property name="jobLocator" ref="jobRegistry" />
    </bean>
    </int:service-activator>
    
    <int:service-activator input-channel="batchJobRequests">
    <bean class="org.springframework.batch.integration.launch.JobLaunchingMessageHandler">			<constructor-arg ref="jobLauncher" /></bean>
    </int:service-activator>
    The job is launched asynchronously
    Code:
    	<task:executor id="asyncExecutor" pool-size="10"/>
    	<bean id="jobLauncher"
    	class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
    		<property name="jobRepository" ref="jobRepository" />
    		<property name="taskExecutor" ref="asyncExecutor"></property>
    	</bean>
    On the client side requests are sent as follows (from another app )
    Code:
    <int-http:outbound-gateway url="http://someurl:port/spring-batch-admin/someJobs" request-channel="someChannel" http-method="POST"></int-http:outbound-gateway>
    How do i configure the client to receive the response which is the JobExecution ?

    Thanks

  • #2
    Probably all you need to do is use <http:inbound-gateway/> instead of <http:inbound-channel-adapter/> and provide an HttpMessageConverter that can convert the reply on the job-operator channel.

    Comment


    • #3
      yes thanks, i had figured i wud have needed a gateway. however i decided to use the already present json api in spring-batch-admin. Is there a better way of doing this invocation on the client side ?
      Code:
      String launchUrl = "http://url:port/spring-batch-admin/jobs/{jobName}.json?{jobParameters}";
      
      Map<String, String> jobConfiguration = new HashMap<String, String>();
      jobConfiguration.put("jobName", someJobNameAsString);
      String jobParameters = // get a string formatted as jobParameters=param1=val1,param2=val2...
      jobConfiguration.put("jobParameters", jobParameters);
      
      RestTemplate template = new RestTemplate();
      List<HttpMessageConverter<?>> converters = new ArrayList<HttpMessageConverter<?>>();
      converters.add(new StringHttpMessageConverter());
      template.setMessageConverters(converters);
      
      String response = template.postForObject(launchURL,null,String.class , jobConfiguration);

      Comment

      Working...
      X