Java Code Examples for org.springframework.integration.core.MessageSource

The following examples show how to use org.springframework.integration.core.MessageSource. These examples are extracted from open source projects. 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 Project: spring-cloud   Source File: DataProducer.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
public MessageSource<TimeInfo> timerMessageSource() {
    return () -> MessageBuilder.withPayload(
            TimeInfo.builder().time(Long.toString(System.currentTimeMillis())).label(UUID.randomUUID().toString()).build())
            .build();
}
 
Example 2
Source Project: spring-cloud   Source File: SampleSource.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = MultiOutputSource.OUTPUT1, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public synchronized MessageSource<String> messageSource1() {
    return new MessageSource<String>() {
        public Message<String> receive() {
            return new GenericMessage<String>("message1_" + UUID.randomUUID().toString());
        }
    };
}
 
Example 3
Source Project: spring-cloud   Source File: SampleSource.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = MultiOutputSource.OUTPUT2, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public synchronized MessageSource<String> messageSource2() {
    return new MessageSource<String>() {
        public Message<String> receive() {
            return new GenericMessage<String>("message2_" + UUID.randomUUID().toString());
        }
    };
}
 
Example 4
Source Project: activiti-examples   Source File: DemoApplication.java    License: Apache License 2.0 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "1000"))
public MessageSource<File> fileReadingMessageSource() {
    FileReadingMessageSource sourceReader = new FileReadingMessageSource();
    sourceReader.setDirectory(new File(INPUT_DIR));
    sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
    return sourceReader;
}
 
Example 5
Source Project: java-examples   Source File: SftpConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@InboundChannelAdapter(channel = "fromSftpChannel", poller = @Poller(cron = "0/5 * * * * *"))
public MessageSource<File> sftpMessageSource() {
    SftpInboundFileSynchronizingMessageSource source = new SftpInboundFileSynchronizingMessageSource(
            sftpInboundFileSynchronizer());
    source.setLocalDirectory(new File(sftpLocalDirectoryDownload));
    source.setAutoCreateLocalDirectory(true);
    source.setLocalFilter(new AcceptOnceFileListFilter<File>());
    return source;
}
 
Example 6
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "60000", maxMessagesPerPoll = "1"))
public MessageSource<StockPriceChangeEvent> stockPriceChangeEvent() {

	StockTicker[] tickers = StockTicker.values();
	String randomStockTicker = tickers[ThreadLocalRandom.current().nextInt(tickers.length)].name();

	return () -> {
		StockPriceChangeEvent event = new StockPriceChangeEvent(randomStockTicker,
				new BigDecimal(getRandomNumber(10, 20)), new BigDecimal(getRandomNumber(10, 20)));

		logger.info("sending " + event);
		return MessageBuilder.withPayload(event).build();
	};
}
 
Example 7
@Bean
@InboundChannelAdapter(value = "unsortedChannel", poller = @Poller(fixedDelay = "100"))
public MessageSource<InputStream> unsortedChannelAdapter(Storage gcs) {
	GcsStreamingMessageSource adapter =
			new GcsStreamingMessageSource(new RemoteFileTemplate<>(new GcsSessionFactory(gcs)));
	adapter.setRemoteDirectory("gcsbucket");
	adapter.setFilter(new AcceptOnceFileListFilter<>());

	return adapter;
}
 
Example 8
@Bean
@InboundChannelAdapter(value = "sortedChannel", poller = @Poller(fixedDelay = "100"))
public MessageSource<InputStream> sortedChannelAdapter(Storage gcs) {
	GcsStreamingMessageSource adapter =
			new GcsStreamingMessageSource(
					new RemoteFileTemplate<>(new GcsSessionFactory(gcs)),
					Comparator.comparing(blob -> blob.getName()));

	adapter.setRemoteDirectory("gcsbucket");
	adapter.setFilter(new AcceptOnceFileListFilter<>());

	return adapter;
}
 
Example 9
/**
 * An inbound channel adapter that polls the GCS bucket for new files and copies them to
 * the local filesystem. The resulting message source produces messages containing handles
 * to local files.
 * @param synchronizer an inbound file synchronizer
 * @return a message source
 */
@Bean
@InboundChannelAdapter(channel = "new-file-channel", poller = @Poller(fixedDelay = "5000"))
public MessageSource<File> synchronizerAdapter(GcsInboundFileSynchronizer synchronizer) {
	GcsInboundFileSynchronizingMessageSource syncAdapter = new GcsInboundFileSynchronizingMessageSource(
			synchronizer);
	syncAdapter.setLocalDirectory(Paths.get(this.localDirectory).toFile());

	return syncAdapter;
}
 
Example 10
/**
 * An inbound channel adapter that polls the remote directory and produces messages with
 * {@code InputStream} payload that can be used to read the data from remote files.
 * @param gcs a storage client to use
 * @return a message source
 */
