├── .asf.yaml ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── coverage.yml │ ├── license-checker.yaml │ └── maven.yml ├── .gitignore ├── .licenserc.yaml ├── LICENSE ├── NOTICE ├── README.md ├── pom.xml ├── rocketmq-spring-boot-parent └── pom.xml ├── rocketmq-spring-boot-samples ├── LICENSE ├── README.md ├── pom.xml ├── rocketmq-consume-acl-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ACLStringConsumer.java │ │ │ ├── ACLStringTransactionalConsumer.java │ │ │ └── ConsumerACLApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-consume-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ConsumerApplication.java │ │ │ ├── ExtRocketMQTemplate.java │ │ │ ├── consumer │ │ │ ├── Checker.java │ │ │ ├── ConsumerWithReplyBytes.java │ │ │ ├── ConsumerWithReplyGeneric.java │ │ │ ├── MessageExtConsumer.java │ │ │ ├── ObjectConsumerWithReplyUser.java │ │ │ ├── OrderPaidEventConsumer.java │ │ │ ├── StringConsumer.java │ │ │ ├── StringConsumerNewNS.java │ │ │ ├── StringConsumerWithReplyString.java │ │ │ ├── StringTransactionalConsumer.java │ │ │ └── UserConsumer.java │ │ │ └── domain │ │ │ ├── OrderPaidEvent.java │ │ │ ├── ProductWithPayload.java │ │ │ └── User.java │ │ └── resources │ │ └── application.properties ├── rocketmq-consumer-pull-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── PullConsumerApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-consumer-push-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── PushConsumerApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-produce-acl-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── ProducerACLApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-produce-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ExtRocketMQTemplate.java │ │ │ ├── ProducerApplication.java │ │ │ └── domain │ │ │ ├── OrderPaidEvent.java │ │ │ ├── ProductWithPayload.java │ │ │ └── User.java │ │ └── resources │ │ └── application.properties ├── rocketmq-producer-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── ProducerApplication.java │ │ └── resources │ │ └── application.properties └── style │ ├── copyright │ ├── Apache.xml │ └── profiles_settings.xml │ ├── rmq_checkstyle.xml │ └── rmq_codeStyle.xml ├── rocketmq-spring-boot-starter └── pom.xml ├── rocketmq-spring-boot ├── README.md ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── spring │ │ │ ├── annotation │ │ │ ├── ConsumeMode.java │ │ │ ├── ExtRocketMQConsumerConfiguration.java │ │ │ ├── ExtRocketMQTemplateConfiguration.java │ │ │ ├── MessageModel.java │ │ │ ├── RocketMQMessageListener.java │ │ │ ├── RocketMQMessageListenerBeanPostProcessor.java │ │ │ ├── RocketMQTransactionListener.java │ │ │ └── SelectorType.java │ │ │ ├── autoconfigure │ │ │ ├── ExtConsumerResetConfiguration.java │ │ │ ├── ExtProducerResetConfiguration.java │ │ │ ├── ListenerContainerConfiguration.java │ │ │ ├── MessageConverterConfiguration.java │ │ │ ├── RocketMQAutoConfiguration.java │ │ │ ├── RocketMQListenerConfiguration.java │ │ │ ├── RocketMQProperties.java │ │ │ └── RocketMQTransactionConfiguration.java │ │ │ ├── core │ │ │ ├── RocketMQListener.java │ │ │ ├── RocketMQLocalRequestCallback.java │ │ │ ├── RocketMQLocalTransactionListener.java │ │ │ ├── RocketMQLocalTransactionState.java │ │ │ ├── RocketMQPushConsumerLifecycleListener.java │ │ │ ├── RocketMQReplyListener.java │ │ │ └── RocketMQTemplate.java │ │ │ └── support │ │ │ ├── DefaultRocketMQListenerContainer.java │ │ │ ├── DelayMode.java │ │ │ ├── RocketMQConsumerLifecycleListener.java │ │ │ ├── RocketMQHeaders.java │ │ │ ├── RocketMQListenerContainer.java │ │ │ ├── RocketMQMessageConverter.java │ │ │ ├── RocketMQMessageListenerContainerRegistrar.java │ │ │ └── RocketMQUtil.java │ └── resources │ │ └── META-INF │ │ ├── spring.factories │ │ └── spring │ │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports │ └── test │ └── java │ └── org │ └── apache │ └── rocketmq │ └── spring │ ├── annotation │ └── RocketMQMessageListenerBeanPostProcessorTest.java │ ├── autoconfigure │ └── RocketMQAutoConfigurationTest.java │ ├── core │ ├── ExtRocketMQTemplateTest.java │ └── RocketMQTemplateTest.java │ └── support │ ├── DefaultRocketMQListenerContainerTest.java │ └── RocketMQUtilTest.java ├── rocketmq-v5-client-spring-boot-parent └── pom.xml ├── rocketmq-v5-client-spring-boot-samples ├── README-CN.md ├── pom.xml ├── rocketmq-v5-client-consume-acl-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ClientConsumerACLApplication.java │ │ │ └── consumer │ │ │ └── ACLConsumer.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-consume-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ClientConsumeApplication.java │ │ │ ├── ExtRocketMQTemplate.java │ │ │ └── consumer │ │ │ ├── FifoConsumer.java │ │ │ └── TransConsumer.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-consumer-push-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── V5PushConsumerConsumerApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-consumer-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── V5SimpleConsumerConsumerApplication.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-producer-acl-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ClientProducerACLApplication.java │ │ │ └── domain │ │ │ └── UserMessage.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-producer-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ ├── ClientProducerApplication.java │ │ │ └── domain │ │ │ └── UserMessage.java │ │ └── resources │ │ └── application.properties ├── rocketmq-v5-client-producer-simple-demo │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ └── org │ │ │ └── apache │ │ │ └── rocketmq │ │ │ └── samples │ │ │ └── springboot │ │ │ └── V5ProducerApplication.java │ │ └── resources │ │ └── application.properties └── style │ ├── copyright │ ├── Apache.xml │ └── profiles_settings.xml │ ├── rmq_checkstyle.xml │ └── rmq_codeStyle.xml ├── rocketmq-v5-client-spring-boot-starter └── pom.xml ├── rocketmq-v5-client-spring-boot ├── pom.xml └── src │ └── main │ ├── java │ └── org │ │ └── apache │ │ └── rocketmq │ │ └── client │ │ ├── annotation │ │ ├── ExtConsumerResetConfiguration.java │ │ ├── ExtProducerResetConfiguration.java │ │ ├── RocketMQMessageListener.java │ │ ├── RocketMQMessageListenerBeanPostProcessor.java │ │ └── RocketMQTransactionListener.java │ │ ├── autoconfigure │ │ ├── ExtConsumerResetConfiguration.java │ │ ├── ExtTemplateResetConfiguration.java │ │ ├── ListenerContainerConfiguration.java │ │ ├── MessageConverterConfiguration.java │ │ ├── RocketMQAutoConfiguration.java │ │ ├── RocketMQListenerConfiguration.java │ │ ├── RocketMQProperties.java │ │ └── RocketMQTransactionConfiguration.java │ │ ├── common │ │ └── Pair.java │ │ ├── core │ │ ├── RocketMQClientTemplate.java │ │ ├── RocketMQListener.java │ │ └── RocketMQTransactionChecker.java │ │ └── support │ │ ├── DefaultListenerContainer.java │ │ ├── RocketMQHeaders.java │ │ ├── RocketMQListenerContainer.java │ │ ├── RocketMQMessageConverter.java │ │ └── RocketMQUtil.java │ └── resources │ └── META-INF │ ├── spring.factories │ └── spring │ └── org.springframework.boot.autoconfigure.AutoConfiguration.imports └── style ├── copyright ├── Apache.xml └── profiles_settings.xml ├── rmq_checkstyle.xml └── rmq_codeStyle.xml /.asf.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | notifications: 17 | commits: commits@rocketmq.apache.org 18 | issues: commits@rocketmq.apache.org 19 | pullrequests: commits@rocketmq.apache.org 20 | jobs: commits@rocketmq.apache.org 21 | discussions: dev@rocketmq.apache.org 22 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | The issue tracker is **ONLY** used for bug report and feature request. 2 | 3 | Any question or RocketMQ proposal please use our [mailing lists](http://rocketmq.apache.org/about/contact/). 4 | 5 | **BUG REPORT** 6 | 7 | 1. Please describe the issue you observed: 8 | 9 | - What did you do (The steps to reproduce)? 10 | 11 | - What did you expect to see? 12 | 13 | - What did you see instead? 14 | 15 | 2. Please tell us about your environment: 16 | 17 | 3. Other information (e.g. detailed explanation, logs, related issues, suggestions how to fix, etc): 18 | 19 | **FEATURE REQUEST** 20 | 21 | 1. Please describe the feature you are requesting. 22 | 23 | 2. Provide any additional detail on your proposed use case for this feature. 24 | 25 | 3. Indicate the importance of this issue to you (blocker, must-have, should-have, nice-to-have). Are you currently using any workarounds to address this issue? 26 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ## What is the purpose of the change 2 | 3 | XXXXX 4 | 5 | ## Brief changelog 6 | 7 | XX 8 | 9 | ## Verifying this change 10 | 11 | XXXX 12 | 13 | Follow this checklist to help us incorporate your contribution quickly and easily. Notice, `it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR`. 14 | 15 | - [ ] Make sure there is a [Github issue](https://github.com/apache/rocketmq/issues) filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue. 16 | - [ ] Format the pull request title like `[ISSUE #123] Fix UnknownException when host config not exist`. Each commit in the pull request should have a meaningful subject line and body. 17 | - [ ] Write a pull request description that is detailed enough to understand what the pull request does, how, and why. 18 | - [ ] Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist. 19 | - [ ] Run `mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle` to make sure basic checks pass. Run `mvn clean install -DskipITs` to make sure unit-test pass. Run `mvn clean test-compile failsafe:integration-test` to make sure integration-test pass. 20 | - [ ] If this contribution is large, please file an [Apache Individual Contributor License Agreement](http://www.apache.org/licenses/#clas). 21 | -------------------------------------------------------------------------------- /.github/workflows/coverage.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | name: Coverage 18 | on: 19 | pull_request: 20 | types: [opened, reopened, synchronize] 21 | push: 22 | branches: [master, develop] 23 | jobs: 24 | calculate-coverage: 25 | runs-on: ubuntu-latest 26 | steps: 27 | - uses: actions/checkout@master 28 | - name: Set up JDK 8 29 | uses: actions/setup-java@v2 30 | with: 31 | java-version: "8" 32 | distribution: "adopt" 33 | cache: "maven" 34 | - name: Generate coverage report 35 | run: mvn -B test -T 2C --file pom.xml 36 | - name: Upload to Codecov 37 | uses: codecov/codecov-action@v3 38 | with: 39 | fail_ci_if_error: true 40 | verbose: true 41 | -------------------------------------------------------------------------------- /.github/workflows/license-checker.yaml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one 2 | # or more contributor license agreements. See the NOTICE file 3 | # distributed with this work for additional information 4 | # regarding copyright ownership. The ASF licenses this file 5 | # to you under the Apache License, Version 2.0 (the 6 | # "License"); you may not use this file except in compliance 7 | # with the License. You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | name: License checker 18 | 19 | on: 20 | pull_request: 21 | branches: 22 | - master 23 | 24 | jobs: 25 | check-license: 26 | runs-on: ubuntu-latest 27 | steps: 28 | - uses: actions/checkout@v3 29 | - name: Check License Header 30 | uses: apache/skywalking-eyes@v0.2.0 31 | with: 32 | log: info 33 | config: .licenserc.yaml 34 | -------------------------------------------------------------------------------- /.github/workflows/maven.yml: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | name: Java CI with Maven 17 | 18 | on: 19 | push: 20 | branches: [ "master" ] 21 | pull_request: 22 | branches: [ "master" ] 23 | 24 | jobs: 25 | build: 26 | 27 | runs-on: ubuntu-latest 28 | 29 | steps: 30 | - uses: actions/checkout@v3 31 | - name: Set up JDK 8 32 | uses: actions/setup-java@v3 33 | with: 34 | java-version: '8' 35 | distribution: 'temurin' 36 | cache: maven 37 | - name: Build with Maven 38 | run: mvn -B package --file pom.xml 39 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | .classpath 3 | .project 4 | .settings/ 5 | target/ 6 | *.log* 7 | *.iml 8 | .idea/ 9 | *.versionsBackup 10 | !NOTICE-BIN 11 | !LICENSE-BIN 12 | .DS_Store 13 | .vscode 14 | .factorypath 15 | -------------------------------------------------------------------------------- /.licenserc.yaml: -------------------------------------------------------------------------------- 1 | # 2 | # Licensed to the Apache Software Foundation (ASF) under one 3 | # or more contributor license agreements. See the NOTICE file 4 | # distributed with this work for additional information 5 | # regarding copyright ownership. The ASF licenses this file 6 | # to you under the Apache License, Version 2.0 (the 7 | # "License"); you may not use this file except in compliance 8 | # with the License. You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, 13 | # software distributed under the License is distributed on an 14 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | # KIND, either express or implied. See the License for the 16 | # specific language governing permissions and limitations 17 | # under the License. 18 | # 19 | header: 20 | license: 21 | spdx-id: Apache-2.0 22 | copyright-owner: Apache Software Foundation 23 | 24 | paths-ignore: 25 | - '.gitignore' 26 | - 'CONTRIBUTING.md' 27 | - 'LICENSE' 28 | - 'NOTICE' 29 | - '**/*.md' 30 | - 'BUILDING' 31 | - '.github/**' 32 | - '*/src/test/resources/certs/*' 33 | - 'src/test/**/*.log' 34 | - '*/src/test/resources/META-INF/service/*' 35 | - '*/src/main/resources/META-INF/service/*' 36 | - '*/src/main/resources/META-INF/spring/*' 37 | - '**/*/spring.factories' 38 | - '**/target/**' 39 | - '**/*.iml' 40 | - 'docs/**' 41 | - '**/application.properties' 42 | 43 | 44 | comment: on-failure -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Apache RocketMQ 2 | Copyright 2016-2024 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # RocketMQ-Spring 2 | 3 | [![Build Status](https://travis-ci.org/apache/rocketmq-spring.svg?branch=master)](https://travis-ci.org/apache/rocketmq-spring) 4 | [![Coverage Status](https://coveralls.io/repos/github/apache/rocketmq-spring/badge.svg?branch=master)](https://coveralls.io/github/apache/rocketmq-spring?branch=master) 5 | [![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.apache.rocketmq/rocketmq-spring-all/badge.svg)](https://search.maven.org/search?q=g:org.apache.rocketmq%20AND%20a:rocketmq-spring-all) 6 | [![GitHub release](https://img.shields.io/badge/release-download-orange.svg)](https://github.com/apache/rocketmq-spring/releases) 7 | [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 8 | [![Average time to resolve an issue](http://isitmaintained.com/badge/resolution/apache/rocketmq-spring.svg)](http://isitmaintained.com/project/apache/rocketmq-spring "Average time to resolve an issue") 9 | [![Percentage of issues still open](http://isitmaintained.com/badge/open/apache/rocketmq-spring.svg)](http://isitmaintained.com/project/apache/rocketmq-spring "Percentage of issues still open") 10 | 11 | This project aims to help developers quickly integrate [RocketMQ](http://rocketmq.apache.org/) with [Spring Boot](http://projects.spring.io/spring-boot/). 12 | 13 | ## Features 14 | 15 | - [x] Send messages synchronously 16 | - [x] Send messages asynchronously 17 | - [x] Send messages in one-way mode 18 | - [x] Send ordered messages 19 | - [x] Send batched messages 20 | - [x] Send transactional messages 21 | - [x] Send scheduled messages with delay level 22 | - [x] Consume messages with concurrent mode (broadcasting/clustering) 23 | - [x] Consume ordered messages 24 | - [x] Filter messages using the tag or sql92 expression 25 | - [x] Support message tracing 26 | - [x] Support authentication and authorization 27 | - [x] Support request-reply message exchange pattern 28 | - [x] Consume messages with push/pull mode 29 | 30 | ## Prerequisites 31 | 32 | - JDK 1.8 and above 33 | - [Maven](http://maven.apache.org/) 3.0 and above 34 | - Spring Boot 2.0 and above 35 | 36 | ## Usage 37 | 38 | Add a dependency using maven: 39 | 40 | ```xml 41 | 42 | 43 | org.apache.rocketmq 44 | rocketmq-spring-boot-starter 45 | ${RELEASE.VERSION} 46 | 47 | ``` 48 | 49 | ## Samples 50 | 51 | Please see the [rocketmq-spring-boot-samples](rocketmq-spring-boot-samples). 52 | 53 | ## User Guide 54 | 55 | Please see the [wiki](https://github.com/apache/rocketmq-spring/wiki) page. 56 | 57 | ## Contributing 58 | 59 | We are always very happy to have contributions, whether for trivial cleanups or big new features. Please see the RocketMQ main website to read the [details](http://rocketmq.apache.org/docs/how-to-contribute/). 60 | 61 | ## License 62 | 63 | [Apache License, Version 2.0](http://www.apache.org/licenses/LICENSE-2.0.html) Copyright (C) Apache Software Foundation 64 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/README.md: -------------------------------------------------------------------------------- 1 | # rocketmq-spring-boot-samples 2 | 3 | [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](https://www.apache.org/licenses/LICENSE-2.0.html) 4 | 5 | It's a demo project for how to use [rocketmq-spring-boot](https://github.com/apache/rocketmq-spring) 6 | 7 | Run the test case locally 8 | 1. build and install the rocketmq-spring-boot-starter 9 | 10 | 2. startup rocketmq according to quick-start, verify the namesvr and broker startup correctly, Note: DON'T do "Shutdown Servers" step. 11 | http://rocketmq.apache.org/docs/quick-start/ 12 | 13 | 3. create topics for the demo test cases 14 | ``` 15 | bash bin/mqadmin updateTopic -c DefaultCluster -t string-topic 16 | bash bin/mqadmin updateTopic -c DefaultCluster -t order-paid-topic 17 | bash bin/mqadmin updateTopic -c DefaultCluster -t message-ext-topic 18 | bash bin/mqadmin updateTopic -c DefaultCluster -t spring-transaction-topic 19 | ``` 20 | 4. run tests 21 | 22 | ``` 23 | # open a terminal, run produce 24 | cd rocketmq-produce-demo 25 | mvn clean package 26 | java -jar target/rocketmq-produce-demo-0.0.1-SNAPSHOT.jar 27 | 28 | # open another terminal, run consume 29 | cd rocketmq-consume-demo 30 | mvn clean package 31 | java -jar target/rocketmq-consume-demo-0.0.1-SNAPSHOT.jar 32 | ``` 33 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 4.0.0 23 | 24 | org.apache.rocketmq 25 | rocketmq-spring-boot-samples 26 | pom 27 | 2.3.2-SNAPSHOT 28 | 29 | RocketMQ Spring Boot Samples 30 | Samples for RocketMQ Spring Boot 31 | https://github.com/apache/rocketmq-spring 32 | 33 | 34 | rocketmq-produce-demo 35 | rocketmq-consume-demo 36 | rocketmq-produce-acl-demo 37 | rocketmq-consume-acl-demo 38 | rocketmq-producer-simple-demo 39 | rocketmq-consumer-pull-simple-demo 40 | rocketmq-consumer-push-simple-demo 41 | 42 | 43 | 44 | 1.8 45 | 1.8 46 | 47 | 48 | 49 | 50 | org.apache.rocketmq 51 | rocketmq-spring-boot-starter 52 | ${project.version} 53 | 54 | 55 | 56 | 57 | 58 | 59 | org.apache.maven.plugins 60 | maven-checkstyle-plugin 61 | 2.17 62 | 63 | 64 | validate 65 | validate 66 | 67 | src/main/resources 68 | style/rmq_checkstyle.xml 69 | UTF-8 70 | true 71 | true 72 | 73 | 74 | check 75 | 76 | 77 | 78 | 79 | 80 | org.springframework.boot 81 | spring-boot-maven-plugin 82 | 2.1.0.RELEASE 83 | 84 | 85 | 86 | repackage 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-acl-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 4.0.0 23 | 24 | org.apache.rocketmq 25 | rocketmq-spring-boot-samples 26 | 2.3.2-SNAPSHOT 27 | 28 | 29 | rocketmq-consume-acl-demo 30 | 31 | 32 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ACLStringConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * RocketMQMessageListener 26 | */ 27 | @Service 28 | @RocketMQMessageListener( 29 | topic = "normal_topic_define_in_cloud_MQ", 30 | consumerGroup = "group_define_in_cloud_MQ" 31 | //accessKey = "AK" // It will read by `rocketmq.consumer.access-key` key 32 | //secretKey = "SK" // It will read by `rocketmq.consumer.secret-key` key 33 | ) 34 | public class ACLStringConsumer implements RocketMQListener { 35 | @Override 36 | public void onMessage(String message) { 37 | System.out.printf("------- ACL StringConsumer received: %s \n", message); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ACLStringTransactionalConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * StringTransactionalConsumer 26 | */ 27 | @Service 28 | @RocketMQMessageListener( 29 | topic = "${demo.rocketmq.transTopic}", 30 | consumerGroup = "group_define_in_cloud_MQ", 31 | accessKey = "AK", // if accessKey is empty, it will read by `rocketmq.consumer.access-key` key 32 | secretKey = "SK" // if accessKey is empty, it will read by `rocketmq.consumer.secret-key` key 33 | ) 34 | public class ACLStringTransactionalConsumer implements RocketMQListener { 35 | @Override 36 | public void onMessage(String message) { 37 | System.out.printf("------- ACL StringTransactionalConsumer received: %s \n", message); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ConsumerACLApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 21 | import org.springframework.boot.CommandLineRunner; 22 | import org.springframework.boot.SpringApplication; 23 | import org.springframework.boot.autoconfigure.SpringBootApplication; 24 | 25 | import javax.annotation.Resource; 26 | import java.util.List; 27 | 28 | /** 29 | * ConsumerApplication 30 | */ 31 | @SpringBootApplication 32 | public class ConsumerACLApplication implements CommandLineRunner { 33 | 34 | @Resource 35 | private RocketMQTemplate rocketMQTemplate; 36 | 37 | public static void main(String[] args) { 38 | SpringApplication.run(ConsumerACLApplication.class, args); 39 | } 40 | 41 | @Override 42 | public void run(String... args) throws Exception { 43 | ////This is an example of pull consumer with access-key and secret-key. 44 | List messages = rocketMQTemplate.receive(String.class); 45 | System.out.printf("receive from rocketMQTemplate, messages=%s %n", messages); 46 | } 47 | } 48 | 49 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-acl-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | 17 | spring.application.name=rocketmq-consume-acl-demo 18 | 19 | rocketmq.name-server=Endpoint_of_cloud_MQ 20 | # When set rocketmq.pull-consumer.group and rocketmq.pull-consumer.topic, rocketmqTemplate will start lite pull consumer 21 | # If you do not want to use lite pull consumer, please do not set rocketmq.pull-consumer.group and rocketmq.pull-consumer.topic 22 | rocketmq.pull-consumer.group=my-group1 23 | rocketmq.pull-consumer.topic=test 24 | rocketmq.topic=normal_topic_define_in_cloud_MQ 25 | 26 | # properties used in application code 27 | demo.rocketmq.transTopic=transaction_topic_define_in_cloud_MQ 28 | 29 | rocketmq.consumer.access-key=AK 30 | rocketmq.consumer.secret-key=SK 31 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 4.0.0 23 | 24 | org.apache.rocketmq 25 | rocketmq-spring-boot-samples 26 | 2.3.2-SNAPSHOT 27 | 28 | 29 | rocketmq-consume-demo 30 | 31 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 21 | import org.springframework.boot.CommandLineRunner; 22 | import org.springframework.boot.SpringApplication; 23 | import org.springframework.boot.autoconfigure.SpringBootApplication; 24 | 25 | import javax.annotation.Resource; 26 | import java.util.List; 27 | 28 | /** 29 | * ConsumerApplication 30 | */ 31 | @SpringBootApplication 32 | public class ConsumerApplication implements CommandLineRunner { 33 | 34 | @Resource 35 | private RocketMQTemplate rocketMQTemplate; 36 | 37 | @Resource(name = "extRocketMQTemplate") 38 | private RocketMQTemplate extRocketMQTemplate; 39 | 40 | public static void main(String[] args) { 41 | SpringApplication.run(ConsumerApplication.class, args); 42 | } 43 | 44 | @Override 45 | public void run(String... args) throws Exception { 46 | //This is an example of pull consumer using rocketMQTemplate. 47 | List messages = rocketMQTemplate.receive(String.class); 48 | System.out.printf("receive from rocketMQTemplate, messages=%s %n", messages); 49 | 50 | //This is an example of pull consumer using extRocketMQTemplate. 51 | messages = extRocketMQTemplate.receive(String.class); 52 | System.out.printf("receive from extRocketMQTemplate, messages=%s %n", messages); 53 | } 54 | } 55 | 56 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot; 18 | 19 | import org.apache.rocketmq.spring.annotation.ExtRocketMQConsumerConfiguration; 20 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 21 | 22 | @ExtRocketMQConsumerConfiguration(topic = "${demo.rocketmq.topic}", group = "string_consumer", tlsEnable = "${demo.ext.consumer.tlsEnable}") 23 | public class ExtRocketMQTemplate extends RocketMQTemplate { 24 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/Checker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.client.producer.LocalTransactionState; 21 | import org.apache.rocketmq.client.producer.TransactionListener; 22 | import org.apache.rocketmq.common.message.Message; 23 | import org.apache.rocketmq.common.message.MessageExt; 24 | 25 | /** 26 | * Note: This is a nagitive testing. It aims to tell user the fact that 27 | * the @RocketMQTransactionListener can not be used on consumer side!!! 28 | * 29 | *

How to try it? just uncomment the annotation declaration, then compile 30 | * and run the consumer, it will fail to start. 31 | */ 32 | 33 | //@RocketMQTransactionListener 34 | public class Checker implements TransactionListener { 35 | @Override 36 | public LocalTransactionState executeLocalTransaction(Message message, Object o) { 37 | return null; 38 | } 39 | 40 | @Override 41 | public LocalTransactionState checkLocalTransaction(MessageExt messageExt) { 42 | return null; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ConsumerWithReplyBytes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.common.message.MessageExt; 21 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | /** 26 | * The consumer that replying bytes 27 | */ 28 | @Service 29 | @RocketMQMessageListener(topic = "${demo.rocketmq.bytesRequestTopic}", consumerGroup = "${demo.rocketmq.bytesRequestConsumer}", selectorExpression = "${demo.rocketmq.tag}") 30 | public class ConsumerWithReplyBytes implements RocketMQReplyListener { 31 | 32 | @Override 33 | public byte[] onMessage(MessageExt message) { 34 | System.out.printf("------- ConsumerWithReplyBytes received: %s \n", message); 35 | return "reply message content".getBytes(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ConsumerWithReplyGeneric.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.samples.springboot.domain.ProductWithPayload; 21 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | /** 26 | * The consumer that replying generic type 27 | */ 28 | @Service 29 | @RocketMQMessageListener(topic = "${demo.rocketmq.genericRequestTopic}", consumerGroup = "${demo.rocketmq.genericRequestConsumer}", selectorExpression = "${demo.rocketmq.tag}") 30 | public class ConsumerWithReplyGeneric implements RocketMQReplyListener> { 31 | @Override 32 | public ProductWithPayload onMessage(String message) { 33 | System.out.printf("------- ConsumerWithReplyGeneric received: %s \n", message); 34 | return new ProductWithPayload("replyProductName", "product payload"); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MessageExtConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; 21 | import org.apache.rocketmq.common.UtilAll; 22 | import org.apache.rocketmq.common.consumer.ConsumeFromWhere; 23 | import org.apache.rocketmq.common.message.MessageExt; 24 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 25 | import org.apache.rocketmq.spring.core.RocketMQListener; 26 | import org.apache.rocketmq.spring.core.RocketMQPushConsumerLifecycleListener; 27 | import org.springframework.stereotype.Service; 28 | 29 | /** 30 | * MessageExtConsumer, consume listener impl class. 31 | */ 32 | @Service 33 | @RocketMQMessageListener(topic = "${demo.rocketmq.msgExtTopic}", selectorExpression = "tag0||tag1", consumerGroup = "${spring.application.name}-message-ext-consumer") 34 | public class MessageExtConsumer implements RocketMQListener, RocketMQPushConsumerLifecycleListener { 35 | @Override 36 | public void onMessage(MessageExt message) { 37 | System.out.printf("------- MessageExtConsumer received message, msgId: %s, body:%s \n", message.getMsgId(), new String(message.getBody())); 38 | } 39 | 40 | @Override 41 | public void prepareStart(DefaultMQPushConsumer consumer) { 42 | // set consumer consume message from now 43 | consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_TIMESTAMP); 44 | consumer.setConsumeTimestamp(UtilAll.timeMillisToHumanString3(System.currentTimeMillis())); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ObjectConsumerWithReplyUser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.samples.springboot.domain.User; 21 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | /** 26 | * The consumer that replying Object 27 | */ 28 | @Service 29 | @RocketMQMessageListener(topic = "${demo.rocketmq.objectRequestTopic}", consumerGroup = "${demo.rocketmq.objectRequestConsumer}", selectorExpression = "${demo.rocketmq.tag}") 30 | public class ObjectConsumerWithReplyUser implements RocketMQReplyListener { 31 | 32 | @Override 33 | public User onMessage(User user) { 34 | System.out.printf("------- ObjectConsumerWithReplyUser received: %s \n", user); 35 | User replyUser = new User(); 36 | replyUser.setUserAge((byte) 10); 37 | replyUser.setUserName("replyUserName"); 38 | return replyUser; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/OrderPaidEventConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.samples.springboot.domain.OrderPaidEvent; 21 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.spring.core.RocketMQListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | /** 26 | * OrderPaidEventConsumer 27 | */ 28 | @Service 29 | @RocketMQMessageListener(topic = "${demo.rocketmq.orderTopic}", consumerGroup = "order-paid-consumer") 30 | public class OrderPaidEventConsumer implements RocketMQListener { 31 | 32 | @Override 33 | public void onMessage(OrderPaidEvent orderPaidEvent) { 34 | System.out.printf("------- OrderPaidEventConsumer received: %s [orderId : %s]\n", orderPaidEvent,orderPaidEvent.getOrderId()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/StringConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * StringConsumer 26 | */ 27 | @Service 28 | @RocketMQMessageListener(topic = "${demo.rocketmq.topic}", consumerGroup = "string_consumer", selectorExpression = "${demo.rocketmq.tag}", tlsEnable = "${demo.rocketmq.tlsEnable}") 29 | public class StringConsumer implements RocketMQListener { 30 | @Override 31 | public void onMessage(String message) { 32 | System.out.printf("------- StringConsumer received: %s \n", message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/StringConsumerNewNS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * RocketMQMessageListener 26 | */ 27 | @Service 28 | @RocketMQMessageListener(nameServer = "${demo.rocketmq.myNameServer}", topic = "${demo.rocketmq.topic}", consumerGroup = "string_consumer_newns") 29 | public class StringConsumerNewNS implements RocketMQListener { 30 | @Override 31 | public void onMessage(String message) { 32 | System.out.printf("------- StringConsumerNewNS received: %s \n", message); 33 | } 34 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/StringConsumerWithReplyString.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQReplyListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * The consumer that replying String 26 | */ 27 | @Service 28 | @RocketMQMessageListener(topic = "${demo.rocketmq.stringRequestTopic}", consumerGroup = "${demo.rocketmq.stringRequestConsumer}", 29 | selectorExpression = "${demo.rocketmq.tag}", replyTimeout = 10000) 30 | public class StringConsumerWithReplyString implements RocketMQReplyListener { 31 | 32 | @Override 33 | public String onMessage(String message) { 34 | System.out.printf("------- StringConsumerWithReplyString received: %s \n", message); 35 | return "reply string"; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/StringTransactionalConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.stereotype.Service; 23 | 24 | /** 25 | * StringTransactionalConsumer 26 | */ 27 | @Service 28 | @RocketMQMessageListener(topic = "${demo.rocketmq.transTopic}", consumerGroup = "string_trans_consumer") 29 | public class StringTransactionalConsumer implements RocketMQListener { 30 | @Override 31 | public void onMessage(String message) { 32 | System.out.printf("------- StringTransactionalConsumer received: %s \n", message); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/UserConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.consumer; 19 | 20 | import org.apache.rocketmq.samples.springboot.domain.User; 21 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.spring.core.RocketMQListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | /** 26 | * RocketMQMessageListener 27 | */ 28 | @Service 29 | @RocketMQMessageListener(nameServer = "${demo.rocketmq.myNameServer}", topic = "${demo.rocketmq.topic.user}", consumerGroup = "user_consumer") 30 | public class UserConsumer implements RocketMQListener { 31 | @Override 32 | public void onMessage(User message) { 33 | 34 | System.out.printf("######## user_consumer received: %s ; age: %s ; name: %s \n", message, message.getUserAge(), message.getUserName()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/OrderPaidEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.domain; 19 | 20 | import java.io.Serializable; 21 | import java.math.BigDecimal; 22 | 23 | /** 24 | * OrderPaidEvent 25 | */ 26 | public class OrderPaidEvent implements Serializable { 27 | private String orderId; 28 | 29 | private BigDecimal paidMoney; 30 | 31 | public OrderPaidEvent() { 32 | } 33 | 34 | public OrderPaidEvent(String orderId, BigDecimal paidMoney) { 35 | this.orderId = orderId; 36 | this.paidMoney = paidMoney; 37 | } 38 | 39 | public String getOrderId() { 40 | return orderId; 41 | } 42 | 43 | public void setOrderId(String orderId) { 44 | this.orderId = orderId; 45 | } 46 | 47 | public BigDecimal getPaidMoney() { 48 | return paidMoney; 49 | } 50 | 51 | public void setPaidMoney(BigDecimal paidMoney) { 52 | this.paidMoney = paidMoney; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/ProductWithPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.domain; 19 | 20 | public class ProductWithPayload { 21 | private String productName; 22 | private T payload; 23 | 24 | public ProductWithPayload() { 25 | } 26 | 27 | public ProductWithPayload(String productName, T payload) { 28 | this.productName = productName; 29 | this.payload = payload; 30 | } 31 | 32 | public String getProductName() { 33 | return productName; 34 | } 35 | 36 | public void setProductName(String productName) { 37 | this.productName = productName; 38 | } 39 | 40 | public T getPayload() { 41 | return payload; 42 | } 43 | 44 | public void setPayload(T payload) { 45 | this.payload = payload; 46 | } 47 | 48 | @Override public String toString() { 49 | return "ProductWithPayload{" + 50 | "productName='" + productName + '\'' + 51 | ", payload=" + payload + 52 | '}'; 53 | } 54 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.domain; 19 | 20 | public class User { 21 | private String userName; 22 | private Byte userAge; 23 | 24 | public String getUserName() { 25 | return userName; 26 | } 27 | 28 | public User setUserName(String userName) { 29 | this.userName = userName; 30 | return this; 31 | } 32 | 33 | public Byte getUserAge() { 34 | return userAge; 35 | } 36 | 37 | public User setUserAge(Byte userAge) { 38 | this.userAge = userAge; 39 | return this; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "User{" + 45 | "userName='" + userName + '\'' + 46 | ", userAge=" + userAge + 47 | '}'; 48 | } 49 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consume-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | spring.application.name=rocketmq-consume-demo 17 | 18 | rocketmq.name-server=localhost:9876 19 | # When set rocketmq.pull-consumer.group and rocketmq.pull-consumer.topic, rocketmqTemplate will start lite pull consumer 20 | # If you do not want to use lite pull consumer, please do not set rocketmq.pull-consumer.group and rocketmq.pull-consumer.topic 21 | rocketmq.pull-consumer.group=my-group1 22 | rocketmq.pull-consumer.topic=test 23 | # properties used in application code 24 | demo.rocketmq.topic=string-topic 25 | demo.rocketmq.bytesRequestTopic=bytesRequestTopic 26 | demo.rocketmq.stringRequestTopic=stringRequestTopic 27 | demo.rocketmq.objectRequestTopic=objectRequestTopic 28 | demo.rocketmq.genericRequestTopic=genericRequestTopic 29 | demo.rocketmq.bytesRequestConsumer=bytesRequestConsumer 30 | demo.rocketmq.stringRequestConsumer=stringRequestConsumer 31 | demo.rocketmq.objectRequestConsumer=objectRequestConsumer 32 | demo.rocketmq.genericRequestConsumer=genericRequestConsumer 33 | demo.rocketmq.orderTopic=order-paid-topic 34 | demo.rocketmq.msgExtTopic=message-ext-topic 35 | demo.rocketmq.transTopic=spring-transaction-topic 36 | demo.rocketmq.topic.user=user-topic 37 | demo.rocketmq.tag=tagA 38 | # another nameserver different global 39 | demo.rocketmq.myNameServer=127.0.0.1:9876 40 | # my Consumer TLS Listener 41 | demo.rocketmq.tlsEnable=false 42 | # default LitePullConsumer TLS 43 | rocketmq.pull-consumer.tlsEnable=false 44 | # ext rocketmq consumer template TLS 45 | demo.ext.consumer.tlsEnable=false 46 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-pull-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-consumer-pull-simple-demo 29 | 30 | 31 | UTF-8 32 | 33 | 34 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-pull-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/PullConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | 21 | import java.util.List; 22 | import javax.annotation.Resource; 23 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 24 | import org.springframework.boot.CommandLineRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.SpringBootApplication; 27 | 28 | @SpringBootApplication 29 | public class PullConsumerApplication implements CommandLineRunner { 30 | @Resource 31 | private RocketMQTemplate rocketMQTemplate; 32 | 33 | public static void main(String[] args) { 34 | SpringApplication.run(PullConsumerApplication.class, args); 35 | } 36 | 37 | @Override 38 | public void run(String... args) { 39 | for (int i = 0; i < 100; i++) { 40 | List messages = rocketMQTemplate.receive(String.class); 41 | System.out.println(messages); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-pull-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.name-server=localhost:9876 17 | 18 | rocketmq.pull-consumer.group=demo-group 19 | rocketmq.pull-consumer.topic=demo-topic 20 | #rocketmq.pull-consumer.access-key= 21 | #rocketmq.pull-consumer.secret-key= -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-push-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-consumer-push-simple-demo 29 | 30 | 31 | UTF-8 32 | 33 | 34 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-push-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/PushConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.springframework.boot.CommandLineRunner; 23 | import org.springframework.boot.SpringApplication; 24 | import org.springframework.boot.autoconfigure.SpringBootApplication; 25 | import org.springframework.stereotype.Service; 26 | 27 | @SpringBootApplication 28 | public class PushConsumerApplication implements CommandLineRunner { 29 | 30 | public static void main(String[] args) { 31 | SpringApplication.run(PushConsumerApplication.class, args); 32 | } 33 | 34 | @Override 35 | public void run(String... args) { 36 | } 37 | 38 | @Service 39 | @RocketMQMessageListener(topic = "demo-topic", consumerGroup = "demo-group") 40 | public static class DemoConsumer implements RocketMQListener { 41 | public void onMessage(String message) { 42 | System.out.println("received message: " + message); 43 | } 44 | } 45 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-consumer-push-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.name-server=localhost:9876 17 | 18 | #rocketmq.consumer.access-key= 19 | #rocketmq.consumer.secret-key= -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-acl-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 4.0.0 23 | 24 | org.apache.rocketmq 25 | rocketmq-spring-boot-samples 26 | 2.3.2-SNAPSHOT 27 | 28 | 29 | rocketmq-produce-acl-demo 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-acl-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.name-server=Endpoint_of_cloud_MQ 17 | rocketmq.producer.group=my-group1 18 | rocketmq.producer.access-key=AK 19 | rocketmq.producer.secret-key=SK 20 | 21 | demo.rocketmq.topic=normal_topic_define_in_cloud_MQ 22 | demo.rocketmq.transTopic=transaction_topic_define_in_cloud_MQ 23 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 22 | 4.0.0 23 | 24 | org.apache.rocketmq 25 | rocketmq-spring-boot-samples 26 | 2.3.2-SNAPSHOT 27 | 28 | 29 | rocketmq-produce-demo 30 | 31 | 32 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot; 18 | 19 | import org.apache.rocketmq.spring.annotation.ExtRocketMQTemplateConfiguration; 20 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 21 | 22 | @ExtRocketMQTemplateConfiguration(nameServer = "${demo.rocketmq.extNameServer}", tlsEnable = "${demo.rocketmq.ext.useTLS}", instanceName = "pztest33") 23 | public class ExtRocketMQTemplate extends RocketMQTemplate { 24 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/OrderPaidEvent.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.domain; 18 | 19 | import java.io.Serializable; 20 | import java.math.BigDecimal; 21 | 22 | public class OrderPaidEvent implements Serializable { 23 | private String orderId; 24 | 25 | private BigDecimal paidMoney; 26 | 27 | public OrderPaidEvent() { 28 | } 29 | 30 | public OrderPaidEvent(String orderId, BigDecimal paidMoney) { 31 | this.orderId = orderId; 32 | this.paidMoney = paidMoney; 33 | } 34 | 35 | public String getOrderId() { 36 | return orderId; 37 | } 38 | 39 | public void setOrderId(String orderId) { 40 | this.orderId = orderId; 41 | } 42 | 43 | public BigDecimal getPaidMoney() { 44 | return paidMoney; 45 | } 46 | 47 | public void setPaidMoney(BigDecimal paidMoney) { 48 | this.paidMoney = paidMoney; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/ProductWithPayload.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.domain; 19 | 20 | public class ProductWithPayload { 21 | private String productName; 22 | private T payload; 23 | 24 | public ProductWithPayload() { 25 | } 26 | 27 | public ProductWithPayload(String productName, T payload) { 28 | this.productName = productName; 29 | this.payload = payload; 30 | } 31 | 32 | public String getProductName() { 33 | return productName; 34 | } 35 | 36 | public void setProductName(String productName) { 37 | this.productName = productName; 38 | } 39 | 40 | public T getPayload() { 41 | return payload; 42 | } 43 | 44 | public void setPayload(T payload) { 45 | this.payload = payload; 46 | } 47 | 48 | @Override public String toString() { 49 | return "ProductWithPayload{" + 50 | "productName='" + productName + '\'' + 51 | ", payload=" + payload + 52 | '}'; 53 | } 54 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/User.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot.domain; 19 | 20 | public class User { 21 | private String userName; 22 | private Byte userAge; 23 | 24 | public String getUserName() { 25 | return userName; 26 | } 27 | 28 | public User setUserName(String userName) { 29 | this.userName = userName; 30 | return this; 31 | } 32 | 33 | public Byte getUserAge() { 34 | return userAge; 35 | } 36 | 37 | public User setUserAge(Byte userAge) { 38 | this.userAge = userAge; 39 | return this; 40 | } 41 | 42 | @Override 43 | public String toString() { 44 | return "User{" + 45 | "userName='" + userName + '\'' + 46 | ", userAge=" + userAge + 47 | '}'; 48 | } 49 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-produce-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.name-server=localhost:9876 17 | rocketmq.producer.group=my-group1 18 | rocketmq.producer.sendMessageTimeout=300000 19 | 20 | # properties used in the application 21 | demo.rocketmq.topic=string-topic 22 | demo.rocketmq.orderTopic=order-paid-topic 23 | demo.rocketmq.msgExtTopic=message-ext-topic 24 | demo.rocketmq.transTopic=spring-transaction-topic 25 | demo.rocketmq.topic.user=user-topic 26 | 27 | demo.rocketmq.bytesRequestTopic=bytesRequestTopic:tagA 28 | demo.rocketmq.stringRequestTopic=stringRequestTopic:tagA 29 | demo.rocketmq.objectRequestTopic=objectRequestTopic:tagA 30 | demo.rocketmq.genericRequestTopic=genericRequestTopic:tagA 31 | 32 | demo.rocketmq.extNameServer=127.0.0.1:9876 33 | # default producer tls config 34 | rocketmq.producer.tls-enable=false 35 | # self ext producer tls config 36 | demo.rocketmq.ext.useTLS=false 37 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-producer-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-producer-simple-demo 29 | 30 | 31 | UTF-8 32 | 33 | 34 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-producer-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/ProducerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import javax.annotation.Resource; 21 | import org.apache.rocketmq.client.producer.SendResult; 22 | import org.apache.rocketmq.spring.core.RocketMQTemplate; 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.CommandLineRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.SpringBootApplication; 27 | 28 | @SpringBootApplication 29 | public class ProducerApplication implements CommandLineRunner { 30 | @Resource 31 | private RocketMQTemplate rocketMQTemplate; 32 | 33 | @Value("${rocketmq.producer.simple.demo.topic}") 34 | private String topic; 35 | 36 | public static void main(String[] args) { 37 | SpringApplication.run(ProducerApplication.class, args); 38 | } 39 | 40 | @Override 41 | public void run(String... args) { 42 | SendResult sendResult = rocketMQTemplate.syncSend(topic, "Hello, World!"); 43 | System.out.println(sendResult); 44 | } 45 | } -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/rocketmq-producer-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.name-server=localhost:9876 17 | 18 | rocketmq.producer.simple.demo.topic=demo-topic 19 | rocketmq.producer.group=demo-group 20 | #rocketmq.producer.access-key= 21 | #rocketmq.producer.secret-key= -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/style/copyright/Apache.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-samples/style/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 47 | 48 | 51 | 52 | 55 | 56 | 59 | 60 | 63 | 64 | -------------------------------------------------------------------------------- /rocketmq-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 20 | 4.0.0 21 | 22 | 23 | org.apache.rocketmq 24 | rocketmq-spring-boot-parent 25 | 2.3.4-SNAPSHOT 26 | ../rocketmq-spring-boot-parent/pom.xml 27 | 28 | 29 | rocketmq-spring-boot-starter 30 | jar 31 | 32 | RocketMQ Spring Boot Starter 33 | RocketMQ Spring Boot Starter 34 | https://github.com/apache/rocketmq-spring 35 | 36 | 37 | 38 | org.apache.rocketmq 39 | rocketmq-spring-boot 40 | 41 | 42 | org.springframework.boot 43 | spring-boot-starter 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-validation 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/README.md: -------------------------------------------------------------------------------- 1 | # RocketMQ Spring Boot Support 2 | This project provides auto-configuration for the following RocketMQ client: 3 | 4 | - [Produce and Consume Spring Message](../rocketmq-spring-boot-starter) 5 | - [Send (half) Message in Transaction](../rocketmq-spring-boot-starter) 6 | 7 | For details, please see sample code in the [rocketmq-spring-boot-samples](../rocketmq-spring-boot-samples) -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/annotation/ConsumeMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | public enum ConsumeMode { 21 | /** 22 | * Receive asynchronously delivered messages concurrently 23 | */ 24 | CONCURRENTLY, 25 | 26 | /** 27 | * Receive asynchronously delivered messages orderly. one queue, one thread 28 | */ 29 | ORDERLY 30 | } 31 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/annotation/ExtRocketMQTemplateConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | import org.springframework.stereotype.Component; 26 | 27 | @Target(ElementType.TYPE) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Documented 30 | @Component 31 | public @interface ExtRocketMQTemplateConfiguration { 32 | /** 33 | * The component name of the Producer configuration. 34 | */ 35 | String value() default ""; 36 | 37 | /** 38 | * The property of "name-server". 39 | */ 40 | String nameServer() default "${rocketmq.name-server:}"; 41 | 42 | /** 43 | * Name of producer. 44 | */ 45 | String group() default "${rocketmq.producer.group:}"; 46 | /** 47 | * Millis of send message timeout. 48 | */ 49 | int sendMessageTimeout() default -1; 50 | /** 51 | * Compress message body threshold, namely, message body larger than 4k will be compressed on default. 52 | */ 53 | int compressMessageBodyThreshold() default -1; 54 | /** 55 | * Maximum number of retry to perform internally before claiming sending failure in synchronous mode. 56 | * This may potentially cause message duplication which is up to application developers to resolve. 57 | */ 58 | int retryTimesWhenSendFailed() default -1; 59 | /** 60 | *

Maximum number of retry to perform internally before claiming sending failure in asynchronous mode.

61 | * This may potentially cause message duplication which is up to application developers to resolve. 62 | */ 63 | int retryTimesWhenSendAsyncFailed() default -1; 64 | /** 65 | * Indicate whether to retry another broker on sending failure internally. 66 | */ 67 | boolean retryNextServer() default false; 68 | /** 69 | * Maximum allowed message size in bytes. 70 | */ 71 | int maxMessageSize() default -1; 72 | /** 73 | * The property of "access-key". 74 | */ 75 | String accessKey() default "${rocketmq.producer.accessKey:}"; 76 | /** 77 | * The property of "secret-key". 78 | */ 79 | String secretKey() default "${rocketmq.producer.secretKey:}"; 80 | /** 81 | * Switch flag instance for message trace. 82 | */ 83 | boolean enableMsgTrace() default false; 84 | /** 85 | * The name value of message trace topic.If you don't config,you can use the default trace topic name. 86 | */ 87 | String customizedTraceTopic() default "${rocketmq.producer.customized-trace-topic:}"; 88 | /** 89 | * The property of "tlsEnable" default false. 90 | */ 91 | String tlsEnable() default "false"; 92 | 93 | /** 94 | * The namespace of producer. 95 | */ 96 | String namespace() default ""; 97 | 98 | /** 99 | * The namespace v2 version of producer, it can not be used in combination with namespace. 100 | */ 101 | String namespaceV2() default ""; 102 | 103 | /** 104 | * The property of "instanceName". 105 | */ 106 | String instanceName() default "DEFAULT"; 107 | } 108 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/annotation/MessageModel.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | public enum MessageModel { 21 | BROADCASTING("BROADCASTING"), 22 | CLUSTERING("CLUSTERING"); 23 | 24 | private final String modeCN; 25 | 26 | MessageModel(String modeCN) { 27 | this.modeCN = modeCN; 28 | } 29 | 30 | public String getModeCN() { 31 | return this.modeCN; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/annotation/RocketMQTransactionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | import java.lang.annotation.Documented; 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | import java.util.concurrent.TimeUnit; 26 | import org.springframework.stereotype.Component; 27 | 28 | /** 29 | * This annotation is used over a class which implements interface 30 | * org.apache.rocketmq.spring.core.RocketMQLocalTransactionListener, which will be converted to 31 | * org.apache.rocketmq.client.producer.TransactionListener later. The class implements 32 | * two methods for process callback events after the txProducer sends a transactional message. 33 | *

Note: The annotation is used only on RocketMQ client producer side, it can not be used 34 | * on consumer side. 35 | */ 36 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) 37 | @Retention(RetentionPolicy.RUNTIME) 38 | @Documented 39 | @Component 40 | public @interface RocketMQTransactionListener { 41 | 42 | /** 43 | * Set ExecutorService params -- corePoolSize 44 | */ 45 | int corePoolSize() default 1; 46 | 47 | /** 48 | * Set ExecutorService params -- maximumPoolSize 49 | */ 50 | int maximumPoolSize() default 1; 51 | 52 | /** 53 | * Set ExecutorService params -- keepAliveTime 54 | */ 55 | long keepAliveTime() default 1000 * 60; 56 | 57 | /** 58 | * Set ExecutorService params -- keepAliveTimeUnit 59 | */ 60 | TimeUnit keepAliveTimeUnit() default TimeUnit.MILLISECONDS; 61 | 62 | /** 63 | * Set ExecutorService params -- blockingQueueSize 64 | */ 65 | int blockingQueueSize() default 2000; 66 | 67 | /** 68 | * Set rocketMQTemplate bean name, the default is rocketMQTemplate. 69 | * if use ExtRocketMQTemplate, can set ExtRocketMQTemplate bean name. 70 | */ 71 | String rocketMQTemplateBeanName() default "rocketMQTemplate"; 72 | 73 | } 74 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/annotation/SelectorType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | import org.apache.rocketmq.common.filter.ExpressionType; 21 | 22 | public enum SelectorType { 23 | 24 | /** 25 | * @see ExpressionType#TAG 26 | */ 27 | TAG, 28 | 29 | /** 30 | * @see ExpressionType#SQL92 31 | */ 32 | SQL92 33 | } 34 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/ListenerContainerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.autoconfigure; 19 | 20 | import org.apache.rocketmq.spring.support.RocketMQMessageConverter; 21 | import org.apache.rocketmq.spring.support.RocketMQMessageListenerContainerRegistrar; 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 23 | import org.springframework.context.annotation.Bean; 24 | import org.springframework.context.annotation.Configuration; 25 | import org.springframework.core.env.ConfigurableEnvironment; 26 | 27 | @Configuration 28 | @ConditionalOnMissingBean(RocketMQMessageListenerContainerRegistrar.class) 29 | public class ListenerContainerConfiguration { 30 | @Bean 31 | public RocketMQMessageListenerContainerRegistrar rocketMQMessageListenerContainerRegistrar(RocketMQMessageConverter rocketMQMessageConverter, ConfigurableEnvironment environment, RocketMQProperties rocketMQProperties) { 32 | return new RocketMQMessageListenerContainerRegistrar(rocketMQMessageConverter, environment, rocketMQProperties); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/MessageConverterConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.autoconfigure; 19 | 20 | import org.apache.rocketmq.spring.support.RocketMQMessageConverter; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | /** 26 | * @see RocketMQMessageConverter 27 | */ 28 | @Configuration 29 | @ConditionalOnMissingBean(RocketMQMessageConverter.class) 30 | class MessageConverterConfiguration { 31 | 32 | @Bean 33 | public RocketMQMessageConverter createRocketMQMessageConverter() { 34 | return new RocketMQMessageConverter(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQListenerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.spring.autoconfigure; 18 | 19 | import org.apache.rocketmq.spring.annotation.RocketMQMessageListenerBeanPostProcessor; 20 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 21 | import org.springframework.beans.factory.support.RootBeanDefinition; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 25 | import org.springframework.core.type.AnnotationMetadata; 26 | 27 | @Configuration 28 | @AutoConfigureAfter(RocketMQAutoConfiguration.class) 29 | public class RocketMQListenerConfiguration implements ImportBeanDefinitionRegistrar { 30 | 31 | @Override 32 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { 33 | if (!registry.containsBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName())) { 34 | registry.registerBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName(), 35 | new RootBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class)); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.core; 19 | 20 | public interface RocketMQListener { 21 | void onMessage(T message); 22 | } 23 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQLocalRequestCallback.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.spring.core; 18 | 19 | /** 20 | * Classes implementing this interface are used for processing callback events after receiving 21 | * reply messages from consumers. 22 | * 23 | * @param the type of message that wanted to receive from consumer 24 | */ 25 | public interface RocketMQLocalRequestCallback { 26 | void onSuccess(final T message); 27 | 28 | void onException(final Throwable e); 29 | } 30 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQLocalTransactionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.spring.core; 18 | 19 | import org.springframework.messaging.Message; 20 | 21 | public interface RocketMQLocalTransactionListener { 22 | RocketMQLocalTransactionState executeLocalTransaction(final Message msg, final Object arg); 23 | 24 | RocketMQLocalTransactionState checkLocalTransaction(final Message msg); 25 | } 26 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQLocalTransactionState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.core; 19 | 20 | public enum RocketMQLocalTransactionState { 21 | COMMIT, 22 | ROLLBACK, 23 | UNKNOWN 24 | } 25 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQPushConsumerLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.core; 19 | 20 | import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; 21 | import org.apache.rocketmq.spring.support.RocketMQConsumerLifecycleListener; 22 | 23 | public interface RocketMQPushConsumerLifecycleListener extends RocketMQConsumerLifecycleListener { 24 | } 25 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/core/RocketMQReplyListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.core; 19 | 20 | /** 21 | * The consumer supporting request-reply should implement this interface. 22 | * 23 | * @param the type of data received by the listener 24 | * @param the type of data replying to producer 25 | */ 26 | public interface RocketMQReplyListener { 27 | /** 28 | * @param message data received by the listener 29 | * @return data replying to producer 30 | */ 31 | R onMessage(T message); 32 | } 33 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/DelayMode.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.support; 19 | 20 | public enum DelayMode { 21 | DELAY_SECONDS, 22 | DELAY_MILLISECONDS, 23 | DELIVER_TIME_MILLISECONDS, 24 | } 25 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQConsumerLifecycleListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.support; 19 | 20 | public interface RocketMQConsumerLifecycleListener { 21 | void prepareStart(final T consumer); 22 | } 23 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.spring.support; 18 | 19 | /** 20 | * Represents the RocketMQ message protocol that is used during the data exchange. 21 | */ 22 | public class RocketMQHeaders { 23 | public static final String PREFIX = "rocketmq_"; 24 | public static final String KEYS = "KEYS"; 25 | public static final String TAGS = "TAGS"; 26 | public static final String TOPIC = "TOPIC"; 27 | public static final String MESSAGE_ID = "MESSAGE_ID"; 28 | public static final String BORN_TIMESTAMP = "BORN_TIMESTAMP"; 29 | public static final String BORN_HOST = "BORN_HOST"; 30 | public static final String FLAG = "FLAG"; 31 | public static final String QUEUE_ID = "QUEUE_ID"; 32 | public static final String SYS_FLAG = "SYS_FLAG"; 33 | public static final String TRANSACTION_ID = "TRANSACTION_ID"; 34 | public static final String DELAY = "DELAY"; 35 | public static final String WAIT = "WAIT"; 36 | } 37 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQListenerContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.support; 19 | 20 | import org.springframework.beans.factory.DisposableBean; 21 | 22 | public interface RocketMQListenerContainer extends DisposableBean { 23 | 24 | } 25 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/support/RocketMQMessageConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.support; 19 | 20 | import com.fasterxml.jackson.databind.ObjectMapper; 21 | import com.fasterxml.jackson.databind.SerializationFeature; 22 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 23 | import java.util.ArrayList; 24 | import java.util.List; 25 | import org.springframework.messaging.converter.ByteArrayMessageConverter; 26 | import org.springframework.messaging.converter.CompositeMessageConverter; 27 | import org.springframework.messaging.converter.MappingJackson2MessageConverter; 28 | import org.springframework.messaging.converter.MessageConverter; 29 | import org.springframework.messaging.converter.StringMessageConverter; 30 | import org.springframework.util.ClassUtils; 31 | 32 | /** 33 | * @see MessageConverter 34 | * @see CompositeMessageConverter 35 | */ 36 | public class RocketMQMessageConverter { 37 | 38 | private static final boolean JACKSON_PRESENT; 39 | private static final boolean FASTJSON_PRESENT; 40 | 41 | static { 42 | ClassLoader classLoader = RocketMQMessageConverter.class.getClassLoader(); 43 | JACKSON_PRESENT = 44 | ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && 45 | ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); 46 | FASTJSON_PRESENT = ClassUtils.isPresent("com.alibaba.fastjson.JSON", classLoader) && 47 | ClassUtils.isPresent("com.alibaba.fastjson.support.config.FastJsonConfig", classLoader); 48 | } 49 | 50 | private final CompositeMessageConverter messageConverter; 51 | 52 | public RocketMQMessageConverter() { 53 | List messageConverters = new ArrayList<>(); 54 | ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter(); 55 | byteArrayMessageConverter.setContentTypeResolver(null); 56 | messageConverters.add(byteArrayMessageConverter); 57 | messageConverters.add(new StringMessageConverter()); 58 | if (JACKSON_PRESENT) { 59 | MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); 60 | ObjectMapper mapper = converter.getObjectMapper(); 61 | mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 62 | mapper.registerModule(new JavaTimeModule()); 63 | converter.setObjectMapper(mapper); 64 | messageConverters.add(converter); 65 | } 66 | if (FASTJSON_PRESENT) { 67 | try { 68 | messageConverters.add( 69 | (MessageConverter)ClassUtils.forName( 70 | "com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter", 71 | ClassUtils.getDefaultClassLoader()).newInstance()); 72 | } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) { 73 | //ignore this exception 74 | } 75 | } 76 | messageConverter = new CompositeMessageConverter(messageConverters); 77 | } 78 | 79 | public MessageConverter getMessageConverter() { 80 | return messageConverter; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration -------------------------------------------------------------------------------- /rocketmq-spring-boot/src/test/java/org/apache/rocketmq/spring/annotation/RocketMQMessageListenerBeanPostProcessorTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.spring.annotation; 19 | 20 | import org.apache.rocketmq.spring.autoconfigure.RocketMQAutoConfiguration; 21 | import org.apache.rocketmq.spring.core.RocketMQListener; 22 | import org.junit.Test; 23 | import org.springframework.boot.autoconfigure.AutoConfigurations; 24 | import org.springframework.boot.test.context.SpringBootTest; 25 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; 26 | import org.springframework.context.annotation.Bean; 27 | import org.springframework.context.annotation.Configuration; 28 | 29 | import static org.assertj.core.api.Assertions.assertThat; 30 | 31 | @SpringBootTest 32 | public class RocketMQMessageListenerBeanPostProcessorTest { 33 | 34 | private static final String TEST_CLASS_SIMPLE_NAME = "Receiver"; 35 | 36 | private ApplicationContextRunner runner = new ApplicationContextRunner() 37 | .withConfiguration(AutoConfigurations.of(RocketMQAutoConfiguration.class)); 38 | 39 | @Test 40 | public void testAnnotationEnhancer() { 41 | runner.withPropertyValues("rocketmq.name-server=127.0.0.1:9876"). 42 | withUserConfiguration(TestAnnotationEnhancerConfig.class, TestReceiverConfig.class). 43 | run((context) -> { 44 | // Started container failed. DefaultRocketMQListenerContainer{consumerGroup='Receiver-Custom-Consumer-Group' ** 45 | assertThat(context).getFailure().hasMessageContaining("connect to null failed"); 46 | }); 47 | 48 | } 49 | 50 | @Configuration 51 | static class TestAnnotationEnhancerConfig { 52 | @Bean 53 | public RocketMQMessageListenerBeanPostProcessor.AnnotationEnhancer consumeContainerEnhancer() { 54 | return (attrs, element) -> { 55 | if (element instanceof Class) { 56 | Class targetClass = (Class) element; 57 | String classSimpleName = targetClass.getSimpleName(); 58 | if (TEST_CLASS_SIMPLE_NAME.equals(classSimpleName)) { 59 | String consumerGroup = "Receiver-Custom-Consumer-Group"; 60 | attrs.put("consumerGroup", consumerGroup); 61 | } 62 | } 63 | return attrs; 64 | }; 65 | } 66 | } 67 | 68 | @Configuration 69 | static class TestReceiverConfig { 70 | @Bean 71 | public Object receiverListener() { 72 | return new Receiver(); 73 | } 74 | } 75 | 76 | @RocketMQMessageListener(consumerGroup = "", topic = "test") 77 | static class Receiver implements RocketMQListener { 78 | 79 | @Override 80 | public void onMessage(Object message) { 81 | 82 | } 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | org.apache.rocketmq 23 | rocketmq-v5-client-spring-boot-samples 24 | pom 25 | 2.3.2-SNAPSHOT 26 | 27 | rocketmq-v5-client-spring-boot-samples 28 | rocketmq-v5-client-spring-boot-samples 29 | 30 | 31 | rocketmq-v5-client-producer-demo 32 | rocketmq-v5-client-consume-demo 33 | rocketmq-v5-client-consume-acl-demo 34 | rocketmq-v5-client-producer-acl-demo 35 | rocketmq-v5-client-producer-simple-demo 36 | rocketmq-v5-client-consumer-simple-demo 37 | rocketmq-v5-client-consumer-push-simple-demo 38 | 39 | 40 | 41 | 1.8 42 | 1.8 43 | 1.3.0 44 | 45 | 46 | 47 | 48 | 49 | org.apache.rocketmq 50 | rocketmq-v5-client-spring-boot-starter 51 | ${project.version} 52 | 53 | 54 | commons-logging 55 | commons-logging 56 | ${commons-logging-version} 57 | 58 | 59 | 60 | 61 | 62 | 63 | org.apache.maven.plugins 64 | maven-checkstyle-plugin 65 | 2.17 66 | 67 | 68 | validate 69 | validate 70 | 71 | src/main/resources 72 | style/rmq_checkstyle.xml 73 | UTF-8 74 | true 75 | true 76 | 77 | 78 | check 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 2.1.0.RELEASE 87 | 88 | 89 | 90 | repackage 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | org.apache.rocketmq 23 | rocketmq-v5-client-spring-boot-samples 24 | 2.3.2-SNAPSHOT 25 | 26 | rocketmq-v5-client-consume-acl-demo 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot; 18 | 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | 22 | @SpringBootApplication 23 | public class ClientConsumerACLApplication { 24 | 25 | public static void main(String[] args) { 26 | SpringApplication.run(ClientConsumerACLApplication.class, args); 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.consumer; 18 | 19 | 20 | import org.apache.rocketmq.client.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.client.apis.consumer.ConsumeResult; 22 | import org.apache.rocketmq.client.apis.message.MessageView; 23 | import org.apache.rocketmq.client.core.RocketMQListener; 24 | import org.springframework.stereotype.Service; 25 | 26 | @Service 27 | @RocketMQMessageListener(accessKey = "${demo.acl.rocketmq.access-key:}", secretKey = "${demo.acl.rocketmq.secret-key:}", 28 | tag = "${demo.acl.rocketmq.tag:}", topic = "${demo.acl.rocketmq.topic:}", 29 | endpoints = "${demo.acl.rocketmq.endpoints:}", consumerGroup = "${demo.acl.rocketmq.consumer-group:}") 30 | public class ACLConsumer implements RocketMQListener { 31 | @Override 32 | public ConsumeResult consume(MessageView messageView) { 33 | System.out.println("handle my acl message:" + messageView); 34 | return ConsumeResult.SUCCESS; 35 | } 36 | } 37 | 38 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | demo.acl.rocketmq.endpoints=localhost:8081 2 | demo.acl.rocketmq.topic=normalTopic 3 | demo.acl.rocketmq.consumer-group=normalGroup 4 | demo.acl.rocketmq.access-key=RocketMQ 5 | demo.acl.rocketmq.secret-key=12345678 6 | demo.acl.rocketmq.tag=* 7 | 8 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | org.apache.rocketmq 23 | rocketmq-v5-client-spring-boot-samples 24 | 2.3.2-SNAPSHOT 25 | 26 | 27 | rocketmq-v5-client-consume-demo 28 | 29 | 30 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot; 18 | 19 | import org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration; 20 | import org.apache.rocketmq.client.core.RocketMQClientTemplate; 21 | 22 | @ExtConsumerResetConfiguration(topic = "${ext.rocketmq.topic:}") 23 | public class ExtRocketMQTemplate extends RocketMQClientTemplate { 24 | } 25 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/FifoConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.consumer; 18 | 19 | import org.apache.rocketmq.client.apis.consumer.ConsumeResult; 20 | import org.apache.rocketmq.client.apis.message.MessageView; 21 | import org.apache.rocketmq.client.annotation.RocketMQMessageListener; 22 | import org.apache.rocketmq.client.core.RocketMQListener; 23 | import org.springframework.stereotype.Service; 24 | 25 | @Service 26 | @RocketMQMessageListener(endpoints = "${demo.fifo.rocketmq.endpoints:}", topic = "${demo.fifo.rocketmq.topic:}", 27 | consumerGroup = "${demo.fifo.rocketmq.consumer-group:}", tag = "${demo.fifo.rocketmq.tag:}") 28 | public class FifoConsumer implements RocketMQListener { 29 | 30 | @Override 31 | public ConsumeResult consume(MessageView messageView) { 32 | System.out.println("handle my fifo message:" + messageView); 33 | return ConsumeResult.SUCCESS; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/TransConsumer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.consumer; 18 | 19 | 20 | import org.apache.rocketmq.client.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.client.apis.consumer.ConsumeResult; 22 | import org.apache.rocketmq.client.apis.message.MessageView; 23 | import org.apache.rocketmq.client.core.RocketMQListener; 24 | import org.springframework.stereotype.Service; 25 | 26 | @Service 27 | @RocketMQMessageListener(endpoints = "${demo.trans.rocketmq.endpoints:}", topic = "${demo.trans.rocketmq.topic:}", 28 | consumerGroup = "${demo.trans.rocketmq.consumer-group:}", tag = "${demo.trans.rocketmq.tag:}") 29 | public class TransConsumer implements RocketMQListener { 30 | public ConsumeResult consume(MessageView messageView) { 31 | System.out.println("handle my transaction message:" + messageView); 32 | return ConsumeResult.SUCCESS; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | rocketmq.simple-consumer.endpoints=localhost:8081 2 | rocketmq.simple-consumer.consumer-group=normalGroup 3 | rocketmq.simple-consumer.topic=normalTopic 4 | rocketmq.simple-consumer.tag=* 5 | rocketmq.simple-consumer.filter-expression-type=tag 6 | demo.fifo.rocketmq.endpoints=localhost:8081 7 | demo.fifo.rocketmq.topic=fifoTopic 8 | demo.fifo.rocketmq.consumer-group=fifoGroup 9 | demo.fifo.rocketmq.tag=* 10 | demo.trans.rocketmq.endpoints=localhost:8081 11 | demo.trans.rocketmq.topic=transTopic 12 | demo.trans.rocketmq.consumer-group=transGroup 13 | demo.trans.rocketmq.tag=* 14 | ext.rocketmq.topic=delayTopic 15 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-push-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-v5-client-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-v5-client-consumer-push-simple-demo 29 | 30 | 31 | 11 32 | 11 33 | UTF-8 34 | 35 | 36 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-push-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/V5PushConsumerConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import org.apache.rocketmq.client.annotation.RocketMQMessageListener; 21 | import org.apache.rocketmq.client.apis.consumer.ConsumeResult; 22 | import org.apache.rocketmq.client.apis.message.MessageView; 23 | import org.apache.rocketmq.client.core.RocketMQListener; 24 | import org.springframework.boot.CommandLineRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.SpringBootApplication; 27 | import org.springframework.stereotype.Service; 28 | 29 | @SpringBootApplication 30 | public class V5PushConsumerConsumerApplication implements CommandLineRunner { 31 | 32 | public static void main(String[] args) { 33 | SpringApplication.run(V5PushConsumerConsumerApplication.class, args); 34 | } 35 | 36 | @Override 37 | public void run(String... args) { 38 | } 39 | 40 | @Service 41 | @RocketMQMessageListener(consumerGroup="demo-group", topic="demo-topic") 42 | public class MyConsumer1 implements RocketMQListener { 43 | @Override 44 | public ConsumeResult consume(MessageView messageView) { 45 | System.out.println("received message: " + messageView); 46 | return ConsumeResult.SUCCESS; 47 | } 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-push-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.push-consumer.endpoints=localhost:8081 17 | rocketmq.push-consumer.tag=* 18 | #rocketmq.push-consumer.access-key= 19 | #rocketmq.push-consumer.secret-key= 20 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-v5-client-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-v5-client-consumer-simple-demo 29 | 30 | 31 | UTF-8 32 | 33 | 34 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/V5SimpleConsumerConsumerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import java.time.Duration; 21 | import java.util.List; 22 | import javax.annotation.Resource; 23 | import org.apache.rocketmq.client.apis.message.MessageView; 24 | import org.apache.rocketmq.client.core.RocketMQClientTemplate; 25 | import org.springframework.boot.CommandLineRunner; 26 | import org.springframework.boot.SpringApplication; 27 | import org.springframework.boot.autoconfigure.SpringBootApplication; 28 | 29 | @SpringBootApplication 30 | public class V5SimpleConsumerConsumerApplication implements CommandLineRunner { 31 | @Resource 32 | private RocketMQClientTemplate rocketMQClientTemplate; 33 | 34 | public static void main(String[] args) { 35 | SpringApplication.run(V5SimpleConsumerConsumerApplication.class, args); 36 | } 37 | 38 | @Override 39 | public void run(String... args) throws Exception { 40 | for (int i = 0; i < 10; i++) { 41 | List messageList = rocketMQClientTemplate.receive(10, Duration.ofSeconds(60)); 42 | System.out.println(messageList); 43 | } 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consumer-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.simple-consumer.endpoints=localhost:8081 17 | rocketmq.simple-consumer.consumer-group=demo-group 18 | rocketmq.simple-consumer.topic=demo-topic 19 | rocketmq.simple-consumer.tag=* 20 | #rocketmq.simple-consumer.access-key= 21 | #rocketmq.simple-consumer.secret-key= 22 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | org.apache.rocketmq 23 | rocketmq-v5-client-spring-boot-samples 24 | 2.3.2-SNAPSHOT 25 | 26 | 27 | rocketmq-v5-client-producer-acl-demo 28 | 29 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot; 18 | 19 | import org.apache.rocketmq.client.apis.ClientException; 20 | import org.apache.rocketmq.client.apis.producer.SendReceipt; 21 | import org.apache.rocketmq.client.core.RocketMQClientTemplate; 22 | import org.apache.rocketmq.samples.springboot.domain.UserMessage; 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.CommandLineRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.SpringBootApplication; 27 | import org.springframework.messaging.support.MessageBuilder; 28 | 29 | import javax.annotation.Resource; 30 | import java.nio.charset.StandardCharsets; 31 | 32 | @SpringBootApplication 33 | public class ClientProducerACLApplication implements CommandLineRunner { 34 | 35 | @Resource 36 | private RocketMQClientTemplate rocketMQClientTemplate; 37 | 38 | @Value("${rocketmq.producer.topic}") 39 | private String normalTopic; 40 | 41 | 42 | public static void main(String[] args) { 43 | SpringApplication.run(ClientProducerACLApplication.class, args); 44 | } 45 | 46 | @Override 47 | public void run(String... args) throws ClientException { 48 | testSendNormalMessage(); 49 | } 50 | 51 | void testSendNormalMessage() { 52 | SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() 53 | .setId(1).setUserName("name").setUserAge((byte) 3)); 54 | System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); 55 | 56 | sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); 57 | System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); 58 | 59 | sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); 60 | System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); 61 | 62 | sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. 63 | withPayload("test message".getBytes()).build()); 64 | System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.domain; 18 | 19 | public class UserMessage { 20 | int id; 21 | private String userName; 22 | private Byte userAge; 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public UserMessage setId(int id) { 29 | this.id = id; 30 | return this; 31 | } 32 | 33 | public String getUserName() { 34 | return userName; 35 | } 36 | 37 | public UserMessage setUserName(String userName) { 38 | this.userName = userName; 39 | return this; 40 | } 41 | 42 | public Byte getUserAge() { 43 | return userAge; 44 | } 45 | 46 | public UserMessage setUserAge(Byte userAge) { 47 | this.userAge = userAge; 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | rocketmq.producer.endpoints=localhost:8081 2 | rocketmq.producer.topic=normalTopic 3 | rocketmq.producer.access-key=RocketMQ 4 | rocketmq.producer.secret-key=12345678 5 | 6 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 20 | 4.0.0 21 | 22 | org.apache.rocketmq 23 | rocketmq-v5-client-spring-boot-samples 24 | 2.3.2-SNAPSHOT 25 | 26 | 27 | rocketmq-v5-client-producer-demo 28 | 29 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.samples.springboot.domain; 18 | 19 | public class UserMessage { 20 | int id; 21 | private String userName; 22 | private Byte userAge; 23 | 24 | public int getId() { 25 | return id; 26 | } 27 | 28 | public UserMessage setId(int id) { 29 | this.id = id; 30 | return this; 31 | } 32 | 33 | public String getUserName() { 34 | return userName; 35 | } 36 | 37 | public UserMessage setUserName(String userName) { 38 | this.userName = userName; 39 | return this; 40 | } 41 | 42 | public Byte getUserAge() { 43 | return userAge; 44 | } 45 | 46 | public UserMessage setUserAge(Byte userAge) { 47 | this.userAge = userAge; 48 | return this; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | rocketmq.producer.endpoints=localhost:8081 2 | rocketmq.producer.topic=normalTopic 3 | demo.rocketmq.fifo-topic=fifoTopic 4 | demo.rocketmq.delay-topic=delayTopic 5 | demo.rocketmq.trans-topic=transTopic 6 | demo.rocketmq.normal-topic=normalTopic 7 | demo.rocketmq.message-group=group1 -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-simple-demo/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 21 | 4.0.0 22 | 23 | org.apache.rocketmq 24 | rocketmq-v5-client-spring-boot-samples 25 | 2.3.2-SNAPSHOT 26 | 27 | 28 | rocketmq-v5-client-producer-simple-demo 29 | 30 | 31 | UTF-8 32 | 33 | 34 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-simple-demo/src/main/java/org/apache/rocketmq/samples/springboot/V5ProducerApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | 18 | package org.apache.rocketmq.samples.springboot; 19 | 20 | import javax.annotation.Resource; 21 | import org.apache.rocketmq.client.apis.producer.SendReceipt; 22 | import org.apache.rocketmq.client.core.RocketMQClientTemplate; 23 | import org.springframework.beans.factory.annotation.Value; 24 | import org.springframework.boot.CommandLineRunner; 25 | import org.springframework.boot.SpringApplication; 26 | import org.springframework.boot.autoconfigure.SpringBootApplication; 27 | 28 | @SpringBootApplication 29 | public class V5ProducerApplication implements CommandLineRunner { 30 | @Resource 31 | private RocketMQClientTemplate rocketMQClientTemplate; 32 | 33 | @Value("${rocketmq.producer.topic}") 34 | private String topic; 35 | 36 | public static void main(String[] args) { 37 | SpringApplication.run(V5ProducerApplication.class, args); 38 | } 39 | 40 | @Override 41 | public void run(String... args) { 42 | SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(topic, "Hello V5"); 43 | System.out.println(sendReceipt); 44 | } 45 | } -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-simple-demo/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | # Licensed to the Apache Software Foundation (ASF) under one or more 2 | # contributor license agreements. See the NOTICE file distributed with 3 | # this work for additional information regarding copyright ownership. 4 | # The ASF licenses this file to You under the Apache License, Version 2.0 5 | # (the "License"); you may not use this file except in compliance with 6 | # the License. You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | rocketmq.producer.endpoints=localhost:8081 17 | rocketmq.producer.topic=demo-test 18 | #rocketmq.producer.access-key= 19 | #rocketmq.producer.secret-key= -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/style/copyright/Apache.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-samples/style/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 47 | 48 | 51 | 52 | 55 | 56 | 59 | 60 | 63 | 64 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot-starter/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 18 | 19 | 4.0.0 20 | 21 | org.apache.rocketmq 22 | rocketmq-v5-client-spring-boot-parent 23 | 2.3.4-SNAPSHOT 24 | ../rocketmq-v5-client-spring-boot-parent/pom.xml 25 | 26 | 27 | rocketmq-v5-client-spring-boot-starter 28 | jar 29 | 2.3.4-SNAPSHOT 30 | 31 | rocketmq-v5-client-spring-boot-starter 32 | rocketmq-v5-client-spring-boot-starter 33 | 34 | 35 | 8 36 | 37 | 38 | 39 | 40 | org.springframework.boot 41 | spring-boot-starter 42 | 43 | 44 | org.springframework.boot 45 | spring-boot-starter-validation 46 | 47 | 48 | org.apache.rocketmq 49 | rocketmq-v5-client-spring-boot 50 | 51 | 52 | 53 | 54 | 55 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.annotation; 18 | 19 | import org.springframework.stereotype.Component; 20 | import java.lang.annotation.ElementType; 21 | import java.lang.annotation.Retention; 22 | import java.lang.annotation.RetentionPolicy; 23 | import java.lang.annotation.Target; 24 | import java.lang.annotation.Documented; 25 | 26 | @Target(ElementType.TYPE) 27 | @Retention(RetentionPolicy.RUNTIME) 28 | @Documented 29 | @Component 30 | public @interface ExtConsumerResetConfiguration { 31 | 32 | String ACCESS_KEY_PLACEHOLDER = "${rocketmq.simple-consumer.accessKey:}"; 33 | String SECRET_KEY_PLACEHOLDER = "${rocketmq.simple-consumer.secretKey:}"; 34 | String TAG_PLACEHOLDER = "${rocketmq.simple-consumer.tag:}"; 35 | String TOPIC_PLACEHOLDER = "${rocketmq.simple-consumer.topic:}"; 36 | String ENDPOINTS_PLACEHOLDER = "${rocketmq.simple-consumer.endpoints:}"; 37 | String CONSUMER_GROUP_PLACEHOLDER = "${rocketmq.simple-consumer.consumerGroup:}"; 38 | String FILTER_EXPRESSION_TYPE_PLACEHOLDER = "${rocketmq.simple-consumer.filterExpressionType:}"; 39 | 40 | /** 41 | * The component name of the Consumer configuration. 42 | */ 43 | String value() default ""; 44 | 45 | /** 46 | * The property of "access-key". 47 | */ 48 | String accessKey() default ACCESS_KEY_PLACEHOLDER; 49 | 50 | /** 51 | * The property of "secret-key". 52 | */ 53 | String secretKey() default SECRET_KEY_PLACEHOLDER; 54 | 55 | /** 56 | * Tag of consumer. 57 | */ 58 | String tag() default TAG_PLACEHOLDER; 59 | 60 | /** 61 | * Topic name of consumer. 62 | */ 63 | String topic() default TOPIC_PLACEHOLDER; 64 | 65 | /** 66 | * The access point that the SDK should communicate with. 67 | */ 68 | String endpoints() default ENDPOINTS_PLACEHOLDER; 69 | 70 | /** 71 | * The load balancing group for the simple consumer. 72 | */ 73 | String consumerGroup() default CONSUMER_GROUP_PLACEHOLDER; 74 | 75 | /** 76 | * The type of filter expression 77 | */ 78 | String filterExpressionType() default FILTER_EXPRESSION_TYPE_PLACEHOLDER; 79 | 80 | /** 81 | * The requestTimeout of client,it is 3s by default. 82 | */ 83 | int requestTimeout() default 3; 84 | 85 | /** 86 | * The max await time when receive messages from the server. 87 | */ 88 | int awaitDuration() default 5; 89 | 90 | /** 91 | * The namespace of consumer. 92 | */ 93 | String namespace() default ""; 94 | } 95 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.annotation; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | import java.lang.annotation.Documented; 26 | 27 | @Target(ElementType.TYPE) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Documented 30 | @Component 31 | public @interface ExtProducerResetConfiguration { 32 | 33 | String ACCESS_KEY_PLACEHOLDER = "${rocketmq.producer.accessKey:}"; 34 | String SECRET_KEY_PLACEHOLDER = "${rocketmq.producer.secretKey:}"; 35 | String TOPIC_PLACEHOLDER = "${rocketmq.producer.topic:}"; 36 | String ENDPOINTS_PLACEHOLDER = "${rocketmq.producer.endpoints:}"; 37 | 38 | /** 39 | * The component name of the Producer configuration. 40 | */ 41 | String value() default ""; 42 | 43 | /** 44 | * The property of "access-key". 45 | */ 46 | String accessKey() default ACCESS_KEY_PLACEHOLDER; 47 | 48 | /** 49 | * The property of "secret-key". 50 | */ 51 | String secretKey() default SECRET_KEY_PLACEHOLDER; 52 | 53 | /** 54 | * The access point that the SDK should communicate with. 55 | */ 56 | String endpoints() default ENDPOINTS_PLACEHOLDER; 57 | 58 | /** 59 | * Topic name of consumer. 60 | */ 61 | String topic() default TOPIC_PLACEHOLDER; 62 | 63 | /** 64 | * Request timeout is 3s by default. 65 | */ 66 | int requestTimeout() default 3; 67 | 68 | /** 69 | * Enable or disable the use of Secure Sockets Layer (SSL) for network transport. 70 | */ 71 | boolean sslEnabled() default true; 72 | 73 | /** 74 | * Max attempts for max internal retries of message publishing. 75 | */ 76 | int maxAttempts() default 3; 77 | 78 | /** 79 | * The namespace of producer. 80 | */ 81 | String namespace() default ""; 82 | } 83 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.annotation; 18 | 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | import java.lang.annotation.Documented; 24 | 25 | @Target(ElementType.TYPE) 26 | @Retention(RetentionPolicy.RUNTIME) 27 | @Documented 28 | public @interface RocketMQMessageListener { 29 | 30 | String ACCESS_KEY_PLACEHOLDER = "${rocketmq.push-consumer.access-key:}"; 31 | String SECRET_KEY_PLACEHOLDER = "${rocketmq.push-consumer.secret-key:}"; 32 | String ENDPOINTS_PLACEHOLDER = "${rocketmq.push-consumer.endpoints:}"; 33 | String TOPIC_PLACEHOLDER = "${rocketmq.push-consumer.topic:}"; 34 | String TAG_PLACEHOLDER = "${rocketmq.push-consumer.tag:}"; 35 | 36 | /** 37 | * The property of "access-key". 38 | */ 39 | String accessKey() default ACCESS_KEY_PLACEHOLDER; 40 | 41 | /** 42 | * The property of "secret-key". 43 | */ 44 | String secretKey() default SECRET_KEY_PLACEHOLDER; 45 | 46 | /** 47 | * The access point that the SDK should communicate with. 48 | */ 49 | String endpoints() default ENDPOINTS_PLACEHOLDER; 50 | 51 | /** 52 | * Topic name of consumer. 53 | */ 54 | String topic() default TOPIC_PLACEHOLDER; 55 | 56 | /** 57 | * Tag of consumer. 58 | */ 59 | String tag() default TAG_PLACEHOLDER; 60 | 61 | /** 62 | * The type of filter expression 63 | */ 64 | String filterExpressionType() default "tag"; 65 | 66 | /** 67 | * The load balancing group for the simple consumer. 68 | */ 69 | String consumerGroup() default ""; 70 | 71 | /** 72 | * The requestTimeout of client,it is 3s by default. 73 | */ 74 | int requestTimeout() default 3; 75 | 76 | 77 | int maxCachedMessageCount() default 1024; 78 | 79 | 80 | int maxCacheMessageSizeInBytes() default 67108864; 81 | 82 | 83 | int consumptionThreadCount() default 20; 84 | 85 | /** 86 | * The namespace of listener. 87 | */ 88 | String namespace() default ""; 89 | } 90 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.annotation; 18 | 19 | import org.springframework.stereotype.Component; 20 | 21 | import java.lang.annotation.ElementType; 22 | import java.lang.annotation.Retention; 23 | import java.lang.annotation.RetentionPolicy; 24 | import java.lang.annotation.Target; 25 | import java.lang.annotation.Documented; 26 | 27 | @Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) 28 | @Retention(RetentionPolicy.RUNTIME) 29 | @Documented 30 | @Component 31 | public @interface RocketMQTransactionListener { 32 | String rocketMQTemplateBeanName() default "rocketMQClientTemplate"; 33 | } 34 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.autoconfigure; 18 | 19 | 20 | import org.apache.rocketmq.client.support.RocketMQMessageConverter; 21 | import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; 22 | import org.springframework.context.annotation.Bean; 23 | import org.springframework.context.annotation.Configuration; 24 | 25 | /** 26 | * @see RocketMQMessageConverter 27 | */ 28 | @Configuration 29 | @ConditionalOnMissingBean(RocketMQMessageConverter.class) 30 | class MessageConverterConfiguration { 31 | 32 | @Bean 33 | public RocketMQMessageConverter createMessageConverter() { 34 | return new RocketMQMessageConverter(); 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.autoconfigure; 18 | 19 | import org.apache.rocketmq.client.annotation.RocketMQMessageListenerBeanPostProcessor; 20 | import org.springframework.beans.factory.support.BeanDefinitionRegistry; 21 | import org.springframework.beans.factory.support.RootBeanDefinition; 22 | import org.springframework.boot.autoconfigure.AutoConfigureAfter; 23 | import org.springframework.context.annotation.Configuration; 24 | import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; 25 | import org.springframework.core.type.AnnotationMetadata; 26 | 27 | @Configuration 28 | @AutoConfigureAfter(RocketMQAutoConfiguration.class) 29 | public class RocketMQListenerConfiguration implements ImportBeanDefinitionRegistrar { 30 | @Override 31 | public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { 32 | if (!registry.containsBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName())) { 33 | registry.registerBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName(), 34 | new RootBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class)); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.autoconfigure; 18 | 19 | import org.apache.rocketmq.client.annotation.RocketMQTransactionListener; 20 | import org.apache.rocketmq.client.apis.producer.TransactionChecker; 21 | import org.apache.rocketmq.client.core.RocketMQClientTemplate; 22 | import org.slf4j.Logger; 23 | import org.slf4j.LoggerFactory; 24 | import org.springframework.aop.framework.AopProxyUtils; 25 | import org.springframework.aop.scope.ScopedProxyUtils; 26 | import org.springframework.beans.BeansException; 27 | import org.springframework.beans.factory.SmartInitializingSingleton; 28 | import org.springframework.context.ApplicationContext; 29 | import org.springframework.context.ApplicationContextAware; 30 | import org.springframework.context.ConfigurableApplicationContext; 31 | import org.springframework.context.annotation.Configuration; 32 | 33 | import java.util.Map; 34 | import java.util.Objects; 35 | import java.util.stream.Collectors; 36 | 37 | @Configuration 38 | public class RocketMQTransactionConfiguration implements ApplicationContextAware, SmartInitializingSingleton { 39 | private final static Logger log = LoggerFactory.getLogger(RocketMQTransactionConfiguration.class); 40 | 41 | private ConfigurableApplicationContext applicationContext; 42 | 43 | @Override 44 | public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { 45 | this.applicationContext = (ConfigurableApplicationContext) applicationContext; 46 | } 47 | 48 | @Override 49 | public void afterSingletonsInstantiated() { 50 | Map beans = this.applicationContext.getBeansWithAnnotation(RocketMQTransactionListener.class) 51 | .entrySet().stream().filter(entry -> !ScopedProxyUtils.isScopedTarget(entry.getKey())) 52 | .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); 53 | beans.forEach(this::handleTransactionChecker); 54 | } 55 | 56 | public void handleTransactionChecker(String beanName, Object bean) { 57 | Class clazz = AopProxyUtils.ultimateTargetClass(bean); 58 | if (!TransactionChecker.class.isAssignableFrom(bean.getClass())) { 59 | throw new IllegalStateException(clazz + " is not instance of " + TransactionChecker.class.getName()); 60 | } 61 | RocketMQTransactionListener annotation = clazz.getAnnotation(RocketMQTransactionListener.class); 62 | if (Objects.isNull(annotation)) { 63 | throw new IllegalStateException("The transactionListener annotation is missing"); 64 | } 65 | RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) applicationContext.getBean(annotation.rocketMQTemplateBeanName()); 66 | if ((rocketMQTemplate.getProducerBuilder()) != null) { 67 | rocketMQTemplate.getProducerBuilder().setTransactionChecker((TransactionChecker) bean); 68 | } 69 | } 70 | 71 | } 72 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.common; 18 | 19 | public class Pair { 20 | private T1 sendReceipt; 21 | private T2 transaction; 22 | 23 | public Pair(T1 sendReceipt, T2 transaction) { 24 | this.sendReceipt = sendReceipt; 25 | this.transaction = transaction; 26 | } 27 | 28 | public T1 getSendReceipt() { 29 | return sendReceipt; 30 | } 31 | 32 | public void setLeft(T1 sendReceipt) { 33 | this.sendReceipt = sendReceipt; 34 | } 35 | 36 | public T2 getTransaction() { 37 | return transaction; 38 | } 39 | 40 | public void setTransaction(T2 transaction) { 41 | this.transaction = transaction; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.core; 18 | 19 | import org.apache.rocketmq.client.apis.consumer.ConsumeResult; 20 | import org.apache.rocketmq.client.apis.consumer.MessageListener; 21 | import org.apache.rocketmq.client.apis.message.MessageView; 22 | 23 | public interface RocketMQListener extends MessageListener { 24 | ConsumeResult consume(MessageView messageView); 25 | } 26 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.core; 18 | 19 | import org.apache.rocketmq.client.apis.message.MessageView; 20 | import org.apache.rocketmq.client.apis.producer.TransactionChecker; 21 | import org.apache.rocketmq.client.apis.producer.TransactionResolution; 22 | 23 | public interface RocketMQTransactionChecker extends TransactionChecker { 24 | TransactionResolution check(MessageView var1); 25 | } 26 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.support; 18 | 19 | import java.util.HashSet; 20 | import java.util.Set; 21 | 22 | public class RocketMQHeaders { 23 | public static final String PREFIX = "rocketmq_"; 24 | public static final String KEYS = "KEYS"; 25 | public static final String TAGS = "TAGS"; 26 | public static final String TOPIC = "TOPIC"; 27 | public static final String MESSAGE_ID = "MESSAGE_ID"; 28 | public static final String BORN_TIMESTAMP = "BORN_TIMESTAMP"; 29 | public static final String BORN_HOST = "BORN_HOST"; 30 | public static final String FLAG = "FLAG"; 31 | public static final String QUEUE_ID = "QUEUE_ID"; 32 | public static final String SYS_FLAG = "SYS_FLAG"; 33 | public static final String TRANSACTION_ID = "TRANSACTION_ID"; 34 | public static final String DELAY = "DELAY"; 35 | public static final String WAIT = "WAIT"; 36 | 37 | public static final Set SYSTEM_PROPERTY_SET = new HashSet() { 38 | { 39 | add(KEYS); 40 | add(TAGS); 41 | add(KEYS); 42 | add(TOPIC); 43 | add(MESSAGE_ID); 44 | add(BORN_TIMESTAMP); 45 | add(BORN_HOST); 46 | add(FLAG); 47 | add(QUEUE_ID); 48 | add(SYS_FLAG); 49 | add(TRANSACTION_ID); 50 | add(DELAY); 51 | add(WAIT); 52 | } 53 | }; 54 | } 55 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.support; 18 | 19 | import org.springframework.beans.factory.DisposableBean; 20 | 21 | public interface RocketMQListenerContainer extends DisposableBean { 22 | } 23 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed to the Apache Software Foundation (ASF) under one or more 3 | * contributor license agreements. See the NOTICE file distributed with 4 | * this work for additional information regarding copyright ownership. 5 | * The ASF licenses this file to You under the Apache License, Version 2.0 6 | * (the "License"); you may not use this file except in compliance with 7 | * the License. You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package org.apache.rocketmq.client.support; 18 | 19 | import com.fasterxml.jackson.databind.ObjectMapper; 20 | import com.fasterxml.jackson.databind.SerializationFeature; 21 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; 22 | import org.springframework.messaging.converter.CompositeMessageConverter; 23 | import org.springframework.messaging.converter.ByteArrayMessageConverter; 24 | import org.springframework.messaging.converter.MessageConverter; 25 | import org.springframework.messaging.converter.MappingJackson2MessageConverter; 26 | import org.springframework.messaging.converter.StringMessageConverter; 27 | import org.springframework.util.ClassUtils; 28 | 29 | import java.util.ArrayList; 30 | import java.util.List; 31 | 32 | /** 33 | * @see MessageConverter 34 | * @see CompositeMessageConverter 35 | */ 36 | public class RocketMQMessageConverter { 37 | private static final boolean JACKSON_PRESENT; 38 | private static final boolean FASTJSON_PRESENT; 39 | 40 | static { 41 | ClassLoader classLoader = RocketMQMessageConverter.class.getClassLoader(); 42 | JACKSON_PRESENT = 43 | ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && 44 | ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); 45 | FASTJSON_PRESENT = ClassUtils.isPresent("com.alibaba.fastjson.JSON", classLoader) && 46 | ClassUtils.isPresent("com.alibaba.fastjson.support.config.FastJsonConfig", classLoader); 47 | } 48 | 49 | private final CompositeMessageConverter messageConverter; 50 | 51 | public RocketMQMessageConverter() { 52 | List messageConverters = new ArrayList<>(); 53 | ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter(); 54 | byteArrayMessageConverter.setContentTypeResolver(null); 55 | messageConverters.add(byteArrayMessageConverter); 56 | messageConverters.add(new StringMessageConverter()); 57 | if (JACKSON_PRESENT) { 58 | MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); 59 | ObjectMapper mapper = converter.getObjectMapper(); 60 | mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); 61 | mapper.registerModule(new JavaTimeModule()); 62 | converter.setObjectMapper(mapper); 63 | messageConverters.add(converter); 64 | } 65 | if (FASTJSON_PRESENT) { 66 | try { 67 | messageConverters.add( 68 | (org.springframework.messaging.converter.MessageConverter) ClassUtils.forName( 69 | "com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter", 70 | ClassUtils.getDefaultClassLoader()).newInstance()); 71 | } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) { 72 | //ignore this exception 73 | } 74 | } 75 | messageConverter = new CompositeMessageConverter(messageConverters); 76 | } 77 | 78 | public org.springframework.messaging.converter.MessageConverter getMessageConverter() { 79 | return messageConverter; 80 | } 81 | 82 | 83 | } 84 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/resources/META-INF/spring.factories: -------------------------------------------------------------------------------- 1 | org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ 2 | org.apache.rocketmq.client.autoconfigure.RocketMQAutoConfiguration 3 | -------------------------------------------------------------------------------- /rocketmq-v5-client-spring-boot/src/main/resources/META-INF/spring/org.springframework.boot.autoconfigure.AutoConfiguration.imports: -------------------------------------------------------------------------------- 1 | org.apache.rocketmq.client.autoconfigure.RocketMQAutoConfiguration -------------------------------------------------------------------------------- /style/copyright/Apache.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 23 | -------------------------------------------------------------------------------- /style/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 27 | 28 | 31 | 32 | 35 | 36 | 39 | 40 | 43 | 44 | 47 | 48 | 51 | 52 | 55 | 56 | 59 | 60 | 63 | 64 | --------------------------------------------------------------------------------