.get(); IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class); integrationFlowContext.registration(standardIntegrationFlow) .autoStartup(false) .register();
@Test public void testIncludesDynamic() { Graph graph = this.server.getGraph(); assertThat(graph.getNodes().size()).isEqualTo(32); IntegrationFlow flow = f -> f.handle(m -> { }); IntegrationFlowRegistration reg = this.flowContext.registration(flow).register(); graph = this.server.rebuild(); assertThat(graph.getNodes().size()).isEqualTo(34); this.flowContext.remove(reg.getId()); graph = this.server.rebuild(); assertThat(graph.getNodes().size()).isEqualTo(32); }
@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"); }
this.integrationFlowContext.registration( flow -> flow .handle(new MessageProducingHandler()) .register(); this.integrationFlowContext.messagingTemplateFor(flowRegistration.getId()) .send(new GenericMessage<>("test"));
/** * Destroy the {@link IntegrationFlow} bean (as well as all its dependant beans) * and clean up all the local cache for it. */ @Override public void destroy() { this.integrationFlowContext.remove(this.id); }
private void register(IntegrationFlowRegistrationBuilder builder) { IntegrationFlow integrationFlow = builder.integrationFlowRegistration.getIntegrationFlow(); String flowId = builder.integrationFlowRegistration.getId(); if (flowId == null) { flowId = generateBeanName(integrationFlow, null); builder.id(flowId); } IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.integrationFlowRegistration.setIntegrationFlow(theFlow); for (Map.Entry<Object, String> entry : builder.additionalBeans.entrySet()) { registerBean(entry.getKey(), entry.getValue(), flowId); } if (builder.autoStartup) { builder.integrationFlowRegistration.start(); } this.registry.put(flowId, builder.integrationFlowRegistration); }
this.flowContext = this.beanFactory.getBean(IntegrationFlowContext.class); boolean useFlowIdAsPrefix = this.flowContext.isUseIdAsPrefix(flowBeanName); int subFlowNameIndex = 0; int channelNameIndex = 0;
private Object registerBean(Object bean, String beanName, String parentName) { if (beanName == null) { beanName = generateBeanName(bean, parentName); } this.autowiredAnnotationBeanPostProcessor.processInjection(bean); bean = this.beanFactory.initializeBean(bean, beanName); this.beanFactory.registerSingleton(beanName, bean); if (parentName != null) { this.beanFactory.registerDependentBean(parentName, beanName); } if (bean instanceof DisposableBean) { ((DefaultSingletonBeanRegistry) this.beanFactory) .registerDisposableBean(beanName, (DisposableBean) bean); } return bean; }
.registration(flow -> flow .bridge(e -> e.role(testRole)) .channel(resultChannel)) this.integrationFlowContext.messagingTemplateFor(flowRegistration.getId());
@Test public void testWrongLifecycle() { try { this.integrationFlowContext.remove("foo"); fail("IllegalStateException expected"); } catch (Exception e) { assertThat(e, instanceOf(IllegalStateException.class)); assertThat(e.getMessage(), containsString("An IntegrationFlow with the id [" + "foo" + "] doesn't exist in the registry.")); } }
private void register(IntegrationFlowRegistrationBuilder builder) { IntegrationFlow integrationFlow = builder.integrationFlowRegistration.getIntegrationFlow(); String flowId = builder.integrationFlowRegistration.getId(); if (flowId == null) { flowId = generateBeanName(integrationFlow, null); builder.id(flowId); } IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null); builder.integrationFlowRegistration.setIntegrationFlow(theFlow); for (Map.Entry<Object, String> entry : builder.additionalBeans.entrySet()) { registerBean(entry.getKey(), entry.getValue(), flowId); } if (builder.autoStartup) { builder.integrationFlowRegistration.start(); } this.registry.put(flowId, builder.integrationFlowRegistration); }
this.flowContext = this.beanFactory.getBean(IntegrationFlowContext.class); boolean useFlowIdAsPrefix = this.flowContext.isUseIdAsPrefix(flowBeanName); int subFlowNameIndex = 0; int channelNameIndex = 0;
private Object registerBean(Object bean, String beanName, String parentName) { if (beanName == null) { beanName = generateBeanName(bean, parentName); } this.autowiredAnnotationBeanPostProcessor.processInjection(bean); bean = this.beanFactory.initializeBean(bean, beanName); this.beanFactory.registerSingleton(beanName, bean); if (parentName != null) { this.beanFactory.registerDependentBean(parentName, beanName); } if (bean instanceof DisposableBean) { ((DefaultSingletonBeanRegistry) this.beanFactory) .registerDisposableBean(beanName, (DisposableBean) bean); } return bean; }
.get(); IntegrationFlowContext integrationFlowContext = this.beanFactory.getBean(IntegrationFlowContext.class); integrationFlowContext.registration(standardIntegrationFlow) .autoStartup(false) .register();
@Test public void testWrongLifecycle() { class MyIntegrationFlow implements IntegrationFlow { @Override public void configure(IntegrationFlowDefinition<?> flow) { flow.bridge(null); } } IntegrationFlow testFlow = new MyIntegrationFlow(); // This is fine because we are not going to start it automatically. assertNotNull(this.integrationFlowContext.registration(testFlow) .autoStartup(false) .register()); try { this.integrationFlowContext.registration(testFlow).register(); fail("IllegalStateException expected"); } catch (Exception e) { assertThat(e, instanceOf(IllegalStateException.class)); assertThat(e.getMessage(), containsString("Consider to implement it for [" + testFlow + "].")); } try { this.integrationFlowContext.remove("foo"); fail("IllegalStateException expected"); } catch (Exception e) { assertThat(e, instanceOf(IllegalStateException.class)); assertThat(e.getMessage(), containsString("But [" + "foo" + "] ins't one of them.")); } }
@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()); }
/** * Destroy the {@link IntegrationFlow} bean (as well as all its dependant beans) * and clean up all the local cache for it. */ public void destroy() { this.integrationFlowContext.remove(this.id); }
@Test public void testConcurrentRegistration() throws InterruptedException { ExecutorService executorService = Executors.newCachedThreadPool(); List<IntegrationFlowRegistration> flowRegistrations = new CopyOnWriteArrayList<>(); AtomicBoolean exceptionHappened = new AtomicBoolean(); for (int i = 0; i < 100; i++) { int index = i; executorService.execute(() -> { IntegrationFlow flow = f -> f .transform(m -> m); try { IntegrationFlowContext.IntegrationFlowRegistrationBuilder registration = this.integrationFlowContext.registration(flow); if (index % 2 == 0) { registration.id("concurrentFlow#" + index); } flowRegistrations.add(registration.register()); } catch (Exception e) { exceptionHappened.set(true); } }); } executorService.shutdownNow(); assertTrue(executorService.awaitTermination(10, TimeUnit.SECONDS)); assertFalse(exceptionHappened.get()); flowRegistrations.forEach(IntegrationFlowRegistration::destroy); }
/** * Destroy the {@link IntegrationFlow} bean (as well as all its dependant beans) * and clean up all the local cache for it. */ @Override public void destroy() { this.integrationFlowContext.remove(this.id); }
@Test void testRuntimeBeanRegistration(@Autowired IntegrationFlowContext context) throws Exception { Set<ObjectName> query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); IntegrationFlow dynamicFlow = IntegrationFlows.from(() -> "foo", e -> e.poller(p -> p.fixedDelay(1000))) .channel("channelTwo") .nullChannel(); IntegrationFlowContext.IntegrationFlowRegistration registration = context.registration(dynamicFlow) .id("dynamic") .register(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(4); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(1); registration.destroy(); query = this.server.queryNames(new ObjectName("dsl:type=MessageChannel,*"), null); assertThat(query).hasSize(3); query = this.server.queryNames(new ObjectName("dsl:type=MessageHandler,*"), null); assertThat(query).hasSize(2); query = this.server.queryNames(new ObjectName("dsl:type=MessageSource,*"), null); assertThat(query).hasSize(0); }