Java Code Examples for org.springframework.cloud.stream.messaging.Processor#OUTPUT

The following examples show how to use org.springframework.cloud.stream.messaging.Processor#OUTPUT . 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: DefaultStatisticService.java    From Hands-On-Reactive-Programming-in-Spring-5 with MIT License 5 votes vote down vote up
@Override
@StreamListener(Processor.INPUT)
@Output(Processor.OUTPUT)
public Flux<UsersStatisticVM> updateStatistic(Flux<MessageResponse> messagesFlux) {
    return messagesFlux.map(MessageMapper::toDomainUnit)
                       .transform(messageRepository::saveAll)
                       .retryBackoff(Long.MAX_VALUE, Duration.ofMillis(500))
                       .onBackpressureLatest()
                       .concatMap(e -> this.doGetUserStatistic(), 1)
                       .onErrorContinue((t, e) -> {});
}
 
Example 2
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Person echo(Object value) throws Exception {
	ObjectMapper mapper = new ObjectMapper();
	// assume it is string because CT is text/plain
	return mapper.readValue((String) value, Person.class);
}
 
Example 3
Source File: CommentService.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Comment> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
	return repository
		.saveAll(newComment)
		.map(comment -> {
			meterRegistry
				.counter("comments.consumed", "imageId", comment.getImageId())
				.increment();
			return comment;
		});
}
 
Example 4
Source File: StreamListenerHandlerMethodTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener
@Output(StreamListenerTestUtils.FooOutboundChannel1.OUTPUT)
public void receive(@Input(Processor.INPUT) SubscribableChannel input,
		@Output(Processor.OUTPUT) final MessageChannel output1) {
	input.subscribe(new MessageHandler() {
		@Override
		public void handleMessage(Message<?> message) throws MessagingException {
			output1.send(org.springframework.messaging.support.MessageBuilder
					.withPayload(message.getPayload().toString().toUpperCase())
					.build());
		}
	});
}
 
Example 5
Source File: StreamListenerHandlerBeanTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener(Processor.INPUT)
@Output(Processor.OUTPUT)
public StreamListenerTestUtils.BarPojo receive(
		StreamListenerTestUtils.FooPojo fooMessage) {
	this.receivedPojos.add(fooMessage);
	StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
	barPojo.setBar(fooMessage.getFoo());
	return barPojo;
}
 
Example 6
Source File: StreamListenerWithAnnotatedInputOutputArgsTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener
public void receive(@Input("invalid") SubscribableChannel input,
		@Output(Processor.OUTPUT) final MessageChannel output) {
	input.subscribe(new MessageHandler() {
		@Override
		public void handleMessage(Message<?> message) throws MessagingException {
			output.send(MessageBuilder
					.withPayload(message.getPayload().toString().toUpperCase())
					.build());
		}
	});
}
 
Example 7
Source File: StreamListenerMethodWithReturnMessageTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener(Processor.INPUT)
@Output(Processor.OUTPUT)
public Message<?> receive(StreamListenerTestUtils.FooPojo fooPojo) {
	this.receivedPojos.add(fooPojo);
	StreamListenerTestUtils.BarPojo bazPojo = new StreamListenerTestUtils.BarPojo();
	bazPojo.setBar(fooPojo.getFoo());
	return MessageBuilder.withPayload(bazPojo).setHeader("foo", "bar").build();
}
 
Example 8
Source File: CommentService.java    From Learning-Spring-Boot-2.0-Second-Edition with MIT License 5 votes vote down vote up
@StreamListener
@Output(Processor.OUTPUT)
public Flux<Void> save(@Input(Processor.INPUT) Flux<Comment> newComment) {
	return repository
		.saveAll(newComment)
		.flatMap(comment -> {
			meterRegistry
				.counter("comments.consumed", "imageId", comment.getImageId())
				.increment();
			return Mono.empty();
		});
}
 
