org.springframework.integration.core.MessageSource Java Examples

The following examples show how to use org.springframework.integration.core.MessageSource. 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: DataProducer.java    From spring-cloud with Apache License 2.0 6 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 File: FileCopyConfig.java    From tutorials with 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 #3
Source File: TxIntegrationConfig.java    From tutorials with 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 #4
Source File: CustomPartitionedProducerTest.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@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 #5
Source File: CustomPartitionedProducerTest.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@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 #6
Source File: DefaultPollableMessageSource.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: MongodbSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@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 #8
Source File: JdbcSourceConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@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 #9
Source File: PollingReceiverApplication.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@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 #10
Source File: GcsSpringIntegrationApplication.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * 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
Source File: GcsStreamingMessageSourceTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@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 #12
Source File: GcsStreamingMessageSourceTests.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
@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 #13
Source File: GcsSpringIntegrationApplication.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * 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 #14
Source File: SampleSource.java    From spring-cloud with 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 #15
Source File: SignificantStockChangeSourceApplication.java    From Mastering-Spring-5.0 with MIT License 5 votes vote down vote up
@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 #16
Source File: SftpConfig.java    From java-examples with 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 #17
Source File: SampleSource.java    From spring-cloud with 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 #18
Source File: DemoApplication.java    From activiti-examples with 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 #19
Source File: SimpleTimeSourceApplication.java    From rocketmq-binder-demo with Apache License 2.0 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 #20
Source File: JavaDSLFileCopyConfig.java    From tutorials with 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;
}
 
Example #21
Source File: TimeSourceApplication.java    From tutorials with 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 #22
Source File: TestChannelBinder.java    From spring-cloud-stream with 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 #23
Source File: PollableConsumerTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
public LifecycleMessageSource(MessageSource<T> delegate) {
	this.delegate = delegate;
}
 
Example #24
Source File: AbstractMessageChannelBinder.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
MessageSource<?> getSource() {
	return this.source;
}
 
Example #25
Source File: AbstractMessageChannelBinder.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
public PolledConsumerResources(MessageSource<?> source,
		ErrorInfrastructure errorInfrastructure) {
	this.source = source;
	this.errorInfrastructure = errorInfrastructure;
}
 
Example #26
Source File: AbstractMessageChannelBinder.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@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 #27
Source File: OrderApplication.java    From Mastering-Spring-Cloud with 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 #28
Source File: ModuleDefinition.java    From spring-bus with 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 #29
Source File: SensorSource.java    From schema-evolution-samples with 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 #30
Source File: SensorSource.java    From schema-evolution-samples with 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());
}