/** * 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; }
PollerSpec(Trigger trigger) { this.target = new PollerMetadata(); this.target.setAdviceChain(this.adviceChain); this.target.setTrigger(trigger); }
public SourcePollingChannelAdapterSpec poller(PollerMetadata pollerMetadata) { if (pollerMetadata != null) { if (PollerMetadata.MAX_MESSAGES_UNBOUNDED == pollerMetadata.getMaxMessagesPerPoll()) { pollerMetadata.setMaxMessagesPerPoll(1); } this.endpointFactoryBean.setPollerMetadata(pollerMetadata); } return _this(); }
pollerMetadata = new PollerMetadata(); if (StringUtils.hasText(maxMessagesPerPollValue)) { pollerMetadata.setMaxMessagesPerPoll(Long.parseLong(maxMessagesPerPollValue)); pollerMetadata.setMaxMessagesPerPoll(1); pollerMetadata.setTaskExecutor(this.beanFactory.getBean(executorRef, TaskExecutor.class)); pollerMetadata.setTrigger(trigger); errorHandler.setDefaultErrorChannelName(errorChannel); errorHandler.setBeanFactory(this.beanFactory); pollerMetadata.setErrorHandler(errorHandler); pollerMetadata.setReceiveTimeout(Long.parseLong(receiveTimeout)); pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(pollerMetadata, "No poller has been defined for Annotation-based endpoint, " + "and no default poller is available within the context."); pollingEndpoint.setTaskExecutor(pollerMetadata.getTaskExecutor()); pollingEndpoint.setTrigger(pollerMetadata.getTrigger()); pollingEndpoint.setAdviceChain(pollerMetadata.getAdviceChain()); pollingEndpoint.setMaxMessagesPerPoll(pollerMetadata.getMaxMessagesPerPoll()); pollingEndpoint.setErrorHandler(pollerMetadata.getErrorHandler()); if (pollingEndpoint instanceof PollingConsumer) { ((PollingConsumer) pollingEndpoint).setReceiveTimeout(pollerMetadata.getReceiveTimeout()); pollingEndpoint.setTransactionSynchronizationFactory(pollerMetadata.getTransactionSynchronizationFactory());
@Bean(name = PollerMetadata.DEFAULT_POLLER) public PollerMetadata defaultPoller() { PollerMetadata pollerMetadata = new PollerMetadata(); pollerMetadata.setTrigger(t -> null); return pollerMetadata; }
factoryBean.setOutputChannel(outputChannel); factoryBean.setSource(() -> new GenericMessage<>("test")); PollerMetadata pollerMetadata = new PollerMetadata(); List<Advice> adviceChain = new ArrayList<>(); final AtomicBoolean adviceApplied = new AtomicBoolean(false); return invocation.proceed(); }); pollerMetadata.setTrigger(new PeriodicTrigger(5000)); pollerMetadata.setMaxMessagesPerPoll(1); final AtomicInteger count = new AtomicInteger(); final MethodInterceptor txAdvice = mock(MethodInterceptor.class); }); pollerMetadata.setAdviceChain(adviceChain); factoryBean.setPollerMetadata(pollerMetadata); factoryBean.setAutoStartup(true);
@Bean(name = PollerMetadata.DEFAULT_POLLER) public PollerMetadata defaultPoller() { PollerMetadata poller = new PollerMetadata(); poller.setTrigger(new PeriodicTrigger(60000)); MessagePublishingErrorHandler errorHandler = new MessagePublishingErrorHandler(); errorHandler.setDefaultErrorChannel(myErrors()); poller.setErrorHandler(errorHandler); return poller; }
this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '" + this.beanName + "', and no default poller is available within the context."); if (this.pollerMetadata.getMaxMessagesPerPoll() == Integer.MIN_VALUE) { this.pollerMetadata.setMaxMessagesPerPoll(1); spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); if (this.sendTimeout != null) { spca.setSendTimeout(this.sendTimeout); spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setAdviceChain(this.pollerMetadata.getAdviceChain()); spca.setTrigger(this.pollerMetadata.getTrigger()); spca.setErrorHandler(this.pollerMetadata.getErrorHandler()); spca.setBeanClassLoader(this.beanClassLoader); spca.setAutoStartup(this.autoStartup); spca.setBeanName(this.beanName); spca.setBeanFactory(this.beanFactory); spca.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory()); spca.afterPropertiesSet(); this.adapter = spca;
PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler); if (this.pollerMetadata == null) { this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName + "', and no default poller is available within the context."); pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); pollingConsumer.setTrigger(this.pollerMetadata.getTrigger()); pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain()); pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler()); pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout()); pollingConsumer.setTransactionSynchronizationFactory( this.pollerMetadata.getTransactionSynchronizationFactory()); pollingConsumer.setBeanClassLoader(this.beanClassLoader); pollingConsumer.setBeanFactory(this.beanFactory);
private Consumer<SourcePollingChannelAdapterSpec> consumerSpec(Advice advice) { if (advice == null) { return spec -> spec.poller(this.defaultPoller); } else { PollerMetadata poller = new PollerMetadata(); BeanUtils.copyProperties(this.defaultPoller, poller, "transactionSynchronizationFactory"); poller.setAdviceChain(Arrays.asList(advice)); return spec -> spec.poller(poller); } }
private void initializeAdapter() { synchronized (this.initializationMonitor) { if (this.initialized) { return; } Assert.notNull(this.source, "source is required"); Assert.notNull(this.outputChannel, "outputChannel is required"); SourcePollingChannelAdapter spca = new SourcePollingChannelAdapter(); spca.setSource(this.source); spca.setOutputChannel(this.outputChannel); if (this.pollerMetadata == null) { this.pollerMetadata = IntegrationContextUtils.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '" + this.beanName + "', and no default poller is available within the context."); } spca.setTrigger(this.pollerMetadata.getTrigger()); spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setTransactionManager(this.pollerMetadata.getTransactionManager()); spca.setTransactionDefinition(this.pollerMetadata.getTransactionDefinition()); spca.setAdviceChain(this.pollerMetadata.getAdviceChain()); spca.setAutoStartup(this.autoStartup); spca.setBeanName(this.beanName); spca.setBeanFactory(this.beanFactory); spca.setBeanClassLoader(this.beanClassLoader); spca.afterPropertiesSet(); this.adapter = spca; this.initialized = true; } }
private Consumer<SourcePollingChannelAdapterSpec> consumerSpecWithDelete(Advice advice) { final PollerMetadata poller = new PollerMetadata(); BeanUtils.copyProperties(this.defaultPoller, poller, "transactionSynchronizationFactory"); TransactionSynchronizationProcessor processor = new RemoteFileDeletingTransactionSynchronizationProcessor( this.sftpTemplate, this.properties.getRemoteFileSeparator()); poller.setTransactionSynchronizationFactory(new DefaultTransactionSynchronizationFactory(processor)); poller.setAdviceChain(Collections.singletonList(new TransactionInterceptor( new PseudoTransactionManager(), new MatchAlwaysTransactionAttributeSource()))); if (advice != null) { poller.setAdviceChain(Arrays.asList(advice)); } return spec -> spec.poller(poller); }
/** * @param maxMessagesPerPoll the maxMessagesPerPoll to set. * @return the spec. * @see PollerMetadata#setMaxMessagesPerPoll */ public PollerSpec maxMessagesPerPoll(long maxMessagesPerPoll) { this.target.setMaxMessagesPerPoll(maxMessagesPerPoll); return this; }
/** * Specify the {@link ErrorHandler} to wrap a {@code taskExecutor} * to the {@link org.springframework.integration.util.ErrorHandlingTaskExecutor}. * @param errorHandler the {@link ErrorHandler} to use. * @return the spec. * @see #taskExecutor(Executor) */ public PollerSpec errorHandler(ErrorHandler errorHandler) { this.target.setErrorHandler(errorHandler); return this; }
/** * Specify the {@link TransactionSynchronizationFactory} to attach a * {@link org.springframework.transaction.support.TransactionSynchronization} * to the transaction around {@code poll} operation. * @param transactionSynchronizationFactory the TransactionSynchronizationFactory to use. * @return the spec. */ public PollerSpec transactionSynchronizationFactory( TransactionSynchronizationFactory transactionSynchronizationFactory) { this.target.setTransactionSynchronizationFactory(transactionSynchronizationFactory); return this; }
pollerMetadata = new PollerMetadata(); if (StringUtils.hasText(maxMessagesPerPollValue)) { pollerMetadata.setMaxMessagesPerPoll(Long.parseLong(maxMessagesPerPollValue)); pollerMetadata.setMaxMessagesPerPoll(1); pollerMetadata.setTaskExecutor(this.beanFactory.getBean(executorRef, TaskExecutor.class)); pollerMetadata.setTrigger(trigger); errorHandler.setDefaultErrorChannelName(errorChannel); errorHandler.setBeanFactory(this.beanFactory); pollerMetadata.setErrorHandler(errorHandler); pollerMetadata.setReceiveTimeout(Long.parseLong(receiveTimeout)); pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(pollerMetadata, "No poller has been defined for Annotation-based endpoint, " + "and no default poller is available within the context."); pollingEndpoint.setTaskExecutor(pollerMetadata.getTaskExecutor()); pollingEndpoint.setTrigger(pollerMetadata.getTrigger()); pollingEndpoint.setAdviceChain(pollerMetadata.getAdviceChain()); pollingEndpoint.setMaxMessagesPerPoll(pollerMetadata.getMaxMessagesPerPoll()); pollingEndpoint.setErrorHandler(pollerMetadata.getErrorHandler()); if (pollingEndpoint instanceof PollingConsumer) { ((PollingConsumer) pollingEndpoint).setReceiveTimeout(pollerMetadata.getReceiveTimeout()); pollingEndpoint.setTransactionSynchronizationFactory(pollerMetadata.getTransactionSynchronizationFactory());
@Bean public PollerMetadata myPoller() { PollerMetadata pollerMetadata = new PollerMetadata(); pollerMetadata.setTrigger(new PeriodicTrigger(11)); return pollerMetadata; }
@Test public void testAdviceChain() throws Exception { SourcePollingChannelAdapterFactoryBean factoryBean = new SourcePollingChannelAdapterFactoryBean(); QueueChannel outputChannel = new QueueChannel(); TestApplicationContext context = TestUtils.createTestApplicationContext(); factoryBean.setBeanFactory(context.getBeanFactory()); factoryBean.setBeanClassLoader(ClassUtils.getDefaultClassLoader()); factoryBean.setOutputChannel(outputChannel); factoryBean.setSource(() -> new GenericMessage<>("test")); PollerMetadata pollerMetadata = new PollerMetadata(); List<Advice> adviceChain = new ArrayList<>(); final AtomicBoolean adviceApplied = new AtomicBoolean(false); adviceChain.add((MethodInterceptor) invocation -> { adviceApplied.set(true); return invocation.proceed(); }); pollerMetadata.setTrigger(new PeriodicTrigger(5000)); pollerMetadata.setMaxMessagesPerPoll(1); pollerMetadata.setAdviceChain(adviceChain); factoryBean.setPollerMetadata(pollerMetadata); factoryBean.setAutoStartup(true); factoryBean.afterPropertiesSet(); context.registerEndpoint("testPollingEndpoint", factoryBean.getObject()); context.refresh(); Message<?> message = outputChannel.receive(5000); assertEquals("test", message.getPayload()); assertTrue("adviceChain was not applied", adviceApplied.get()); context.close(); }
this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for channel-adapter '" + this.beanName + "', and no default poller is available within the context."); if (this.pollerMetadata.getMaxMessagesPerPoll() == Integer.MIN_VALUE) { this.pollerMetadata.setMaxMessagesPerPoll(1); spca.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); if (this.sendTimeout != null) { spca.setSendTimeout(this.sendTimeout); spca.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); spca.setAdviceChain(this.pollerMetadata.getAdviceChain()); spca.setTrigger(this.pollerMetadata.getTrigger()); spca.setErrorHandler(this.pollerMetadata.getErrorHandler()); spca.setBeanClassLoader(this.beanClassLoader); spca.setAutoStartup(this.autoStartup); spca.setBeanName(this.beanName); spca.setBeanFactory(this.beanFactory); spca.setTransactionSynchronizationFactory(this.pollerMetadata.getTransactionSynchronizationFactory()); spca.afterPropertiesSet(); this.adapter = spca;
PollingConsumer pollingConsumer = new PollingConsumer((PollableChannel) channel, this.handler); if (this.pollerMetadata == null) { this.pollerMetadata = PollerMetadata.getDefaultPollerMetadata(this.beanFactory); Assert.notNull(this.pollerMetadata, "No poller has been defined for endpoint '" + this.beanName + "', and no default poller is available within the context."); pollingConsumer.setTaskExecutor(this.pollerMetadata.getTaskExecutor()); pollingConsumer.setTrigger(this.pollerMetadata.getTrigger()); pollingConsumer.setAdviceChain(this.pollerMetadata.getAdviceChain()); pollingConsumer.setMaxMessagesPerPoll(this.pollerMetadata.getMaxMessagesPerPoll()); pollingConsumer.setErrorHandler(this.pollerMetadata.getErrorHandler()); pollingConsumer.setReceiveTimeout(this.pollerMetadata.getReceiveTimeout()); pollingConsumer.setTransactionSynchronizationFactory( this.pollerMetadata.getTransactionSynchronizationFactory()); pollingConsumer.setBeanClassLoader(this.beanClassLoader); pollingConsumer.setBeanFactory(this.beanFactory);