Example 9
Source File: TensorflowProcessorConfiguration.java    From tensorflow-spring-cloud-stream-app-starters with Apache License 2.0 5 votes vote down vote up
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Message<?> evaluate(Message<?> input) {

	Map<String, Object> processorContext = new ConcurrentHashMap<>();

	Map<String, Object> inputData = tensorflowInputConverter.convert(input, processorContext);

	Tensor outputTensor = tensorFlowService.evaluate(
			inputData, properties.getOutputName(), properties.getOutputIndex());

	Object outputData = tensorflowOutputConverter.convert(outputTensor, processorContext);

	if (properties.isSaveOutputInHeader()) {
		// Add the result to the message header
		return MessageBuilder
				.withPayload(input.getPayload())
				.copyHeadersIfAbsent(input.getHeaders())
				.setHeaderIfAbsent(TF_OUTPUT_HEADER, outputData)
				.build();
	}

	// Add the outputData as part of the message payload
	Message<?> outputMessage = MessageBuilder
			.withPayload(outputData)
			.copyHeadersIfAbsent(input.getHeaders())
			.build();

	return outputMessage;
}
 
Example 10
Source File: StreamListenerMessageArgumentTests.java    From spring-cloud-stream with Apache License 2.0 5 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public StreamListenerTestUtils.BarPojo receive(Message<String> fooMessage) {
	this.receivedMessages.add(fooMessage);
	StreamListenerTestUtils.BarPojo barPojo = new StreamListenerTestUtils.BarPojo();
	barPojo.setBar(fooMessage.getPayload());
	return barPojo;
}
 
Example 11
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener("internalChannel")
@SendTo(Processor.OUTPUT)
public String handleB(Person value) {
	return value.toString();
}
 
Example 12
Source File: StreamListenerDuplicateMappingTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public String receiveDuplicateMapping(Message<String> fooMessage) {
	return null;
}
 
Example 13
Source File: StockIntelligenceProcessorApplication.java    From Mastering-Spring-5.0 with MIT License 4 votes vote down vote up
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object addOurInventory(StockPriceChangeEvent event) {

	logger.info("started processing event " + event);
	
	logger.info("received stock ticker " + event.getStockTicker());
	
	logger.info("received stock ticker and mapped to " + StockTicker.valueOf(event.getStockTicker()));

	Integer holding = holdings.get(StockTicker.valueOf(event.getStockTicker()));
	
	logger.info("holding value is  " + holding);
	
	StockPriceChangeEventWithHoldings eventWithHoldings = new StockPriceChangeEventWithHoldings(event, holding);

	logger.info("ended processing eventWithHoldings " + eventWithHoldings);
	return eventWithHoldings;
}
 
Example 14
Source File: GroovyTransformProcessorConfiguration.java    From spring-cloud-stream-app-starters with Apache License 2.0 4 votes vote down vote up
@Bean
@Transformer(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public MessageProcessor<?> transformer() {
	return new GroovyScriptExecutingMessageProcessor(
			new ResourceScriptSource(properties.getScript()), scriptVariableGenerator);
}
 
Example 15
Source File: AccountApplication.java    From Mastering-Spring-Cloud with MIT License 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Order receiveAndSendOrder(Order order) throws JsonProcessingException {
	LOGGER.info("Order received: {}", mapper.writeValueAsString(order));
	return service.process(order);
}
 
Example 16
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Map<?, ?> echo(MessageHeaders value) throws Exception {
	return value;
}
 
Example 17
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT)
public Object echo(Object value) throws Exception {
	System.out.println(value);
	return value;
}
 
Example 18
Source File: ContentTypeTckTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public Person echo(byte[] value) throws Exception {
	ObjectMapper mapper = new ObjectMapper();
	return mapper.readValue(value, Person.class);
}
 
Example 19
Source File: StreamListenerDuplicateMappingTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public String receive(Message<String> fooMessage) {
	return null;
}
 
Example 20
Source File: StreamListenerHandlerMethodTests.java    From spring-cloud-stream with Apache License 2.0 4 votes vote down vote up
@StreamListener(Processor.INPUT)
@SendTo(Processor.OUTPUT)
public String receive(Object received) {
	return received.toString().toUpperCase();
}