/** * Create an {@link IntegrationFlow} with a {@link ChunkProcessorChunkHandler} * configured as a service activator listening to the input channel and replying * on the output channel. * * @return the integration flow */ @SuppressWarnings({"unchecked", "rawtypes"}) public IntegrationFlow build() { Assert.notNull(this.itemWriter, "An ItemWriter must be provided"); Assert.notNull(this.inputChannel, "An InputChannel must be provided"); Assert.notNull(this.outputChannel, "An OutputChannel must be provided"); if(this.itemProcessor == null) { this.itemProcessor = new PassThroughItemProcessor(); } SimpleChunkProcessor<I, O> chunkProcessor = new SimpleChunkProcessor<>(this.itemProcessor, this.itemWriter); ChunkProcessorChunkHandler<I> chunkProcessorChunkHandler = new ChunkProcessorChunkHandler<>(); chunkProcessorChunkHandler.setChunkProcessor(chunkProcessor); return IntegrationFlows .from(this.inputChannel) .handle(chunkProcessorChunkHandler, SERVICE_ACTIVATOR_METHOD_NAME) .channel(this.outputChannel) .get(); }
handler.setChunkProcessor(chunkProcessor);
@Test public void testVanillaHandleChunk() throws Exception { handler.setChunkProcessor(new ChunkProcessor<Object>() { public void process(StepContribution contribution, Chunk<Object> chunk) throws Exception { count += chunk.size(); } }); StepContribution stepContribution = MetaDataInstanceFactory.createStepExecution().createStepContribution(); ChunkResponse response = handler.handleChunk(new ChunkRequest<>(0, StringUtils .commaDelimitedListToSet("foo,bar"), 12L, stepContribution)); assertEquals(stepContribution, response.getStepContribution()); assertEquals(12, response.getJobId().longValue()); assertTrue(response.isSuccessful()); assertEquals(2, count); }
@Bean @Profile("slave") @ServiceActivator(inputChannel = "inboundRequests", outputChannel = "outboundReplies") public ChunkProcessorChunkHandler chunkProcessorChunkHandler(ItemProcessor<Customer, Customer> itemProcessor, ItemWriter<Customer> itemWriter) throws Exception { SimpleChunkProcessor chunkProcessor = new SimpleChunkProcessor<>(itemProcessor, itemWriter); chunkProcessor.afterPropertiesSet(); ChunkProcessorChunkHandler<Customer> chunkHandler = new ChunkProcessorChunkHandler<>(); chunkHandler.setChunkProcessor(chunkProcessor); chunkHandler.afterPropertiesSet(); return chunkHandler; }