Search in sources :

Example 51 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class InboundChannelAdapterAnnotationPostProcessor method postProcess.

@Override
public Object postProcess(Object bean, String beanName, Method method, List<Annotation> annotations) {
    String channelName = MessagingAnnotationUtils.resolveAttribute(annotations, AnnotationUtils.VALUE, String.class);
    Assert.hasText(channelName, "The channel ('value' attribute of @InboundChannelAdapter) can't be empty.");
    MessageSource<?> messageSource = null;
    try {
        messageSource = createMessageSource(bean, beanName, method);
    } catch (NoSuchBeanDefinitionException e) {
        if (this.logger.isDebugEnabled()) {
            this.logger.debug("Skipping endpoint creation; " + e.getMessage() + "; perhaps due to some '@Conditional' annotation.");
        }
        return null;
    }
    SourcePollingChannelAdapter adapter = new SourcePollingChannelAdapter();
    adapter.setOutputChannelName(channelName);
    adapter.setSource(messageSource);
    configurePollingEndpoint(adapter, annotations);
    return adapter;
}
Also used : SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) NoSuchBeanDefinitionException(org.springframework.beans.factory.NoSuchBeanDefinitionException)

Example 52 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class MBeanExporterIntegrationTests method testSelfDestruction.

@Test
public void testSelfDestruction() throws Exception {
    context = new GenericXmlApplicationContext(getClass(), "self-destruction-context.xml");
    SourcePollingChannelAdapter adapter = context.getBean(SourcePollingChannelAdapter.class);
    adapter.start();
    int n = 0;
    while (adapter.isRunning()) {
        n += 10;
        if (n > 10000) {
            fail("Adapter failed to stop");
        }
        Thread.sleep(10);
    }
}
Also used : SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) GenericXmlApplicationContext(org.springframework.context.support.GenericXmlApplicationContext) AbstractEndpoint(org.springframework.integration.endpoint.AbstractEndpoint) Test(org.junit.Test)

Example 53 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class JpaPollingChannelAdapterTests method testWithJpaQueryAndDelete.

/**
 * In this test, a Jpa Polling Channel Adapter will use JpQL query
 * to retrieve a list of records from the database. Additionally, the records
 * will be deleted after the polling.
 *
 * @throws Exception
 */
@Test
@DirtiesContext
public void testWithJpaQueryAndDelete() throws Exception {
    testTrigger.reset();
    // ~~~~SETUP~~~~~
    final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
    jpaExecutor.setJpaQuery("from Student s");
    jpaExecutor.setDeleteAfterPoll(true);
    jpaExecutor.setDeleteInBatch(true);
    jpaExecutor.setFlush(true);
    jpaExecutor.afterPropertiesSet();
    final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
    final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
    adapter.start();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
    final Consumer consumer = new Consumer();
    received.add(consumer.poll(10000));
    Message<Collection<?>> message = received.get(0);
    adapter.stop();
    assertNotNull("Message is null.", message);
    assertNotNull(message.getPayload());
    Collection<?> students = message.getPayload();
    assertTrue(students.size() == 3);
    Long studentCount = waitForDeletes(students);
    assertEquals(Long.valueOf(0), studentCount);
}
Also used : Message(org.springframework.messaging.Message) Consumer(org.springframework.integration.jpa.test.Consumer) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Example 54 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class JpaPollingChannelAdapterTests method testWithJpaQuery.

/**
 * In this test, a Jpa Polling Channel Adapter will use JpQL query
 * to retrieve a list of records from the database.
 *
 * @throws Exception
 */
