Merge pull request #2406 from DanielLiu1123/upgrade_rocketmq_4.9.2

Upgrade rocketmq 4.9.2
pull/2407/head
Freeman Lau 3 years ago committed by GitHub
commit 713c32a094
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -90,7 +90,7 @@
<curator.version>4.0.1</curator.version>
<!-- Apache RocketMQ -->
<rocketmq.version>4.6.1</rocketmq.version>
<rocketmq.version>4.9.2</rocketmq.version>
<!-- Maven Plugin Versions -->
<maven-compiler-plugin.version>3.8.1</maven-compiler-plugin.version>

@ -40,6 +40,7 @@
<module>seata-example/account-service</module>
<module>rocketmq-example/rocketmq-consume-example</module>
<module>rocketmq-example/rocketmq-produce-example</module>
<module>rocketmq-example/rocketmq-comprehensive-example</module>
<module>spring-cloud-bus-rocketmq-example</module>
<module>spring-cloud-alibaba-dubbo-examples</module>
<module>spring-cloud-alibaba-sidecar-examples/spring-cloud-alibaba-sidecar-nacos-example</module>

@ -0,0 +1,52 @@
<?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-actuator</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,75 @@
/*
* 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())));
user.setName("not freeman");
user.getMeta().put("hobbies", Arrays.asList("programming"));
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,36 @@
server:
port: 28082
spring:
application:
name: rocketmq-comprehensive-example
cloud:
stream:
function:
definition: producer;consumer;processor
rocketmq:
binder:
name-server: 127.0.0.1:9876
bindings:
# TODO producer must have a group, need optimization !!!
producer-out-0:
producer:
group: output_1
processor-out-0:
producer:
group: output_2
bindings:
producer-out-0:
destination: num
processor-out-0:
destination: square
processor-in-0:
destination: num
group: processor_group
consumer-in-0:
destination: square
group: consumer_group
logging:
level:
org.springframework.context.support: debug

@ -24,24 +24,6 @@
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-actuator-autoconfigure</artifactId>
@ -56,18 +38,13 @@
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

@ -48,7 +48,7 @@ public class ExtendedBindingHandlerMappingsProviderConfiguration {
}
@Bean
public RocketMQConfigBeanPostProcessor rocketMQConfigBeanPostProcessor() {
public static RocketMQConfigBeanPostProcessor rocketMQConfigBeanPostProcessor() {
return new RocketMQConfigBeanPostProcessor();
}

@ -24,6 +24,7 @@ import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvis
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.actuate.autoconfigure.health.ConditionalOnEnabledHealthIndicator;
import org.springframework.boot.actuate.health.HealthIndicator;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
@ -46,13 +47,6 @@ public class RocketMQBinderAutoConfiguration {
@Autowired
private RocketMQBinderConfigurationProperties rocketBinderConfigurationProperties;
@Bean
@ConditionalOnEnabledHealthIndicator("rocketmq")
@ConditionalOnClass(name = "org.springframework.boot.actuate.health.HealthIndicator")
public RocketMQBinderHealthIndicator rocketMQBinderHealthIndicator() {
return new RocketMQBinderHealthIndicator();
}
@Bean
public RocketMQTopicProvisioner rocketMQTopicProvisioner() {
return new RocketMQTopicProvisioner();
@ -65,4 +59,16 @@ public class RocketMQBinderAutoConfiguration {
extendedBindingProperties, provisioningProvider);
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass(HealthIndicator.class)
@ConditionalOnEnabledHealthIndicator("rocketmq")
static class KafkaBinderHealthIndicatorConfiguration {
@Bean
public RocketMQBinderHealthIndicator rocketMQBinderHealthIndicator() {
return new RocketMQBinderHealthIndicator();
}
}
}

@ -33,7 +33,7 @@ import org.springframework.messaging.converter.CompositeMessageConverter;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.CollectionUtils;
import org.springframework.util.MimeTypeUtils;
import org.springframework.util.StringUtils;
import org.springframework.util.ObjectUtils;
/**
* @author zkzlx
@ -138,13 +138,13 @@ public final class RocketMQMessageConverterSupport {
if (Objects.nonNull(headers) && !headers.isEmpty()) {
Object tag = headers.getOrDefault(Headers.TAGS,
headers.get(toRocketHeaderKey(Headers.TAGS)));
if (StringUtils.hasLength(tag.toString())) {
if (!ObjectUtils.isEmpty(tag)) {
rocketMsg.setTags(String.valueOf(tag));
}
Object keys = headers.getOrDefault(Headers.KEYS,
headers.get(toRocketHeaderKey(Headers.KEYS)));
if (StringUtils.hasLength(keys.toString())) {
if (!ObjectUtils.isEmpty(keys)) {
rocketMsg.setKeys(keys.toString());
}
Object flagObj = headers.getOrDefault(Headers.FLAG,

@ -19,7 +19,7 @@ package com.alibaba.cloud.stream.binder.rocketmq;
import com.alibaba.cloud.stream.binder.rocketmq.autoconfigurate.RocketMQBinderAutoConfiguration;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQBinderConfigurationProperties;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindingProperties;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;

Loading…
Cancel
Save