Move samples from spring-cloud-stream
This commit is contained in:
committed by
Marius Bogoevici
parent
f7ae1a8201
commit
07991ce344
33
rxjava-processor/src/main/java/demo/RxJavaApplication.java
Normal file
33
rxjava-processor/src/main/java/demo/RxJavaApplication.java
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package demo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
* @author Ilayaperumal Gopinathan
|
||||
*/
|
||||
@SpringBootApplication
|
||||
public class RxJavaApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(RxJavaApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
51
rxjava-processor/src/main/java/demo/RxJavaTransformer.java
Normal file
51
rxjava-processor/src/main/java/demo/RxJavaTransformer.java
Normal file
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package demo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.cloud.stream.annotation.rxjava.EnableRxJavaProcessor;
|
||||
import org.springframework.cloud.stream.annotation.rxjava.RxJavaProcessor;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
@EnableRxJavaProcessor
|
||||
public class RxJavaTransformer {
|
||||
|
||||
private static Logger logger = LoggerFactory.getLogger(RxJavaTransformer.class);
|
||||
|
||||
@Bean
|
||||
public RxJavaProcessor<String,String> processor() {
|
||||
return inputStream -> inputStream.map(data -> {
|
||||
logger.info("Got data = " + data);
|
||||
return data;
|
||||
}).buffer(5).map(data -> String.valueOf(avg(data)));
|
||||
}
|
||||
|
||||
private static Double avg(List<String> data) {
|
||||
double sum = 0;
|
||||
double count = 0;
|
||||
for(String d : data) {
|
||||
count++;
|
||||
sum += Double.valueOf(d);
|
||||
}
|
||||
return sum/count;
|
||||
}
|
||||
|
||||
}
|
||||
8
rxjava-processor/src/main/resources/application.yml
Normal file
8
rxjava-processor/src/main/resources/application.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
server:
|
||||
port: 8082
|
||||
spring:
|
||||
cloud:
|
||||
stream:
|
||||
bindings:
|
||||
output: xformed
|
||||
input: testtock
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package demo;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.context.web.WebAppConfiguration;
|
||||
import org.springframework.boot.test.SpringApplicationConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@SpringApplicationConfiguration(classes = RxJavaApplication.class)
|
||||
@WebAppConfiguration
|
||||
@DirtiesContext
|
||||
public class ModuleApplicationTests {
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user