@Test
public void testWithJpaQuery() throws Exception {
    testTrigger.reset();
    // ~~~~SETUP~~~~~
    final JpaExecutor jpaExecutor = new JpaExecutor(entityManager);
    jpaExecutor.setJpaQuery("from Student");
    jpaExecutor.afterPropertiesSet();
    final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
    final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
    adapter.start();
    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
    final Consumer consumer = new Consumer();
    received.add(consumer.poll(10000));
    Message<Collection<?>> message = received.get(0);
    adapter.stop();
    assertNotNull(message);
    assertNotNull(message.getPayload());
    Collection<?> primeNumbers = message.getPayload();
    assertTrue(primeNumbers.size() == 3);
}
Also used : Message(org.springframework.messaging.Message) Consumer(org.springframework.integration.jpa.test.Consumer) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test)

Example 55 with SourcePollingChannelAdapter

use of org.springframework.integration.endpoint.SourcePollingChannelAdapter in project spring-integration by spring-projects.

the class JpaPollingChannelAdapterTests method testWithJpaQueryAndDeletePerRow.

/**
 * In this test, a Jpa Polling Channel Adapter will use JpQL query
 * to retrieve a list of records from the database. Additionaly, the records
 * will be deleted after the polling.
 *
 * @throws Exception
 */
@Test
@DirtiesContext
public void testWithJpaQueryAndDeletePerRow() throws Exception {
    testTrigger.reset();
    // ~~~~SETUP~~~~~
    final JpaExecutor jpaExecutor = new JpaExecutor(jpaOperations);
    jpaExecutor.setJpaQuery("from Student s");
    jpaExecutor.setDeleteAfterPoll(true);
    jpaExecutor.setDeleteInBatch(false);
    jpaExecutor.afterPropertiesSet();
    final JpaPollingChannelAdapter jpaPollingChannelAdapter = new JpaPollingChannelAdapter(jpaExecutor);
    final SourcePollingChannelAdapter adapter = JpaTestUtils.getSourcePollingChannelAdapter(jpaPollingChannelAdapter, this.outputChannel, this.poller, this.context, this.getClass().getClassLoader());
    adapter.start();
    Thread.sleep(1000);
    final Consumer consumer = new Consumer();
    final List<Message<Collection<?>>> received = new ArrayList<Message<Collection<?>>>();
    received.add(consumer.poll(10000));
    final Message<Collection<?>> message = received.get(0);
    adapter.stop();
    assertNotNull("Message is null.", message);
    assertNotNull(message.getPayload());
    final Collection<?> students = message.getPayload();
    assertTrue(students.size() == 3);
    Long studentCount = waitForDeletes(students);
    assertEquals(Long.valueOf(0), studentCount);
}
Also used : Consumer(org.springframework.integration.jpa.test.Consumer) Message(org.springframework.messaging.Message) JpaExecutor(org.springframework.integration.jpa.core.JpaExecutor) ArrayList(java.util.ArrayList) SourcePollingChannelAdapter(org.springframework.integration.endpoint.SourcePollingChannelAdapter) Collection(java.util.Collection) Test(org.junit.Test) DirtiesContext(org.springframework.test.annotation.DirtiesContext)

Aggregations

SourcePollingChannelAdapter (org.springframework.integration.endpoint.SourcePollingChannelAdapter)66 Test (org.junit.Test)58 ClassPathXmlApplicationContext (org.springframework.context.support.ClassPathXmlApplicationContext)29 Message (org.springframework.messaging.Message)15 PollableChannel (org.springframework.messaging.PollableChannel)13 Collection (java.util.Collection)10 ArrayList (java.util.ArrayList)9 QueueChannel (org.springframework.integration.channel.QueueChannel)9 JpaExecutor (org.springframework.integration.jpa.core.JpaExecutor)9 Consumer (org.springframework.integration.jpa.test.Consumer)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)8 PeriodicTrigger (org.springframework.scheduling.support.PeriodicTrigger)8 Trigger (org.springframework.scheduling.Trigger)7 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)6 Expression (org.springframework.expression.Expression)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 BeanFactory (org.springframework.beans.factory.BeanFactory)5 RedisConnectionFactory (org.springframework.data.redis.connection.RedisConnectionFactory)5 RedisAvailable (org.springframework.integration.redis.rules.RedisAvailable)5 File (java.io.File)4