@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); }
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.")); } }
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); }
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); }
@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()); }
public IntegrationFlowRegistrationBuilder addBean(Object bean) { return addBean(null, bean); }
/** * Associate provided {@link IntegrationFlow} with an {@link IntegrationFlowRegistrationBuilder} * for additional options and farther registration in the application context. * @param integrationFlow the {@link IntegrationFlow} to register * @return the IntegrationFlowRegistrationBuilder associated with the provided {@link IntegrationFlow} */ public IntegrationFlowRegistrationBuilder registration(IntegrationFlow integrationFlow) { return new IntegrationFlowRegistrationBuilder(integrationFlow); }
/** * Associate provided {@link IntegrationFlow} with an {@link IntegrationFlowRegistrationBuilder} * for additional options and farther registration in the application context. * @param integrationFlow the {@link IntegrationFlow} to register * @return the IntegrationFlowRegistrationBuilder associated with the provided {@link IntegrationFlow} */ public IntegrationFlowRegistrationBuilder registration(IntegrationFlow integrationFlow) { return new IntegrationFlowRegistrationBuilder(integrationFlow); }
@Test public void testDynamicAdapterFlow() { this.integrationFlowContext.registration(new MyFlowAdapter()).register(); PollableChannel resultChannel = this.beanFactory.getBean("flowAdapterOutput", PollableChannel.class); Message<?> receive = resultChannel.receive(1000); assertNotNull(receive); assertEquals("flowAdapterMessage", receive.getPayload()); }
public IntegrationFlowRegistrationBuilder addBean(Object bean) { return addBean(null, bean); }
IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(myFlow) .id(flowId) .useFlowIdAsPrefix() .addBean(additionalBean) .register();
.bridge(e -> e.role(testRole)) .channel(resultChannel)) .register();
.channel(channel) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); assertTrue(started.get());
.handle(new MessageProducingHandler()) .channel(resultChannel)) .register();
@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); }
@Test public void testDynamicHttpEndpoint() throws Exception { IntegrationFlow flow = IntegrationFlows.from(Http.inboundGateway("/dynamic") .requestMapping(r -> r.params("name")) .payloadExpression("#requestParams.name[0]")) .<String, String>transform(String::toLowerCase) .get(); IntegrationFlowContext.IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); this.mockMvc.perform( get("/dynamic") .with(httpBasic("admin", "admin")) .param("name", "BAR")) .andExpect( content() .string("bar")); flowRegistration.destroy(); this.mockMvc.perform( get("/dynamic") .with(httpBasic("admin", "admin")) .param("name", "BAZ")) .andExpect( status() .isNotFound()); }
@Test public void testWithAnonymousMessageProducerSpecStart() { final AtomicBoolean started = new AtomicBoolean(); class MyProducer extends MessageProducerSupport { @Override protected void doStart() { started.set(true); super.doStart(); } } class MyProducerSpec extends MessageProducerSpec<MyProducerSpec, MyProducer> { MyProducerSpec(MyProducer producer) { super(producer); } } MyProducerSpec spec = new MyProducerSpec(new MyProducer()); QueueChannel channel = new QueueChannel(); IntegrationFlow flow = IntegrationFlows.from(spec.id("fooChannel")) .channel(channel) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext.registration(flow).register(); assertTrue(started.get()); flowRegistration.destroy(); }
@Test public void testRegistrationDuplicationRejected() { String testId = "testId"; StandardIntegrationFlow testFlow = IntegrationFlows.from(Supplier.class) .get(); IntegrationFlowRegistration flowRegistration = this.integrationFlowContext .registration(testFlow) .id(testId) .register(); try { this.integrationFlowContext .registration(testFlow) .id(testId) .register(); } catch (Exception e) { assertThat(e, instanceOf(IllegalArgumentException.class)); assertThat(e.getMessage(), containsString("with flowId '" + testId + "' is already registered.")); } flowRegistration.destroy(); }