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

The following examples show how to use org.springframework.cloud.stream.binder.PollableMessageSource. 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: PolledConsumerApplication.java    From spring-cloud-stream-samples with Apache License 2.0 5 votes vote down vote up
@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
Source File: CompositeMessageChannelConfigurer.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
public void configurePolledMessageSource(PollableMessageSource binding, String name) {
	this.messageChannelConfigurers.forEach(cconfigurer -> {
		if (cconfigurer instanceof MessageChannelAndSourceConfigurer) {
			((MessageChannelAndSourceConfigurer) cconfigurer)
					.configurePolledMessageSource(binding, name);
		}
	});
}
 
Example #3
Source File: MessageSourceBindingTargetFactory.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
public MessageSourceBindingTargetFactory(SmartMessageConverter messageConverter,
		MessageChannelConfigurer messageSourceConfigurer) {
	super(PollableMessageSource.class);
	Assert.isInstanceOf(MessageChannelAndSourceConfigurer.class,
			messageSourceConfigurer);
	this.messageSourceConfigurer = (MessageChannelAndSourceConfigurer) messageSourceConfigurer;
	this.messageConverter = messageConverter;
}
 
Example #4
Source File: MessageSourceBindingTargetFactory.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@Override
public PollableMessageSource createInput(String name) {
	DefaultPollableMessageSource binding = new DefaultPollableMessageSource(
			this.messageConverter);
	this.messageSourceConfigurer.configurePolledMessageSource(binding, name);
	return binding;
}
 
Example #5
Source File: MessageConverterConfigurer.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@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 File: MySink.java    From hello-spring-cloud-alibaba with MIT License 4 votes vote down vote up
@Input("input5")
PollableMessageSource input5();
 
Example #7
Source File: RocketMQConsumerApplication.java    From spring-cloud-alibaba with Apache License 2.0 4 votes vote down vote up
@Input("input5")
PollableMessageSource input5();
 
Example #8
Source File: PollableSink.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
@Input("input")
PollableMessageSource input();
 
Example #9
Source File: KafkaBinderActuatorTests.java    From spring-cloud-stream-binder-kafka with Apache License 2.0 4 votes vote down vote up
@Input
PollableMessageSource source();
 
Example #10
Source File: PolledConsumerApplication.java    From spring-cloud-stream-samples with Apache License 2.0 4 votes vote down vote up
@Input
PollableMessageSource input();
 
Example #11
Source File: RabbitBinderModuleTests.java    From spring-cloud-stream-binder-rabbit with Apache License 2.0 4 votes vote down vote up
@Input
PollableMessageSource source();
 
Example #12
Source File: MessageSourceBindingTargetFactory.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Override
public PollableMessageSource createOutput(String name) {
	throw new UnsupportedOperationException();
}
 
Example #13
Source File: SampleStreamApp.java    From spring-cloud-stream with 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 File: SampleStreamApp.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@Input
PollableMessageSource pollableSource();
 
Example #15
Source File: MessageChannelAndSourceConfigurer.java    From spring-cloud-stream with Apache License 2.0 2 votes vote down vote up
/**
 * Configure the provided message source binding.
 * @param binding the binding.
 * @param name the name.
 */
void configurePolledMessageSource(PollableMessageSource binding, String name);