-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add relevant hints of RocketMQ starter (#3371)
feature: add relevant hints of RocketMQ starter & fix files format problem
- Loading branch information
Showing
8 changed files
with
243 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
...va/com/alibaba/cloud/stream/binder/rocketmq/aot/hint/RocketMQConsumerPropertiesHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...libaba/cloud/stream/binder/rocketmq/aot/hint/RocketMQSpecificPropertiesProviderHints.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ers/spring-cloud-starter-stream-rocketmq/src/main/resources/META-INF/spring/aot.factories
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
55 changes: 55 additions & 0 deletions
55
...m/alibaba/cloud/stream/binder/rocketmq/aot/hint/RocketMQConsumerPropertiesHintsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...a/cloud/stream/binder/rocketmq/aot/hint/RocketMQSpecificPropertiesProviderHintsTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |