Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: add relevant hints of RocketMQ starter #3371

Merged
merged 2 commits into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@

<properties>
<!-- Project revision -->
<revision>2022.0.0.0-RC2</revision>
<revision>2022.0.0.0</revision>

<!-- Spring Cloud -->
<spring.cloud.version>2022.0.0</spring.cloud.version>
Expand Down
2 changes: 1 addition & 1 deletion spring-cloud-alibaba-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<description>Spring Cloud Alibaba Dependencies</description>

<properties>
<revision>2022.0.0.0-RC2</revision>
<revision>2022.0.0.0</revision>
<sentinel.version>1.8.6</sentinel.version>
<seata.version>1.7.0-native-rc2</seata.version>
<nacos.client.version>2.2.1</nacos.client.version>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,18 @@
<dependency>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-acl</artifactId>
<exclusions>
<exclusion>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.22</version>
</dependency>

<!-- Testing -->
<dependency>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright 2013-2023 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.stream.binder.rocketmq.aot.hint;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties;

import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.util.ReflectionUtils;

/**
* @author ChengPu raozihao
*/
public class RocketMQConsumerPropertiesHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
Constructor<RocketMQConsumerProperties> constructor;
try {
constructor = RocketMQConsumerProperties.class.getConstructor();
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
hints.reflection().registerConstructor(constructor, ExecutableMode.INVOKE);
// setMessageModel
Method setMessageModel = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "setMessageModel", String.class);
hints.reflection().registerMethod(setMessageModel, ExecutableMode.INVOKE);
// getPush
Method getPush = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "getPush");
hints.reflection().registerMethod(getPush, ExecutableMode.INVOKE);
// setSubscription
Method setSubscription = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "setSubscription", String.class);
hints.reflection().registerMethod(setSubscription, ExecutableMode.INVOKE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2013-2023 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.stream.binder.rocketmq.aot.hint;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQSpecificPropertiesProvider;

import org.springframework.aot.hint.ExecutableMode;
import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.RuntimeHintsRegistrar;
import org.springframework.util.ReflectionUtils;

/**
* @author ChengPu raozihao
*/
public class RocketMQSpecificPropertiesProviderHints implements RuntimeHintsRegistrar {

@Override
public void registerHints(RuntimeHints hints, ClassLoader classLoader) {
Constructor<RocketMQSpecificPropertiesProvider> constructor;
try {
constructor = RocketMQSpecificPropertiesProvider.class.getConstructor();
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
hints.reflection().registerConstructor(constructor, ExecutableMode.INVOKE);
// getConsumer
Method getConsumer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "getConsumer");
hints.reflection().registerMethod(getConsumer, ExecutableMode.INVOKE);
// setConsumer
Method setConsumer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "setConsumer", RocketMQConsumerProperties.class);
hints.reflection().registerMethod(setConsumer, ExecutableMode.INVOKE);
// getProducer
Method getProducer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "getProducer");
hints.reflection().registerMethod(getProducer, ExecutableMode.INVOKE);
// setProducer
Method setProducer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "setProducer", RocketMQProducerProperties.class);
hints.reflection().registerMethod(setProducer, ExecutableMode.INVOKE);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
org.springframework.aot.hint.RuntimeHintsRegistrar=\
com.alibaba.cloud.stream.binder.rocketmq.aot.hint.RocketMQSpecificPropertiesProviderHints,\
com.alibaba.cloud.stream.binder.rocketmq.aot.hint.RocketMQConsumerPropertiesHints
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright 2013-2023 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.stream.binder.rocketmq.aot.hint;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties;
import org.junit.jupiter.api.Test;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.util.ReflectionUtils;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author ChengPu raozihao
*/
public class RocketMQConsumerPropertiesHintsTests {

@Test
public void shouldRegisterHints() {
Constructor<RocketMQConsumerProperties> constructor;
try {
constructor = RocketMQConsumerProperties.class.getConstructor();
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
Method setMessageModel = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "setMessageModel", String.class);
Method getPush = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "getPush");
Method setSubscription = ReflectionUtils.findMethod(RocketMQConsumerProperties.class, "setSubscription", String.class);
RuntimeHints hints = new RuntimeHints();
new RocketMQConsumerPropertiesHints().registerHints(hints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onConstructor(constructor)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(setMessageModel)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(getPush)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(setSubscription)).accepts(hints);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2013-2023 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.stream.binder.rocketmq.aot.hint;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;

import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQSpecificPropertiesProvider;
import org.junit.jupiter.api.Test;

import org.springframework.aot.hint.RuntimeHints;
import org.springframework.aot.hint.predicate.RuntimeHintsPredicates;
import org.springframework.util.ReflectionUtils;

import static org.assertj.core.api.Assertions.assertThat;

/**
* @author ChengPu raozihao
*/
public class RocketMQSpecificPropertiesProviderHintsTests {

@Test
public void shouldRegisterHints() {
Constructor<RocketMQSpecificPropertiesProvider> constructor;
try {
constructor = RocketMQSpecificPropertiesProvider.class.getConstructor();
}
catch (NoSuchMethodException e) {
throw new RuntimeException(e);
}
Method getConsumer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "getConsumer");
Method setConsumer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "setConsumer", RocketMQConsumerProperties.class);
Method getProducer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "getProducer");
Method setProducer = ReflectionUtils.findMethod(RocketMQSpecificPropertiesProvider.class, "setProducer", RocketMQProducerProperties.class);
RuntimeHints hints = new RuntimeHints();
new RocketMQSpecificPropertiesProviderHints().registerHints(hints, getClass().getClassLoader());
assertThat(RuntimeHintsPredicates.reflection().onConstructor(constructor)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(getConsumer)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(setConsumer)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(getProducer)).accepts(hints);
assertThat(RuntimeHintsPredicates.reflection().onMethod(setProducer)).accepts(hints);
}
}