Java Code Examples for org.springframework.cloud.stream.binder.PollableMessageSource

The following examples show how to use org.springframework.cloud.stream.binder.PollableMessageSource. 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
@Bean
public ApplicationRunner runner(PollableMessageSource input, MessageChannel output) {
	return args -> {
		System.out.println("Send some messages to topic polledConsumerIn and receive from polledConsumerOut");
		System.out.println("Messages will be processed one per second");
		exec.execute(() -> {
			boolean result = false;
			while (true) {
				// this is where we poll for a message, process it, and send a new one
				result = input.poll(m -> {
					String payload = (String) m.getPayload();
					System.out.println("Received: " + payload);
					output.send(MessageBuilder.withPayload(payload.toUpperCase())
						.copyHeaders(m.getHeaders())
						.build());
				}, new ParameterizedTypeReference<String>() { });

				try {
					Thread.sleep(1_000);
				}
				catch (InterruptedException e) {
					Thread.currentThread().interrupt();
					break;
				}
				if (result) {
					System.out.println("Success");
				}
			}
		});
	};
}
 
Example 2
@Override
public void configurePolledMessageSource(PollableMessageSource binding, String name) {
	this.messageChannelConfigurers.forEach(cconfigurer -> {
		if (cconfigurer instanceof MessageChannelAndSourceConfigurer) {
			((MessageChannelAndSourceConfigurer) cconfigurer)
					.configurePolledMessageSource(binding, name);
		}
	});
}
 
Example 3
public MessageSourceBindingTargetFactory(SmartMessageConverter messageConverter,
		MessageChannelConfigurer messageSourceConfigurer) {
	super(PollableMessageSource.class);
	Assert.isInstanceOf(MessageChannelAndSourceConfigurer.class,
			messageSourceConfigurer);
	this.messageSourceConfigurer = (MessageChannelAndSourceConfigurer) messageSourceConfigurer;
	this.messageConverter = messageConverter;
}
 
Example 4
@Override
public PollableMessageSource createInput(String name) {
	DefaultPollableMessageSource binding = new DefaultPollableMessageSource(
			this.messageConverter);
	this.messageSourceConfigurer.configurePolledMessageSource(binding, name);
	return binding;
}
 
Example 5
@Override
public void configurePolledMessageSource(PollableMessageSource binding, String name) {
	BindingProperties bindingProperties = this.bindingServiceProperties
			.getBindingProperties(name);
	String contentType = bindingProperties.getContentType();
	ConsumerProperties consumerProperties = bindingProperties.getConsumer();
	if ((consumerProperties == null || !consumerProperties.isUseNativeDecoding())
			&& binding instanceof DefaultPollableMessageSource) {
		((DefaultPollableMessageSource) binding).addInterceptor(
				new InboundContentTypeEnhancingInterceptor(contentType));
	}
}
 
Example 6
Source Project: hello-spring-cloud-alibaba   Source File: MySink.java    License: MIT License 4 votes vote down vote up
@Input("input5")
PollableMessageSource input5();
 
Example 7
@Input("input5")
PollableMessageSource input5();
 
Example 8
Source Project: spring-cloud-gcp   Source File: PollableSink.java    License: Apache License 2.0 4 votes vote down vote up
@Input("input")
PollableMessageSource input();
 
Example 9
@Input
PollableMessageSource source();
 
Example 10
@Input
PollableMessageSource input();
 
Example 11
@Input
PollableMessageSource source();
 
Example 12
@Override
public PollableMessageSource createOutput(String name) {
	throw new UnsupportedOperationException();
}
 
Example 13
Source Project: spring-cloud-stream   Source File: SampleStreamApp.java    License: Apache License 2.0 4 votes vote down vote up
@Bean
public ApplicationRunner runner(PollableMessageSource pollableSource) {
	return args -> pollableSource.poll(message -> {
		System.out.println("Polled payload: " + message.getPayload());
	});
}
 
Example 14
Source Project: spring-cloud-stream   Source File: SampleStreamApp.java    License: Apache License 2.0 4 votes vote down vote up
@Input
PollableMessageSource pollableSource();
 
Example 15
/**
 * Configure the provided message source binding.
 * @param binding the binding.
 * @param name the name.
 */
void configurePolledMessageSource(PollableMessageSource binding, String name);