@Bean
@InboundChannelAdapter(channel = "copy-channel", poller = @Poller(fixedDelay = "5000"))
public MessageSource<InputStream> streamingAdapter(Storage gcs) {
	GcsStreamingMessageSource adapter = new GcsStreamingMessageSource(
			new GcsRemoteFileTemplate(new GcsSessionFactory(gcs)));
	adapter.setRemoteDirectory(this.gcsReadBucket);
	return adapter;
}
 
Example 11
@Bean
@InboundChannelAdapter(channel = "pubsubInputChannel", poller = @Poller(fixedDelay = "100"))
public MessageSource<Object> pubsubAdapter(PubSubTemplate pubSubTemplate) {
	PubSubMessageSource messageSource = new PubSubMessageSource(pubSubTemplate,  "exampleSubscription");
	messageSource.setMaxFetchSize(5);
	messageSource.setAckMode(AckMode.MANUAL);
	messageSource.setPayloadType(String.class);
	return messageSource;
}
 
Example 12
@Bean
public MessageSource<Object> jdbcMessageSource() {
	JdbcPollingChannelAdapter jdbcPollingChannelAdapter =
			new JdbcPollingChannelAdapter(this.dataSource, this.properties.getQuery());
	jdbcPollingChannelAdapter.setMaxRowsPerPoll(this.properties.getMaxRowsPerPoll());
	jdbcPollingChannelAdapter.setUpdateSql(this.properties.getUpdate());
	return jdbcPollingChannelAdapter;
}
 
Example 13
@Bean
protected MessageSource<Object> mongoSource() {
    MongoDbMessageSource ms = new MongoDbMessageSource(mongoTemplate, new LiteralExpression(config.getQuery()));
    ms.setCollectionNameExpression(new LiteralExpression(config.getCollection()));
    ms.setEntityClass(String.class);
    return ms;
}
 
Example 14
public void setSource(MessageSource<?> source) {
	ProxyFactory pf = new ProxyFactory(source);
	class ReceiveAdvice implements MethodInterceptor {

		private final List<ChannelInterceptor> interceptors = new ArrayList<>();

		@Override
		public Object invoke(MethodInvocation invocation) throws Throwable {
			Object result = invocation.proceed();
			if (result instanceof Message) {
				Message<?> received = (Message<?>) result;
				for (ChannelInterceptor interceptor : this.interceptors) {
					received = interceptor.preSend(received, dummyChannel);
					if (received == null) {
						return null;
					}
				}
				return received;
			}
			return result;
		}

	}
	final ReceiveAdvice advice = new ReceiveAdvice();
	advice.interceptors.addAll(this.interceptors);
	NameMatchMethodPointcutAdvisor sourceAdvisor = new NameMatchMethodPointcutAdvisor(
			advice);
	sourceAdvisor.addMethodName("receive");
	pf.addAdvisor(sourceAdvisor);
	this.source = (MessageSource<?>) pf.getProxy();
}
 
Example 15
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
	return new MessageSource<String>() {
		@Override
		public Message<String> receive() {
			throw new MessagingException("test");
		}
	};
}
 
Example 16
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "5000", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
	return new MessageSource<String>() {
		@Override
		public Message<String> receive() {
			throw new MessagingException("test");
		}
	};
}
 
Example 17
Source Project: tutorials   Source File: TxIntegrationConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = "inputChannel", poller = @Poller(value = "pollerMetadata"))
public MessageSource<File> fileReadingMessageSource() {
    FileReadingMessageSource sourceReader = new FileReadingMessageSource();
    sourceReader.setDirectory(new File(INPUT_DIR));
    sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
    return sourceReader;
}
 
Example 18
Source Project: tutorials   Source File: FileCopyConfig.java    License: MIT License 5 votes vote down vote up
@Bean
@InboundChannelAdapter(value = "fileChannel", poller = @Poller(fixedDelay = "10000"))
public MessageSource<File> fileReadingMessageSource() {
    FileReadingMessageSource sourceReader = new FileReadingMessageSource();
    sourceReader.setDirectory(new File(INPUT_DIR));
    sourceReader.setFilter(new SimplePatternFileListFilter(FILE_PATTERN));
    return sourceReader;
}
 
Example 19
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
public MessageSource<Long> timeMessageSource() {
	return () -> MessageBuilder.withPayload(new Date().getTime()).build();
}
 
Example 20
Source Project: Mastering-Spring-Cloud   Source File: OrderApplication.java    License: MIT License 4 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "1000", maxMessagesPerPoll = "1"))
public MessageSource<Order> ordersSource() {
	Random r = new Random();
	return () -> new GenericMessage<>(new Order(OrderStatus.NEW, (long) r.nextInt(5), Collections.singletonList((long) r.nextInt(10))));
}
 
Example 21
Source Project: schema-evolution-samples   Source File: SensorSource.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
public MessageSource<Sensor> timeSensorSource(){
	return () -> new GenericMessage<Sensor>(randomSensor());
}
 
