/** * The {@link org.springframework.integration.channel.PublishSubscribeChannel} {@link #channel} * method specific implementation to allow the use of the 'subflow' subscriber capability. * @param publishSubscribeChannelConfigurer the {@link Consumer} to specify * {@link PublishSubscribeSpec} options including 'subflow' definition. * @return the current {@link IntegrationFlowDefinition}. */ public B publishSubscribeChannel(Consumer<PublishSubscribeSpec> publishSubscribeChannelConfigurer) { return publishSubscribeChannel(null, publishSubscribeChannelConfigurer); }
/** * The {@link org.springframework.integration.channel.PublishSubscribeChannel} {@link #channel} * method specific implementation to allow the use of the 'subflow' subscriber capability. * @param publishSubscribeChannelConfigurer the {@link Consumer} to specify * {@link PublishSubscribeSpec} options including 'subflow' definition. * @return the current {@link IntegrationFlowDefinition}. */ public B publishSubscribeChannel(Consumer<PublishSubscribeSpec> publishSubscribeChannelConfigurer) { return publishSubscribeChannel(null, publishSubscribeChannelConfigurer); }
/** * The {@link org.springframework.integration.channel.PublishSubscribeChannel} {@link #channel} * method specific implementation to allow the use of the 'subflow' subscriber capability. * @param publishSubscribeChannelConfigurer the {@link Consumer} to specify * {@link PublishSubscribeSpec} options including 'subflow' definition. * @return the current {@link IntegrationFlowDefinition}. */ public B publishSubscribeChannel(Consumer<PublishSubscribeSpec> publishSubscribeChannelConfigurer) { return publishSubscribeChannel(null, publishSubscribeChannelConfigurer); }
/** * The {@link org.springframework.integration.channel.PublishSubscribeChannel} {@link #channel} * method specific implementation to allow the use of the 'subflow' subscriber capability. * @param publishSubscribeChannelConfigurer the {@link Consumer} to specify * {@link PublishSubscribeSpec} options including 'subflow' definition. * @return the current {@link IntegrationFlowDefinition}. */ public B publishSubscribeChannel(Consumer<PublishSubscribeSpec> publishSubscribeChannelConfigurer) { return publishSubscribeChannel(null, publishSubscribeChannelConfigurer); }
@Bean public IntegrationFlow publishSubscribeFlow() { return flow -> flow .publishSubscribeChannel(s -> s .applySequence(true) .subscribe(f -> f .handle((p, h) -> "Hello") .channel("publishSubscribeAggregateFlow.input")) .subscribe(f -> f .handle((p, h) -> "World!") .channel("publishSubscribeAggregateFlow.input")) ); }
@Bean public IntegrationFlow pubSubFlow() { return f -> f .publishSubscribeChannel(c -> c .subscribe(sf -> sf .handle(m -> subscribersOrderedCall().add(0))) .subscribe(sf -> sf .<String>handle((p, h) -> { subscribersOrderedCall().add(1); return null; })) .subscribe(sf -> sf .handle(subscriberConsumerBean())) .subscribe(sf -> sf .handle(subscriberMessageHandlerBean())) .subscribe(sf -> sf .channel("secondInlineSubscriberChannel") .handle(m -> subscribersOrderedCall().add(4))) ) .<String>handle((p, h) -> { subscribersOrderedCall().add(5); return null; }); }
@Bean public IntegrationFlow subscribersFlow() { return flow -> flow .publishSubscribeChannel(executor(), s -> s .subscribe(f -> f .<Integer>handle((p, h) -> p / 2) .channel(MessageChannels.queue("subscriber1Results"))) .subscribe(f -> f .<Integer>handle((p, h) -> p * 2) .channel(MessageChannels.queue("subscriber2Results")))) .<Integer>handle((p, h) -> p * 3) .channel(MessageChannels.queue("subscriber3Results")); }
@Test public void testDynamicSubFlow() { PollableChannel resultChannel = new QueueChannel(); this.integrationFlowContext.registration(flow -> flow.publishSubscribeChannel(p -> p .minSubscribers(1) .subscribe(f -> f.channel(resultChannel)) )) .id("dynamicFlow") .register(); this.integrationFlowContext.messagingTemplateFor("dynamicFlow").send(new GenericMessage<>("test")); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("test", receive.getPayload()); MessageHistory messageHistory = MessageHistory.read(receive); assertNotNull(messageHistory); String messageHistoryString = messageHistory.toString(); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.input")); assertThat(messageHistoryString, Matchers.containsString("dynamicFlow.subFlow#0.channel#1")); this.integrationFlowContext.remove("dynamicFlow"); }
@Bean public IntegrationFlow publishSubscribeFlow() { return flow -> flow .publishSubscribeChannel(s -> s .applySequence(true) .subscribe(f -> f .handle((p, h) -> "Hello") .channel("publishSubscribeAggregateFlow.input")) .subscribe(f -> f .handle((p, h) -> "World!") .channel("publishSubscribeAggregateFlow.input")) ); }
@Bean public IntegrationFlow sendToKafkaFlow() { return f -> f.<String>split(p -> Stream.generate(() -> p).limit(101).iterator(), null) .publishSubscribeChannel(c -> c .subscribe(sf -> sf.handle(kafkaMessageHandler(producerFactory(), TEST_TOPIC), e -> e.id("kafkaProducer"))) .subscribe(sf -> sf.handle(kafkaMessageHandler(producerFactory(), TEST_TOPIC3), e -> e.id("kafkaProducer3"))) ); }
@Bean public IntegrationFlow subscribersFlow() { return flow -> flow .publishSubscribeChannel(Executors.newCachedThreadPool(), s -> s .subscribe(f -> f .<Integer>handle((p, h) -> p / 2) .channel(c -> c.queue("subscriber1Results"))) .subscribe(f -> f .<Integer>handle((p, h) -> p * 2) .channel(c -> c.queue("subscriber2Results")))) .<Integer>handle((p, h) -> p * 3) .channel(c -> c.queue("subscriber3Results")); }
@Bean public IntegrationFlow sendToKafkaFlow() { return f -> f .<String>split(p -> Stream.generate(() -> p).limit(101).iterator(), null) .publishSubscribeChannel(c -> c .subscribe(sf -> sf.handle( kafkaMessageHandler(producerFactory(), TEST_TOPIC1) .timestampExpression("T(Long).valueOf('1487694048633')"), e -> e.id("kafkaProducer1"))) .subscribe(sf -> sf.handle( kafkaMessageHandler(producerFactory(), TEST_TOPIC2) .timestamp(m -> 1487694048644L), e -> e.id("kafkaProducer2"))) ); }
@Test public void testDynamicSubFlow() { PollableChannel resultChannel = new QueueChannel(); this.integrationFlowContext.registration(flow -> flow.publishSubscribeChannel(p -> p .minSubscribers(1) .subscribe(f -> f.channel(resultChannel)) )) .id("dynamicFlow") .register(); this.integrationFlowContext.messagingTemplateFor("dynamicFlow").send(new GenericMessage<>("test")); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("test", receive.getPayload()); }