org.springframework.integration.scheduling.PollerMetadata Java Examples

The following examples show how to use org.springframework.integration.scheduling.PollerMetadata. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupplierWithCustomPoller() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(SupplierWithExplicitPollerConfiguration.class))
					.web(WebApplicationType.NONE)
					.run("--spring.jmx.enabled=false", "--spring.cloud.stream.poller.fixed-delay=2000")) {

		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		PollerMetadata pollerMetadata = context.getBean(PollerMetadata.class);
		assertThat(((PeriodicTrigger) pollerMetadata.getTrigger()).getPeriod()).isEqualTo(2000);

		Message<byte[]> outputMessage = outputDestination.receive(6000);
		assertThat(outputMessage.getPayload()).isEqualTo("hello".getBytes());
	}
}
 
Example #2
Source File: ImplicitFunctionBindingTests.java    From spring-cloud-stream with Apache License 2.0 6 votes vote down vote up
@Test
public void testSupplierWithCustomPollerAndMappedOutput() {
	System.clearProperty("spring.cloud.function.definition");
	try (ConfigurableApplicationContext context = new SpringApplicationBuilder(
			TestChannelBinderConfiguration.getCompleteConfiguration(SupplierWithExplicitPollerConfiguration.class))
					.web(WebApplicationType.NONE).run("--spring.jmx.enabled=false",
							"--spring.cloud.stream.poller.fixed-delay=2000",
							"--spring.cloud.function.bindings.supplier-out-0=output")) {

		OutputDestination outputDestination = context.getBean(OutputDestination.class);

		PollerMetadata pollerMetadata = context.getBean(PollerMetadata.class);
		assertThat(((PeriodicTrigger) pollerMetadata.getTrigger()).getPeriod()).isEqualTo(2000);

		Message<byte[]> outputMessage = outputDestination.receive(6000);
		assertThat(outputMessage.getPayload()).isEqualTo("hello".getBytes());
	}
}
 
Example #3
Source File: CustomPollerConfiguration.java    From paascloud-master with Apache License 2.0 5 votes vote down vote up
/**
 * Custom poller poller metadata.
 *
 * @return the poller metadata
 */
@Bean(name = StreamSpanReporter.POLLER)
PollerMetadata customPoller() {
	PollerMetadata poller = new PollerMetadata();
	poller.setMaxMessagesPerPoll(500);
	poller.setTrigger(new PeriodicTrigger(5000L));
	return poller;
}
 
Example #4
Source File: TriggerConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@Bean(name = { "defaultPoller", PollerMetadata.DEFAULT_POLLER })
public PollerMetadata defaultPoller(Trigger trigger) {
	logger.info("Trigger type: " + trigger);
	PollerMetadata pollerMetadata = new PollerMetadata();
	pollerMetadata.setTrigger(trigger);
	// the default is 1 since a source might return
	// a non-null and non-interruptible value every time it is invoked
	pollerMetadata.setMaxMessagesPerPoll(this.triggerProperties.getMaxMessages() > -1
			? this.triggerProperties.getMaxMessages()
			: 1);
	return pollerMetadata;
}
 
Example #5
Source File: DefaultPollerProperties.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
public PollerMetadata getPollerMetadata() {
	PollerMetadata pollerMetadata = new PollerMetadata();
	if (cron != null) {
		pollerMetadata.setTrigger(new CronTrigger(cron));
	}
	else {
		final PeriodicTrigger periodicTrigger = new PeriodicTrigger(this.fixedDelay);
		periodicTrigger.setInitialDelay(initialDelay);
		pollerMetadata.setTrigger(periodicTrigger);
	}

	pollerMetadata.setMaxMessagesPerPoll(this.maxMessagesPerPoll);
	return pollerMetadata;
}
 
Example #6
Source File: TxIntegrationConfig.java    From tutorials with MIT License 5 votes vote down vote up
@Bean
public PollerMetadata pollerMetadata() {
    return Pollers.fixedDelay(5000)
             .advice(transactionInterceptor())
             .transactionSynchronizationFactory(transactionSynchronizationFactory)
             .get();
}
 
Example #7
Source File: ChannelBindingAutoConfiguration.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Bean(name = PollerMetadata.DEFAULT_POLLER)
@ConditionalOnMissingBean(PollerMetadata.class)
public PollerMetadata defaultPoller() {
	return this.poller.getPollerMetadata();
}