Search in sources :

Example 1 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration-samples by spring-projects.

the class Application method addAnotherListenerForTopics.

public void addAnotherListenerForTopics(String... topics) {
    Map<String, Object> consumerProperties = kafkaProperties.buildConsumerProperties();
    // change the group id so we don't revoke the other partitions.
    consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG) + "x");
    IntegrationFlow flow = IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(new DefaultKafkaConsumerFactory<String, String>(consumerProperties), topics)).channel("fromKafka").get();
    this.flowContext.registration(flow).register();
}
Also used : IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 2 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration-samples by spring-projects.

the class Application method addAnotherListenerForTopics.

public void addAnotherListenerForTopics(String... topics) {
    Map<String, Object> consumerProperties = kafkaProperties.buildConsumerProperties();
    // change the group id so we don't revoke the other partitions.
    consumerProperties.put(ConsumerConfig.GROUP_ID_CONFIG, consumerProperties.get(ConsumerConfig.GROUP_ID_CONFIG) + "x");
    IntegrationFlow flow = IntegrationFlows.from(Kafka.messageDrivenChannelAdapter(new DefaultKafkaConsumerFactory<String, String>(consumerProperties), topics)).channel("fromKafka").get();
    this.flowContext.registration(flow).register();
}
Also used : IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) DefaultKafkaConsumerFactory(org.springframework.kafka.core.DefaultKafkaConsumerFactory)

Example 3 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.

the class ManualFlowTests method testWithAnonymousMessageProducerSpecStart.

@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("foo")).channel(channel).get();
    this.integrationFlowContext.registration(flow).register();
    assertTrue(started.get());
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) QueueChannel(org.springframework.integration.channel.QueueChannel) MessageProducerSupport(org.springframework.integration.endpoint.MessageProducerSupport) MessageProducerSpec(org.springframework.integration.dsl.MessageProducerSpec) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) StandardIntegrationFlow(org.springframework.integration.dsl.StandardIntegrationFlow) Test(org.junit.Test)

Example 4 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.

the class ReactiveStreamsTests method testFromPublisher.

@Test
public void testFromPublisher() {
    Flux<Message<?>> messageFlux = Flux.just("1,2,3,4").map(v -> v.split(",")).flatMapIterable(Arrays::asList).map(Integer::parseInt).log("org.springframework.integration.flux").map(GenericMessage<Integer>::new);
    QueueChannel resultChannel = new QueueChannel();
    IntegrationFlow integrationFlow = IntegrationFlows.from(messageFlux).log("org.springframework.integration.flux2").<Integer, Integer>transform(p -> p * 2).channel(resultChannel).get();
    this.integrationFlowContext.registration(integrationFlow).register();
    for (int i = 0; i < 4; i++) {
        Message<?> receive = resultChannel.receive(10000);
        assertNotNull(receive);
        assertEquals((i + 1) * 2, receive.getPayload());
    }
}
Also used : GenericMessage(org.springframework.messaging.support.GenericMessage) Message(org.springframework.messaging.Message) GenericMessage(org.springframework.messaging.support.GenericMessage) QueueChannel(org.springframework.integration.channel.QueueChannel) IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow) Test(org.junit.Test)

Example 5 with IntegrationFlow

use of org.springframework.integration.dsl.IntegrationFlow in project spring-integration by spring-projects.

the class StandardIntegrationFlowContext method register.

private void register(StandardIntegrationFlowRegistrationBuilder builder) {
    IntegrationFlow integrationFlow = builder.integrationFlowRegistration.getIntegrationFlow();
    String flowId = builder.integrationFlowRegistration.getId();
    if (flowId == null) {
        flowId = generateBeanName(integrationFlow, null);
        builder.id(flowId);
    } else if (this.registry.containsKey(flowId)) {
        throw new IllegalArgumentException("An IntegrationFlow '" + this.registry.get(flowId) + "' with flowId '" + flowId + "' is already registered.\n" + "An existing IntegrationFlowRegistration must be destroyed before overriding.");
    }
    IntegrationFlow theFlow = (IntegrationFlow) registerBean(integrationFlow, flowId, null);
    builder.integrationFlowRegistration.setIntegrationFlow(theFlow);
    final String theFlowId = flowId;
    builder.additionalBeans.forEach((key, value) -> registerBean(key, value, theFlowId));
    if (builder.autoStartup) {
        builder.integrationFlowRegistration.start();
    }
    this.registry.put(flowId, builder.integrationFlowRegistration);
}
Also used : IntegrationFlow(org.springframework.integration.dsl.IntegrationFlow)

Aggregations

IntegrationFlow (org.springframework.integration.dsl.IntegrationFlow)17 Test (org.junit.Test)14 QueueChannel (org.springframework.integration.channel.QueueChannel)13 StandardIntegrationFlow (org.springframework.integration.dsl.StandardIntegrationFlow)12 IntegrationFlowRegistration (org.springframework.integration.dsl.context.IntegrationFlowContext.IntegrationFlowRegistration)10 Message (org.springframework.messaging.Message)9 GenericMessage (org.springframework.messaging.support.GenericMessage)9 Matchers.instanceOf (org.hamcrest.Matchers.instanceOf)8 Assert.assertEquals (org.junit.Assert.assertEquals)8 Assert.assertNotNull (org.junit.Assert.assertNotNull)8 Assert.assertThat (org.junit.Assert.assertThat)8 RunWith (org.junit.runner.RunWith)8 Autowired (org.springframework.beans.factory.annotation.Autowired)8 Configuration (org.springframework.context.annotation.Configuration)8 EnableIntegration (org.springframework.integration.config.EnableIntegration)8 IntegrationFlows (org.springframework.integration.dsl.IntegrationFlows)8 IntegrationFlowContext (org.springframework.integration.dsl.context.IntegrationFlowContext)8 DirtiesContext (org.springframework.test.annotation.DirtiesContext)8 SpringRunner (org.springframework.test.context.junit4.SpringRunner)8 File (java.io.File)7