Example 22
Source Project: schema-evolution-samples   Source File: SensorSource.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
public MessageSource<Sensor> timeSensorSource(){
	return () -> new GenericMessage<Sensor>(randomSensor());
}
 
Example 23
Source Project: spring-bus   Source File: ModuleDefinition.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
@InboundChannelAdapter(value = "output", autoStartup = "false", poller = @Poller(fixedDelay = "${fixedDelay}", maxMessagesPerPoll = "1"))
public MessageSource<String> timerMessageSource() {
	return () -> new GenericMessage<>(new SimpleDateFormat(format).format(new Date()));
}
 
Example 24
@Override
public Binding<PollableSource<MessageHandler>> bindPollableConsumer(String name,
		String group, final PollableSource<MessageHandler> inboundBindTarget,
		C properties) {
	Assert.isInstanceOf(DefaultPollableMessageSource.class, inboundBindTarget);
	DefaultPollableMessageSource bindingTarget = (DefaultPollableMessageSource) inboundBindTarget;
	ConsumerDestination destination = this.provisioningProvider
			.provisionConsumerDestination(name, group, properties);
	if (HeaderMode.embeddedHeaders.equals(properties.getHeaderMode())) {
		bindingTarget.addInterceptor(0, this.embeddedHeadersChannelInterceptor);
	}
	final PolledConsumerResources resources = createPolledConsumerResources(name,
			group, destination, properties);

	MessageSource<?> messageSource = resources.getSource();
	if (messageSource instanceof BeanFactoryAware) {
		((BeanFactoryAware) messageSource).setBeanFactory(getApplicationContext().getBeanFactory());
	}
	bindingTarget.setSource(messageSource);
	if (resources.getErrorInfrastructure() != null) {
		if (resources.getErrorInfrastructure().getErrorChannel() != null) {
			bindingTarget.setErrorChannel(
					resources.getErrorInfrastructure().getErrorChannel());
		}
		ErrorMessageStrategy ems = getErrorMessageStrategy();
		if (ems != null) {
			bindingTarget.setErrorMessageStrategy(ems);
		}
	}
	if (properties.getMaxAttempts() > 1) {
		bindingTarget.setRetryTemplate(buildRetryTemplate(properties));
		bindingTarget.setRecoveryCallback(getPolledConsumerRecoveryCallback(
				resources.getErrorInfrastructure(), properties));
	}
	postProcessPollableSource(bindingTarget);
	if (properties.isAutoStartup() && resources.getSource() instanceof Lifecycle) {
		((Lifecycle) resources.getSource()).start();
	}
	Binding<PollableSource<MessageHandler>> binding = new DefaultBinding<PollableSource<MessageHandler>>(
			name, group, inboundBindTarget, resources.getSource() instanceof Lifecycle
					? (Lifecycle) resources.getSource() : null) {

		@Override
		public Map<String, Object> getExtendedInfo() {
			return doGetExtendedInfo(destination, properties);
		}

		@Override
		public boolean isInput() {
			return true;
		}

		@Override
		public void afterUnbind() {
			afterUnbindConsumer(destination, this.group, properties);
			destroyErrorInfrastructure(destination, this.group, properties);
		}

	};

	doPublishEvent(new BindingCreatedEvent(binding));
	return binding;
}
 
Example 25
public PolledConsumerResources(MessageSource<?> source,
		ErrorInfrastructure errorInfrastructure) {
	this.source = source;
	this.errorInfrastructure = errorInfrastructure;
}
 
Example 26
MessageSource<?> getSource() {
	return this.source;
}
 
Example 27
Source Project: spring-cloud-stream   Source File: PollableConsumerTests.java    License: Apache License 2.0 4 votes vote down vote up
public LifecycleMessageSource(MessageSource<T> delegate) {
	this.delegate = delegate;
}
 
Example 28
Source Project: spring-cloud-stream   Source File: TestChannelBinder.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Set a delegate {@link MessageSource} for pollable consumers.
 * @param messageSourceDelegate the delegate.
 */
@Autowired(required = false)
public void setMessageSourceDelegate(MessageSource<byte[]> messageSourceDelegate) {
	this.messageSourceDelegate = messageSourceDelegate;
}
 
Example 29
Source Project: tutorials   Source File: TimeSourceApplication.java    License: MIT License 4 votes vote down vote up
@Bean
@InboundChannelAdapter(value = Source.OUTPUT, poller = @Poller(fixedDelay = "10000", maxMessagesPerPoll = "1"))
public MessageSource<Long> timeMessageSource() {

    return () -> MessageBuilder.withPayload(new Date().getTime()).build();
}
 
Example 30
Source Project: tutorials   Source File: JavaDSLFileCopyConfig.java    License: MIT License 4 votes vote down vote up
@Bean
public MessageSource<File> sourceDirectory() {
    FileReadingMessageSource messageSource = new FileReadingMessageSource();
    messageSource.setDirectory(new File(INPUT_DIR));
    return messageSource;
}