cherry-pick freeman Add rocketmq example

pull/2570/head
Freeman Lau 3 years ago committed by sorie
parent e611224fa3
commit cfc15d8cbd

@ -23,11 +23,13 @@
<module>sentinel-example/sentinel-dubbo-example/sentinel-dubbo-api</module>
<module>sentinel-example/sentinel-feign-example/sentinel-feign-consumer-example</module>
<module>sentinel-example/sentinel-feign-example/sentinel-feign-provider-example</module>
<module>sentinel-example/sentinel-circuitbreaker-example</module>
<module>sentinel-example/sentinel-webflux-example</module>
<module>sentinel-example/sentinel-spring-cloud-gateway-example</module>
<module>sentinel-example/sentinel-zuul-example</module>
<module>nacos-example/nacos-discovery-example</module>
<module>nacos-example/nacos-config-example</module>
<module>nacos-example/nacos-config-2.4.x-example</module>
<module>nacos-example/nacos-gateway-example</module>
<module>seata-example/business-service</module>
<module>seata-example/order-service</module>

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-examples</artifactId>
<version>${revision}</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>rocketmq-comprehensive-example</artifactId>
<name>Spring Cloud Starter Stream Alibaba RocketMQ Comprehensive Example</name>
<description>Example demonstrating how to use rocketmq to produce, process and consume</description>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<version>${maven-deploy-plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>

@ -0,0 +1,73 @@
/*
* Copyright 2013-2022 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
*
* https://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 com.alibaba.cloud.examples;
import java.time.Duration;
import java.util.Arrays;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Flux;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.integration.support.StringObjectMapBuilder;
/**
* @author freeman
*/
@SpringBootApplication
public class RocketMQComprehensiveApplication {
private static final Logger log = LoggerFactory
.getLogger(RocketMQComprehensiveApplication.class);
public static void main(String[] args) {
SpringApplication.run(RocketMQComprehensiveApplication.class, args);
}
@Bean
public Supplier<Flux<User>> producer() {
return () -> Flux.interval(Duration.ofSeconds(2)).map(id -> {
User user = new User();
user.setId(id.toString());
user.setName("freeman");
user.setMeta(new StringObjectMapBuilder()
.put("hobbies", Arrays.asList("movies", "songs")).put("age", 21)
.get());
return user;
}).log();
}
@Bean
public Function<Flux<User>, Flux<User>> processor() {
return flux -> flux.map(user -> {
user.setId(String.valueOf(
Long.parseLong(user.getId()) * Long.parseLong(user.getId())));
return user;
});
}
@Bean
public Consumer<User> consumer() {
return num -> log.info(num.toString());
}
}

@ -0,0 +1,58 @@
/*
* Copyright 2013-2022 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
*
* https://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 com.alibaba.cloud.examples;
import java.util.Map;
/**
* @author freeman
*/
public class User {
private String id;
private String name;
private Map<String, Object> meta;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Map<String, Object> getMeta() {
return meta;
}
public void setMeta(Map<String, Object> meta) {
this.meta = meta;
}
@Override
public String toString() {
return "User{" + "id='" + id + '\'' + ", name='" + name + '\'' + ", meta=" + meta
+ '}';
}
}

@ -0,0 +1,28 @@
server:
port: 28082
spring:
application:
name: rocketmq-comprehensive-example
cloud:
stream:
rocketmq:
binder:
name-server: 127.0.0.1:9876
function:
definition: producer;processor;consumer
bindings:
producer-out-0:
destination: num
group: producer_group
processor-in-0:
destination: num
group: processor_group
processor-out-0:
destination: square
group: processor_group
consumer-in-0:
destination: square
group: consumer_group
logging:
level:
org.apache.rocketmq: debug
Loading…
Cancel
Save