From b116cf14c3b50fd6103abdf6f42af47220aca28a Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sun, 23 Apr 2023 17:40:18 +0800 Subject: [PATCH 01/13] feat:Integrate RocketMQ 5.0 client with Spring --- pom.xml | 3 + .../springboot/ClientConsumeApplication.java | 120 +++++++ .../springboot/ExtRocketMQTemplate.java | 12 + .../springboot/consumer/MyConsumer.java | 23 ++ .../springboot/ClientProducerApplication.java | 171 +++++++++ .../springboot/domain/UserMessage.java | 37 ++ .../ExtConsumerResetConfiguration.java | 74 ++++ .../ExtProducerResetConfiguration.java | 61 ++++ .../annotation/RocketMQMessageListener.java | 69 ++++ ...ketMQMessageListenerBeanPostProcessor.java | 91 +++++ .../RocketMQTransactionListener.java | 16 + .../ExtConsumerResetConfiguration.java | 137 +++++++ .../ExtTemplateResetConfiguration.java | 118 ++++++ .../ListenerContainerConfiguration.java | 95 +++++ .../MessageConverterConfiguration.java | 21 ++ .../RocketMQAutoConfiguration.java | 144 ++++++++ .../RocketMQListenerConfiguration.java | 24 ++ .../autoconfigure/RocketMQProperties.java | 287 +++++++++++++++ .../RocketMQTransactionConfiguration.java | 60 ++++ .../rocketmq/client/client/common/Pair.java | 30 ++ .../client/core/RocketMQClientTemplate.java | 337 ++++++++++++++++++ .../client/client/core/RocketMQListener.java | 12 + .../core/RocketMQTransactionChecker.java | 12 + .../support/DefaultListenerContainer.java | 331 +++++++++++++++++ .../client/support/RocketMQHeaders.java | 20 ++ .../support/RocketMQListenerContainer.java | 9 + .../support/RocketMQMessageConverter.java | 67 ++++ .../client/client/support/RocketMQUtil.java | 152 ++++++++ .../main/resources/META-INF/spring.factories | 2 + 29 files changed, 2535 insertions(+) create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java create mode 100644 rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories diff --git a/pom.xml b/pom.xml index f4659e2c..099d9052 100644 --- a/pom.xml +++ b/pom.xml @@ -215,6 +215,9 @@ rocketmq-spring-boot-parent rocketmq-spring-boot rocketmq-spring-boot-starter + rocketmq-client-spring-boot + rocketmq-client-spring-boot-parent + rocketmq-client-spring-boot-starter diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java new file mode 100644 index 00000000..60ce31d0 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java @@ -0,0 +1,120 @@ +package org.apache.rocketmq.samples.springboot; + +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.message.MessageId; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +import javax.annotation.Resource; +import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.stream.Collectors; + +@SpringBootApplication +public class ClientConsumeApplication implements CommandLineRunner { + private static final Logger log = LoggerFactory.getLogger(ClientConsumeApplication.class); + + @Resource + RocketMQClientTemplate rocketMQClientTemplate; + + @Resource(name = "extRocketMQTemplate") + RocketMQClientTemplate extRocketMQTemplate; + + public static void main(String[] args) { + SpringApplication.run(ClientConsumeApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + receiveSimpleConsumerMessage(); + receiveExtSimpleConsumerMessage(); + } + + public void receiveSimpleConsumerMessage() throws ClientException { + do { + final List messages = rocketMQClientTemplate.receive(16, Duration.ofSeconds(15)); + log.info("Received {} message(s)", messages.size()); + for (MessageView message : messages) { + log.info("receive message, topic:" + message.getTopic() + " messageId:" + message.getMessageId()); + final MessageId messageId = message.getMessageId(); + try { + rocketMQClientTemplate.ack(message); + log.info("Message is acknowledged successfully, messageId={}", messageId); + } catch (Throwable t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + } + } + } while (true); + } + + public void receiveExtSimpleConsumerMessage() throws ClientException { + do { + final List messages = extRocketMQTemplate.receive(16, Duration.ofSeconds(15)); + log.info("Received {} message(s)", messages.size()); + for (MessageView message : messages) { + log.info("receive message, topic:" + message.getTopic() + " messageId:" + message.getMessageId()); + final MessageId messageId = message.getMessageId(); + try { + rocketMQClientTemplate.ack(message); + log.info("Message is acknowledged successfully, messageId={}", messageId); + } catch (Throwable t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + } + } + } while (true); + } + + + public void receiveSimpleConsumerMessageAsynchronously() { + do { + int maxMessageNum = 16; + // Set message invisible duration after it is received. + Duration invisibleDuration = Duration.ofSeconds(15); + // Set individual thread pool for receive callback. + ExecutorService receiveCallbackExecutor = Executors.newCachedThreadPool(); + // Set individual thread pool for ack callback. + ExecutorService ackCallbackExecutor = Executors.newCachedThreadPool(); + CompletableFuture> future0; + try { + future0 = rocketMQClientTemplate.receiveAsync(maxMessageNum, invisibleDuration); + } catch (ClientException | IOException e) { + throw new RuntimeException(e); + } + future0.whenCompleteAsync(((messages, throwable) -> { + if (null != throwable) { + log.error("Failed to receive message from remote", throwable); + // Return early. + return; + } + log.info("Received {} message(s)", messages.size()); + // Using messageView as key rather than message id because message id may be duplicated. + final Map> map = + messages.stream().collect(Collectors.toMap(message -> message, rocketMQClientTemplate::ackAsync)); + for (Map.Entry> entry : map.entrySet()) { + final MessageId messageId = entry.getKey().getMessageId(); + final CompletableFuture future = entry.getValue(); + future.whenCompleteAsync((v, t) -> { + if (null != t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + // Return early. + return; + } + log.info("Message is acknowledged successfully, messageId={}", messageId); + }, ackCallbackExecutor); + } + + }), receiveCallbackExecutor); + } while (true); + } + +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java new file mode 100644 index 00000000..478fdcf5 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java @@ -0,0 +1,12 @@ +package org.apache.rocketmq.samples.springboot; + + +import org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration; +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; + +/** + * @author Akai + */ +@ExtConsumerResetConfiguration(topic = "${ext.rocketmq.topic:}") +public class ExtRocketMQTemplate extends RocketMQClientTemplate { +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java new file mode 100644 index 00000000..54d7b294 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java @@ -0,0 +1,23 @@ +package org.apache.rocketmq.samples.springboot.consumer; + + +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.client.core.RocketMQListener; +import org.springframework.stereotype.Service; + +/** + * @author Akai + */ +@Service +@RocketMQMessageListener(endpoints = "${demo.rocketmq.endpoints:}", topic = "${demo.rocketmq.topic:}", + consumerGroup = "${demo.rocketmq.consumer-group:}", tag = "${demo.rocketmq.tag:}") +public class MyConsumer implements RocketMQListener { + + @Override + public ConsumeResult consume(MessageView messageView) { + System.out.println("handle my message:" + messageView); + return ConsumeResult.SUCCESS; + } +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java new file mode 100644 index 00000000..c9f34a84 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java @@ -0,0 +1,171 @@ +package org.apache.rocketmq.samples.springboot; + +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.apis.producer.SendReceipt; +import org.apache.rocketmq.client.apis.producer.Transaction; +import org.apache.rocketmq.client.apis.producer.TransactionResolution; + +import org.apache.rocketmq.client.client.annotation.RocketMQTransactionListener; +import org.apache.rocketmq.client.client.common.Pair; +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.client.core.RocketMQTransactionChecker; +import org.apache.rocketmq.samples.springboot.domain.UserMessage; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.messaging.support.MessageBuilder; + +import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +@SpringBootApplication +public class ClientProducerApplication implements CommandLineRunner { + + private static final Logger log = LoggerFactory.getLogger(ClientProducerApplication.class); + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + + @Value("${demo.rocketmq.fifo-topic}") + private String fifoTopic; + + @Value("${demo.rocketmq.normal-topic}") + private String normalTopic; + + @Value("${demo.rocketmq.delay-topic}") + private String delayTopic; + + @Value("${demo.rocketmq.trans-topic}") + private String transTopic; + + @Value("${demo.rocketmq.message-group}") + private String messageGroup; + + + public static void main(String[] args) { + SpringApplication.run(ClientProducerApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendDelayMessage(); + testSendFIFOMessage(); + testSendNormalMessage(); + testSendTransactionMessage(); + } + + void testASycSendMessage() { + CompletableFuture future = rocketMQClientTemplate.asyncSend(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), null); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future); + + CompletableFuture future1 = rocketMQClientTemplate.asyncSend(normalTopic, "normal message", null); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future1); + + CompletableFuture future2 = rocketMQClientTemplate.asyncSend(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8), null); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future2); + + CompletableFuture future3 = rocketMQClientTemplate.asyncSend(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build(), null); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future3); + } + + void testSendDelayMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), Duration.ofSeconds(10)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, MessageBuilder. + withPayload("test message".getBytes()).build(), Duration.ofSeconds(20)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "this is my message", + Duration.ofSeconds(30)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "byte messages".getBytes(StandardCharsets.UTF_8), + Duration.ofSeconds(40)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + } + + void testSendFIFOMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, MessageBuilder. + withPayload("test message".getBytes()).build(), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, "fifo message", messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, "byte message".getBytes(StandardCharsets.UTF_8), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + } + + void testSendNormalMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build()); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + } + + void testSendTransactionMessage() throws ClientException { + Pair pair; + SendReceipt sendReceipt; + try { + pair = rocketMQClientTemplate.sendGRpcMessageInTransaction(transTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), null); + } catch (ClientException e) { + throw new RuntimeException(e); + } + sendReceipt = pair.getLeft(); + System.out.printf("transactionSend to topic %s sendReceipt=%s %n", transTopic, sendReceipt); + Transaction transaction = pair.getRight(); + // executed local transaction + if (doLocalTransaction(1)) { + transaction.commit(); + } else { + transaction.rollback(); + } + } + + @RocketMQTransactionListener + class TransactionListenerImpl implements RocketMQTransactionChecker { + @Override + public TransactionResolution check(MessageView messageView) { + if (Objects.nonNull(messageView.getProperties().get("KEY"))) { + log.info("commit transaction"); + return TransactionResolution.COMMIT; + } + log.info("rollback transaction"); + return TransactionResolution.ROLLBACK; + } + } + + boolean doLocalTransaction(int number) { + log.info("execute local transaction"); + if (number > 0) { + return true; + } + return false; + } + +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java new file mode 100644 index 00000000..88919ff1 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java @@ -0,0 +1,37 @@ +package org.apache.rocketmq.samples.springboot.domain; + +/** + * @author Akai + */ +public class UserMessage { + int id; + private String userName; + private Byte userAge; + + public int getId() { + return id; + } + + public UserMessage setId(int id) { + this.id = id; + return this; + } + + public String getUserName() { + return userName; + } + + public UserMessage setUserName(String userName) { + this.userName = userName; + return this; + } + + public Byte getUserAge() { + return userAge; + } + + public UserMessage setUserAge(Byte userAge) { + this.userAge = userAge; + return this; + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java new file mode 100644 index 00000000..41238813 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java @@ -0,0 +1,74 @@ +package org.apache.rocketmq.client.client.annotation; + +import org.springframework.stereotype.Component; + +import java.lang.annotation.*; + +/** + * @author Akai + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface ExtConsumerResetConfiguration { + + String ACCESS_KEY_PLACEHOLDER = "${rocketmq.simple-consumer.accessKey:}"; + String SECRET_KEY_PLACEHOLDER = "${rocketmq.simple-consumer.secretKey:}"; + String TAG_PLACEHOLDER = "${rocketmq.simple-consumer.tag:}"; + String TOPIC_PLACEHOLDER = "${rocketmq.simple-consumer.topic:}"; + String ENDPOINTS_PLACEHOLDER = "${rocketmq.simple-consumer.endpoints:}"; + String CONSUMER_GROUP_PLACEHOLDER = "${rocketmq.simple-consumer.consumerGroup:}"; + String FILTER_EXPRESSION_TYPE_PLACEHOLDER = "${rocketmq.simple-consumer.filterExpressionType:}"; + + /** + * The component name of the Consumer configuration. + */ + String value() default ""; + + /** + * The property of "access-key". + */ + String accessKey() default ACCESS_KEY_PLACEHOLDER; + + /** + * The property of "secret-key". + */ + String secretKey() default SECRET_KEY_PLACEHOLDER; + + /** + * Tag of consumer. + */ + String tag() default TAG_PLACEHOLDER; + + /** + * Topic name of consumer. + */ + String topic() default TOPIC_PLACEHOLDER; + + /** + * The access point that the SDK should communicate with. + */ + String endpoints() default ENDPOINTS_PLACEHOLDER; + + /** + * The load balancing group for the simple consumer. + */ + String consumerGroup() default CONSUMER_GROUP_PLACEHOLDER; + + /** + * The type of filter expression + */ + String filterExpressionType() default FILTER_EXPRESSION_TYPE_PLACEHOLDER; + + /** + * The requestTimeout of client,it is 3s by default. + */ + int requestTimeout() default 3; + + /** + * The max await time when receive messages from the server. + */ + int awaitDuration() default 0; + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java new file mode 100644 index 00000000..82380d9c --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java @@ -0,0 +1,61 @@ +package org.apache.rocketmq.client.client.annotation; + +import org.springframework.stereotype.Component; + +import java.lang.annotation.*; + +/** + * @author Akai + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface ExtProducerResetConfiguration { + + String ACCESS_KEY_PLACEHOLDER = "${rocketmq.producer.accessKey:}"; + String SECRET_KEY_PLACEHOLDER = "${rocketmq.producer.secretKey:}"; + String TOPIC_PLACEHOLDER = "${rocketmq.producer.topic:}"; + String ENDPOINTS_PLACEHOLDER = "${rocketmq.producer.endpoints:}"; + + /** + * The component name of the Producer configuration. + */ + String value() default ""; + + /** + * The property of "access-key". + */ + String accessKey() default ACCESS_KEY_PLACEHOLDER; + + /** + * The property of "secret-key". + */ + String secretKey() default SECRET_KEY_PLACEHOLDER; + + /** + * The access point that the SDK should communicate with. + */ + String endpoints() default ENDPOINTS_PLACEHOLDER; + + /** + * Topic name of consumer. + */ + String topic() default TOPIC_PLACEHOLDER; + + /** + * Request timeout is 3s by default. + */ + int requestTimeout() default 3; + + /** + * Enable or disable the use of Secure Sockets Layer (SSL) for network transport. + */ + boolean sslEnabled() default true; + + /** + * Max attempts for max internal retries of message publishing. + */ + int maxAttempts() default 3; + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java new file mode 100644 index 00000000..21796fb6 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java @@ -0,0 +1,69 @@ +package org.apache.rocketmq.client.client.annotation; + +import java.lang.annotation.*; + +/** + * @author Akai + */ +@Target(ElementType.TYPE) +@Retention(RetentionPolicy.RUNTIME) +@Documented +public @interface RocketMQMessageListener { + + String ACCESS_KEY_PLACEHOLDER = "${rocketmq.push-consumer.access-key:}"; + String SECRET_KEY_PLACEHOLDER = "${rocketmq.push-consumer.secret-key:}"; + String ENDPOINTS_PLACEHOLDER = "${rocketmq.push-consumer.endpoints:}"; + String TOPIC_PLACEHOLDER = "${rocketmq.push-consumer.endpoints:}"; + String TAG_PLACEHOLDER = "${rocketmq.push-consumer.tag:}"; + + /** + * The property of "access-key". + */ + String accessKey() default ACCESS_KEY_PLACEHOLDER; + + /** + * The property of "secret-key". + */ + String secretKey() default SECRET_KEY_PLACEHOLDER; + + /** + * The access point that the SDK should communicate with. + */ + String endpoints() default ENDPOINTS_PLACEHOLDER; + + /** + * Topic name of consumer. + */ + String topic() default TOPIC_PLACEHOLDER; + + /** + * Tag of consumer. + */ + String tag() default TAG_PLACEHOLDER; + + /** + * The type of filter expression + */ + String filterExpressionType() default "tag"; + + /** + * The load balancing group for the simple consumer. + */ + String consumerGroup(); + + /** + * The requestTimeout of client,it is 3s by default. + */ + int requestTimeout() default 3; + + + int maxCachedMessageCount() default 1024; + + + int maxCacheMessageSizeInBytes() default 67108864; + + + int consumptionThreadCount() default 20; + + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java new file mode 100644 index 00000000..c80642f8 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java @@ -0,0 +1,91 @@ +package org.apache.rocketmq.client.client.annotation; + +import org.apache.rocketmq.client.client.autoconfigure.ListenerContainerConfiguration; +import org.springframework.aop.support.AopUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.core.OrderComparator; +import org.springframework.core.annotation.AnnotationUtils; + +import java.lang.reflect.AnnotatedElement; +import java.util.List; +import java.util.Map; +import java.util.function.BiFunction; +import java.util.stream.Collectors; + +/** + * @author Akai + */ +public class RocketMQMessageListenerBeanPostProcessor implements ApplicationContextAware, BeanPostProcessor, InitializingBean { + + private ApplicationContext applicationContext; + + private AnnotationEnhancer enhancer; + + private ListenerContainerConfiguration listenerContainerConfiguration; + + @Override + public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException { + return bean; + } + + @Override + public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { + Class targetClass = AopUtils.getTargetClass(bean); + RocketMQMessageListener ann = targetClass.getAnnotation(RocketMQMessageListener.class); + if (ann != null) { + RocketMQMessageListener enhance = enhance(targetClass, ann); + if (listenerContainerConfiguration != null) { + listenerContainerConfiguration.registerContainer(beanName, bean, enhance); + } + } + return bean; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @Override + public void afterPropertiesSet() throws Exception { + buildEnhancer(); + this.listenerContainerConfiguration = this.applicationContext.getBean(ListenerContainerConfiguration.class); + } + + private void buildEnhancer() { + if (this.applicationContext != null) { + Map enhancersMap = + this.applicationContext.getBeansOfType(AnnotationEnhancer.class, false, false); + if (enhancersMap.size() > 0) { + List enhancers = enhancersMap.values() + .stream() + .sorted(new OrderComparator()) + .collect(Collectors.toList()); + this.enhancer = (attrs, element) -> { + Map newAttrs = attrs; + //遍历所有注解增强器,将前一次注解增强得到的结果作为下一个注解增强器的参数,最后返回多个注解增强器处理后的结果 + for (AnnotationEnhancer enh : enhancers) { + newAttrs = enh.apply(newAttrs, element); + } + return attrs; + }; + } + } + } + + private RocketMQMessageListener enhance(AnnotatedElement element, RocketMQMessageListener ann) { + if (this.enhancer == null) { + return ann; + } else { + return AnnotationUtils.synthesizeAnnotation( + this.enhancer.apply(AnnotationUtils.getAnnotationAttributes(ann), element), RocketMQMessageListener.class, null); + } + } + + public interface AnnotationEnhancer extends BiFunction, AnnotatedElement, Map> { + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java new file mode 100644 index 00000000..904cd742 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java @@ -0,0 +1,16 @@ +package org.apache.rocketmq.client.client.annotation; + +import org.springframework.stereotype.Component; + +import java.lang.annotation.*; + +/** + * @author Akai + */ +@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface RocketMQTransactionListener { + String rocketMQTemplateBeanName() default "rocketMQClientTemplate"; +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java new file mode 100644 index 00000000..4e2d028c --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java @@ -0,0 +1,137 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.consumer.FilterExpression; +import org.apache.rocketmq.client.apis.consumer.SimpleConsumer; +import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; + +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.AopProxyUtils; +import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.beans.factory.support.BeanDefinitionValidationException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.time.Duration; +import java.util.Collections; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author Akai + */ +@Configuration +public class ExtConsumerResetConfiguration implements ApplicationContextAware, SmartInitializingSingleton { + private static final Logger log = LoggerFactory.getLogger(ExtConsumerResetConfiguration.class); + + private ConfigurableApplicationContext applicationContext; + + private ConfigurableEnvironment environment; + + private RocketMQProperties rocketMQProperties; + + private RocketMQMessageConverter rocketMQMessageConverter; + + public ExtConsumerResetConfiguration(RocketMQMessageConverter rocketMQMessageConverter, + ConfigurableEnvironment environment, RocketMQProperties rocketMQProperties) { + this.rocketMQMessageConverter = rocketMQMessageConverter; + this.environment = environment; + this.rocketMQProperties = rocketMQProperties; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = (ConfigurableApplicationContext) applicationContext; + } + + @Override + public void afterSingletonsInstantiated() { + Map beans = this.applicationContext + .getBeansWithAnnotation(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration.class) + .entrySet().stream().filter(entry -> !ScopedProxyUtils.isScopedTarget(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + beans.forEach(this::registerTemplate); + } + + private void registerTemplate(String beanName, Object bean) { + Class clazz = AopProxyUtils.ultimateTargetClass(bean); + + if (!RocketMQClientTemplate.class.isAssignableFrom(bean.getClass())) { + throw new IllegalStateException(clazz + " is not instance of " + RocketMQClientTemplate.class.getName()); + } + org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation = clazz.getAnnotation(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration.class); + GenericApplicationContext genericApplicationContext = (GenericApplicationContext) applicationContext; + validate(annotation, genericApplicationContext); + + SimpleConsumerBuilder consumerBuilder = null; + SimpleConsumer simpleConsumer = null; + try { + consumerBuilder = createConsumer(annotation); + simpleConsumer = consumerBuilder.build(); + } catch (Exception e) { + log.error("Failed to startup SimpleConsumer for RocketMQTemplate {}", beanName, e); + } + RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) bean; + rocketMQTemplate.setSimpleConsumerBuilder(consumerBuilder); + rocketMQTemplate.setSimpleConsumer(simpleConsumer); + rocketMQTemplate.setMessageConverter(rocketMQMessageConverter.getMessageConverter()); + log.info("Set real simpleConsumer to :{} {}", beanName, annotation.value()); + } + + private SimpleConsumerBuilder createConsumer(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation) { + RocketMQProperties.SimpleConsumer simpleConsumer = rocketMQProperties.getSimpleConsumer(); + String consumerGroupName = resolvePlaceholders(annotation.consumerGroup(), simpleConsumer.getConsumerGroup()); + String topicName = resolvePlaceholders(annotation.topic(), simpleConsumer.getTopic()); + String accessKey = resolvePlaceholders(annotation.accessKey(), simpleConsumer.getAccessKey()); + String secretKey = resolvePlaceholders(annotation.secretKey(), simpleConsumer.getSecretKey()); + String endPoints = resolvePlaceholders(annotation.endpoints(), simpleConsumer.getEndpoints()); + String tag = resolvePlaceholders(annotation.tag(), simpleConsumer.getTag()); + String filterExpressionType = resolvePlaceholders(annotation.filterExpressionType(), simpleConsumer.getFilterExpressionType()); + Duration requestTimeout = Duration.ofDays(annotation.requestTimeout()); + int awaitDuration = annotation.awaitDuration(); + Assert.hasText(topicName, "[topic] must not be null"); + ClientConfiguration clientConfiguration = RocketMQUtil.createClientConfiguration(accessKey, secretKey, endPoints, requestTimeout); + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + FilterExpression filterExpression = RocketMQUtil.createFilterExpression(tag, filterExpressionType); + Duration duration = Duration.ofSeconds(awaitDuration); + SimpleConsumerBuilder simpleConsumerBuilder = provider.newSimpleConsumerBuilder(); + simpleConsumerBuilder.setClientConfiguration(clientConfiguration); + if (StringUtils.hasLength(consumerGroupName)) { + simpleConsumerBuilder.setConsumerGroup(consumerGroupName); + } + simpleConsumerBuilder.setAwaitDuration(duration); + if (Objects.nonNull(filterExpression)) { + simpleConsumerBuilder.setSubscriptionExpressions(Collections.singletonMap(topicName, filterExpression)); + } + return simpleConsumerBuilder; + } + + private String resolvePlaceholders(String text, String defaultValue) { + String value = environment.resolvePlaceholders(text); + return StringUtils.hasLength(value) ? value : defaultValue; + } + + private void validate(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation, + GenericApplicationContext genericApplicationContext) { + if (genericApplicationContext.isBeanNameInUse(annotation.value())) { + throw new BeanDefinitionValidationException( + String.format("Bean {} has been used in Spring Application Context, " + + "please check the @ExtRocketMQConsumerConfiguration", + annotation.value())); + } + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java new file mode 100644 index 00000000..75acb8a6 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java @@ -0,0 +1,118 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.annotation.ExtProducerResetConfiguration; +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.producer.ProducerBuilder; + +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.AopProxyUtils; +import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.beans.factory.support.BeanDefinitionValidationException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.util.StringUtils; + +import java.time.Duration; +import java.util.Map; +import java.util.stream.Collectors; + +/** + * @author Akai + */ +@Configuration +public class ExtTemplateResetConfiguration implements ApplicationContextAware, SmartInitializingSingleton { + + private static final Logger log = LoggerFactory.getLogger(ExtTemplateResetConfiguration.class); + + private ConfigurableApplicationContext applicationContext; + + private ConfigurableEnvironment environment; + + private RocketMQProperties rocketMQProperties; + + private RocketMQMessageConverter rocketMQMessageConverter; + + public ExtTemplateResetConfiguration(RocketMQMessageConverter rocketMQMessageConverter, + ConfigurableEnvironment environment, RocketMQProperties rocketMQProperties) { + this.rocketMQMessageConverter = rocketMQMessageConverter; + this.environment = environment; + this.rocketMQProperties = rocketMQProperties; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = (ConfigurableApplicationContext) applicationContext; + } + + + + + @Override + public void afterSingletonsInstantiated() { + Map beans = this.applicationContext.getBeansWithAnnotation(ExtProducerResetConfiguration.class) + .entrySet().stream().filter(entry -> !ScopedProxyUtils.isScopedTarget(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + beans.forEach(this::registerTemplate); + } + + private void registerTemplate(String beanName, Object bean) { + Class clazz = AopProxyUtils.ultimateTargetClass(bean); + + if (!RocketMQClientTemplate.class.isAssignableFrom(bean.getClass())) { + throw new IllegalStateException(clazz + " is not instance of " + RocketMQClientTemplate.class.getName()); + } + + ExtProducerResetConfiguration annotation = clazz.getAnnotation(ExtProducerResetConfiguration.class); + GenericApplicationContext genericApplicationContext = (GenericApplicationContext) applicationContext; + validate(annotation, genericApplicationContext); + + ProducerBuilder producerBuilder = createProducer(annotation); + RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) bean; + rocketMQTemplate.setProducerBuilder(producerBuilder); + rocketMQTemplate.setMessageConverter(rocketMQMessageConverter.getMessageConverter()); + log.info("Set real producerBuilder to :{} {}", beanName, annotation.value()); + } + + private ProducerBuilder createProducer(ExtProducerResetConfiguration annotation) { + RocketMQProperties.Producer producerConfig = rocketMQProperties.getProducer(); + if (producerConfig == null) { + producerConfig = new RocketMQProperties.Producer(); + } + String topic = environment.resolvePlaceholders(annotation.topic()); + topic = StringUtils.hasLength(topic) ? topic : producerConfig.getTopic(); + String endpoints = environment.resolvePlaceholders(annotation.endpoints()); + endpoints = StringUtils.hasLength(endpoints) ? endpoints : producerConfig.getEndpoints(); + String accessKey = environment.resolvePlaceholders(annotation.accessKey()); + accessKey = StringUtils.hasLength(accessKey) ? accessKey : producerConfig.getAccessKey(); + String secretKey = environment.resolvePlaceholders(annotation.secretKey()); + secretKey = StringUtils.hasLength(secretKey) ? secretKey : producerConfig.getSecretKey(); + int requestTimeout = annotation.requestTimeout(); + ClientConfiguration clientConfiguration = RocketMQUtil.createClientConfiguration(accessKey, secretKey, endpoints, Duration.ofDays(requestTimeout)); + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + ProducerBuilder producerBuilder = provider.newProducerBuilder() + .setClientConfiguration(clientConfiguration).setMaxAttempts(annotation.maxAttempts()) + .setTopics(topic); + return producerBuilder; + } + + private void validate(ExtProducerResetConfiguration annotation, + GenericApplicationContext genericApplicationContext) { + if (genericApplicationContext.isBeanNameInUse(annotation.value())) { + throw new BeanDefinitionValidationException(String.format("Bean {} has been used in Spring Application Context, " + + "please check the @ExtTemplateConfiguration", + annotation.value())); + } + } + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java new file mode 100644 index 00000000..e26f9f51 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java @@ -0,0 +1,95 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.client.core.RocketMQListener; +import org.apache.rocketmq.client.client.support.DefaultListenerContainer; +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.support.GenericApplicationContext; +import org.springframework.core.env.ConfigurableEnvironment; +import org.springframework.util.Assert; + +import java.time.Duration; +import java.util.concurrent.atomic.AtomicLong; + +/** + * @author Akai + */ +@Configuration +public class ListenerContainerConfiguration implements ApplicationContextAware { + private final static Logger log = LoggerFactory.getLogger(ListenerContainerConfiguration.class); + + private ConfigurableApplicationContext applicationContext; + + private AtomicLong counter = new AtomicLong(0); + + private ConfigurableEnvironment environment; + + private RocketMQProperties rocketMQProperties; + + private RocketMQMessageConverter rocketMQMessageConverter; + + public ListenerContainerConfiguration(RocketMQMessageConverter rocketMQMessageConverter, + ConfigurableEnvironment environment, RocketMQProperties rocketMQProperties) { + this.rocketMQMessageConverter = rocketMQMessageConverter; + this.environment = environment; + this.rocketMQProperties = rocketMQProperties; + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = (ConfigurableApplicationContext) applicationContext; + } + + public void registerContainer(String beanName, Object bean, RocketMQMessageListener annotation) { + validate(annotation); + String containerBeanName = String.format("%s_%s", DefaultListenerContainer.class.getName(), + counter.incrementAndGet()); + GenericApplicationContext genericApplicationContext = (GenericApplicationContext) applicationContext; + genericApplicationContext.registerBean(containerBeanName, DefaultListenerContainer.class, + () -> createRocketMQListenerContainer(containerBeanName, bean, annotation)); + DefaultListenerContainer container = genericApplicationContext.getBean(containerBeanName, + DefaultListenerContainer.class); + if (!container.isRunning()) { + try { + container.start(); + } catch (Exception e) { + log.error("Started container failed. {}", container, e); + throw new RuntimeException(e); + } + } + log.info("Register the listener to container, listenerBeanName:{}, containerBeanName:{}", beanName, containerBeanName); + } + + private DefaultListenerContainer createRocketMQListenerContainer(String name, Object bean, RocketMQMessageListener annotation) { + DefaultListenerContainer container = new DefaultListenerContainer(); + container.setName(name); + container.setRocketMQMessageListener(annotation); + container.setMessageListener((RocketMQListener) bean); + container.setAccessKey(environment.resolvePlaceholders(annotation.accessKey())); + container.setSecretKey(environment.resolvePlaceholders(annotation.secretKey())); + container.setConsumerGroup(environment.resolvePlaceholders(annotation.consumerGroup())); + container.setTag(environment.resolvePlaceholders(annotation.tag())); + container.setEndpoints(environment.resolvePlaceholders(annotation.endpoints())); + container.setTopic(environment.resolvePlaceholders(annotation.topic())); + container.setRequestTimeout(Duration.ofDays(annotation.requestTimeout())); + container.setMaxCachedMessageCount(annotation.maxCachedMessageCount()); + container.setConsumptionThreadCount(annotation.consumptionThreadCount()); + container.setMaxCacheMessageSizeInBytes(annotation.maxCacheMessageSizeInBytes()); + container.setType(annotation.filterExpressionType()); + return container; + } + + private void validate(RocketMQMessageListener annotation) { + Assert.hasText(annotation.accessKey(), "[accessKey] must not be null"); + Assert.hasText(annotation.secretKey(), "[secretKey] must not be null"); + Assert.hasText(annotation.topic(), "[topic] must not be null"); + Assert.hasText(annotation.endpoints(), "[endpoints] must not be null"); + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java new file mode 100644 index 00000000..045d518f --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java @@ -0,0 +1,21 @@ +package org.apache.rocketmq.client.client.autoconfigure; + + +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @see RocketMQMessageConverter + */ +@Configuration +@ConditionalOnMissingBean(RocketMQMessageConverter.class) +class MessageConverterConfiguration { + + @Bean + public RocketMQMessageConverter createMessageConverter() { + return new RocketMQMessageConverter(); + } + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java new file mode 100644 index 00000000..60818e24 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java @@ -0,0 +1,144 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.consumer.FilterExpression; +import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; +import org.apache.rocketmq.client.apis.producer.ProducerBuilder; +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.java.impl.producer.ProducerBuilderImpl; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.boot.autoconfigure.AutoConfigureBefore; +import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; +import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Conditional; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Import; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.time.Duration; +import java.util.Collections; +import java.util.Objects; + +/** + * @author Akai + */ +@Configuration +@EnableConfigurationProperties(RocketMQProperties.class) +@Import({MessageConverterConfiguration.class, ListenerContainerConfiguration.class, ExtTemplateResetConfiguration.class, + ExtConsumerResetConfiguration.class, RocketMQTransactionConfiguration.class, RocketMQListenerConfiguration.class}) +@AutoConfigureAfter({MessageConverterConfiguration.class}) +@AutoConfigureBefore({RocketMQTransactionConfiguration.class}) +public class RocketMQAutoConfiguration implements ApplicationContextAware { + private static final Logger log = LoggerFactory.getLogger(RocketMQAutoConfiguration.class); + public static final String ROCKETMQ_TEMPLATE_DEFAULT_GLOBAL_NAME = "rocketMQClientTemplate"; + public static final String PRODUCER_BUILDER_BEAN_NAME = "producerBuilder"; + public static final String SIMPLE_CONSUMER_BUILDER_BEAN_NAME = "simpleConsumerBuilder"; + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + /** + * description:gRPC-SDK ProducerBuilder + */ + @Bean(PRODUCER_BUILDER_BEAN_NAME) + @ConditionalOnMissingBean(ProducerBuilderImpl.class) + @ConditionalOnProperty(prefix = "rocketmq", value = {"producer.endpoints"}) + public ProducerBuilder producerBuilder(RocketMQProperties rocketMQProperties) { + RocketMQProperties.Producer rocketMQProducer = rocketMQProperties.getProducer(); + log.info("Init Producer Args: " + rocketMQProducer); + String topic = rocketMQProducer.getTopic(); + String endPoints = rocketMQProducer.getEndpoints(); + Assert.hasText(topic, "[rocketmq.producer.topic] must not be null"); + ClientConfiguration clientConfiguration = RocketMQUtil.createProducerClientConfiguration(rocketMQProducer); + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + ProducerBuilder producerBuilder; + producerBuilder = provider.newProducerBuilder() + .setClientConfiguration(clientConfiguration) + // Set the topic name(s), which is optional but recommended. It makes producer could prefetch the topic + // route before message publishing. + .setTopics(rocketMQProducer.getTopic()) + .setMaxAttempts(rocketMQProducer.getMaxAttempts()); + log.info(String.format("a producer init on proxy %s", endPoints)); + return producerBuilder; + } + + + /** + * description:gRPC-SDK SimpleConsumerBuilder + */ + @Bean(SIMPLE_CONSUMER_BUILDER_BEAN_NAME) + @ConditionalOnMissingBean(SimpleConsumerBuilder.class) + @ConditionalOnProperty(prefix = "rocketmq", value = {"simple-consumer.endpoints"}) + public SimpleConsumerBuilder simpleConsumerBuilder(RocketMQProperties rocketMQProperties) { + //此处getConsumer返回一个pushConsumer,getPullConsumer返回一个pullConsumer + RocketMQProperties.SimpleConsumer simpleConsumer = rocketMQProperties.getSimpleConsumer(); + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + String consumerGroup = simpleConsumer.getConsumerGroup(); + FilterExpression filterExpression = RocketMQUtil.createFilterExpression(simpleConsumer.getTag(), simpleConsumer.getFilterExpressionType()); + ClientConfiguration clientConfiguration = RocketMQUtil.createConsumerClientConfiguration(simpleConsumer); + SimpleConsumerBuilder simpleConsumerBuilder = provider.newSimpleConsumerBuilder() + .setClientConfiguration(clientConfiguration); + // set await duration for long-polling. + simpleConsumerBuilder.setAwaitDuration(Duration.ofSeconds(simpleConsumer.getAwaitDuration())); + + // Set the consumer group name. + if (StringUtils.hasLength(consumerGroup)) { + simpleConsumerBuilder.setConsumerGroup(consumerGroup); + } + // Set the subscription for the consumer. + if (Objects.nonNull(filterExpression)) { + simpleConsumerBuilder.setSubscriptionExpressions(Collections.singletonMap(simpleConsumer.getTopic(), filterExpression)); + } + return simpleConsumerBuilder; + } + + @Bean(destroyMethod = "destroy") + @Conditional(ProducerOrConsumerPropertyCondition.class) + @ConditionalOnMissingBean(name = ROCKETMQ_TEMPLATE_DEFAULT_GLOBAL_NAME) + public RocketMQClientTemplate rocketMQClientTemplate(RocketMQMessageConverter rocketMQMessageConverter) { + RocketMQClientTemplate rocketMQClientTemplate = new RocketMQClientTemplate(); + + if (applicationContext.containsBean(PRODUCER_BUILDER_BEAN_NAME)) { + rocketMQClientTemplate.setProducerBuilder((ProducerBuilder) applicationContext.getBean(PRODUCER_BUILDER_BEAN_NAME)); + } + if (applicationContext.containsBean(SIMPLE_CONSUMER_BUILDER_BEAN_NAME)) { + rocketMQClientTemplate.setSimpleConsumerBuilder((SimpleConsumerBuilder) applicationContext.getBean(SIMPLE_CONSUMER_BUILDER_BEAN_NAME)); + } + rocketMQClientTemplate.setMessageConverter(rocketMQMessageConverter.getMessageConverter()); + return rocketMQClientTemplate; + } + + /** + * + */ + static class ProducerOrConsumerPropertyCondition extends AnyNestedCondition { + + public ProducerOrConsumerPropertyCondition() { + super(ConfigurationPhase.REGISTER_BEAN); + } + + @ConditionalOnBean(ProducerBuilder.class) + static class DefaultMQProducerExistsCondition { + } + + @ConditionalOnBean(SimpleConsumerBuilder.class) + static class SimpleConsumerExistsCondition { + } + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java new file mode 100644 index 00000000..37587876 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java @@ -0,0 +1,24 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.annotation.RocketMQMessageListenerBeanPostProcessor; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.beans.factory.support.RootBeanDefinition; +import org.springframework.boot.autoconfigure.AutoConfigureAfter; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; +import org.springframework.core.type.AnnotationMetadata; + +/** + * @author Akai + */ +@Configuration +@AutoConfigureAfter(RocketMQAutoConfiguration.class) +public class RocketMQListenerConfiguration implements ImportBeanDefinitionRegistrar { + @Override + public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata, BeanDefinitionRegistry registry) { + if (!registry.containsBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName())) { + registry.registerBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class.getName(), + new RootBeanDefinition(RocketMQMessageListenerBeanPostProcessor.class)); + } + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java new file mode 100644 index 00000000..8851e186 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java @@ -0,0 +1,287 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * @author Akai + */ +@SuppressWarnings("WeakerAccess") +@ConfigurationProperties(prefix = "rocketmq") +public class RocketMQProperties { + + private Producer producer; + + private SimpleConsumer simpleConsumer = new SimpleConsumer(); + + public Producer getProducer() { + return producer; + } + + public void setProducer(Producer producer) { + this.producer = producer; + } + + public SimpleConsumer getSimpleConsumer() { + return simpleConsumer; + } + + public void setSimpleConsumer(SimpleConsumer simpleConsumer) { + this.simpleConsumer = simpleConsumer; + } + + public static class Producer { + + /** + * The property of "access-key". + */ + private String accessKey; + + /** + * The property of "secret-key". + */ + private String secretKey; + + /** + * The access point that the SDK should communicate with. + */ + private String endpoints; + + /** + * Topic is used to prefetch the route. + */ + private String topic; + + /** + * Request timeout is 3s by default. + */ + private int requestTimeout = 3; + + /** + * Enable or disable the use of Secure Sockets Layer (SSL) for network transport. + */ + private boolean sslEnabled = true; + + /** + * Max attempts for max internal retries of message publishing. + */ + private int maxAttempts = 3; + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getEndpoints() { + return endpoints; + } + + public void setEndpoints(String endpoints) { + this.endpoints = endpoints; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public int getRequestTimeout() { + return requestTimeout; + } + + public void setRequestTimeout(int requestTimeout) { + this.requestTimeout = requestTimeout; + } + + public boolean isSslEnabled() { + return sslEnabled; + } + + public void setSslEnabled(boolean sslEnabled) { + this.sslEnabled = sslEnabled; + } + + public int getMaxAttempts() { + return maxAttempts; + } + + public void setMaxAttempts(int maxAttempts) { + this.maxAttempts = maxAttempts; + } + + @Override + public String toString() { + return "Producer{" + + "accessKey='" + accessKey + '\'' + + ", secretKey='" + secretKey + '\'' + + ", endpoints='" + endpoints + '\'' + + ", topic='" + topic + '\'' + + ", requestTimeout=" + requestTimeout + + ", sslEnabled=" + sslEnabled + + '}'; + } + } + + public static class SimpleConsumer { + + /** + * The property of "access-key". + */ + private String accessKey; + + /** + * The property of "secret-key". + */ + private String secretKey; + + /** + * The access point that the SDK should communicate with. + */ + private String endpoints; + + /** + * The load balancing group for the simple consumer. + */ + private String consumerGroup; + + /** + * The max await time when receive messages from the server. + */ + private int awaitDuration = 0; + + /** + * Tag of consumer. + */ + private String tag; + + /** + * Topic name of consumer. + */ + private String topic; + + /** + * The requestTimeout of client,it is 3s by default. + */ + private int requestTimeout = 3; + + /** + * The type of filter expression + */ + private String filterExpressionType = "tag"; + + /** + * Enable or disable the use of Secure Sockets Layer (SSL) for network transport. + */ + private boolean sslEnabled = true; + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getEndpoints() { + return endpoints; + } + + public void setEndpoints(String endpoints) { + this.endpoints = endpoints; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + + public int getAwaitDuration() { + return awaitDuration; + } + + public void setAwaitDuration(int awaitDuration) { + this.awaitDuration = awaitDuration; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public int getRequestTimeout() { + return requestTimeout; + } + + public void setRequestTimeout(int requestTimeout) { + this.requestTimeout = requestTimeout; + } + + public boolean isSslEnabled() { + return sslEnabled; + } + + public void setSslEnabled(boolean sslEnabled) { + this.sslEnabled = sslEnabled; + } + + public String getFilterExpressionType() { + return filterExpressionType; + } + + public void setFilterExpressionType(String filterExpressionType) { + this.filterExpressionType = filterExpressionType; + } + + @Override + public String toString() { + return "SimpleConsumer{" + + "accessKey='" + accessKey + '\'' + + ", secretKey='" + secretKey + '\'' + + ", endpoints='" + endpoints + '\'' + + ", consumerGroup='" + consumerGroup + '\'' + + ", awaitDuration='" + awaitDuration + '\'' + + ", tag='" + tag + '\'' + + ", topic='" + topic + '\'' + + ", requestTimeout=" + requestTimeout + + ", filterExpressionType='" + filterExpressionType + '\'' + + ", sslEnabled=" + sslEnabled + + '}'; + } + } + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java new file mode 100644 index 00000000..f5283012 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java @@ -0,0 +1,60 @@ +package org.apache.rocketmq.client.client.autoconfigure; + +import org.apache.rocketmq.client.client.annotation.RocketMQTransactionListener; +import org.apache.rocketmq.client.apis.producer.TransactionChecker; +import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.aop.framework.AopProxyUtils; +import org.springframework.aop.scope.ScopedProxyUtils; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.SmartInitializingSingleton; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.annotation.Configuration; + +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * @author Akai + */ +@Configuration +public class RocketMQTransactionConfiguration implements ApplicationContextAware, SmartInitializingSingleton { + private final static Logger log = LoggerFactory.getLogger(RocketMQTransactionConfiguration.class); + + private ConfigurableApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = (ConfigurableApplicationContext) applicationContext; + } + + //获取被@RocketMQTransactionListener标记的类 + @Override + public void afterSingletonsInstantiated() { + Map beans = this.applicationContext.getBeansWithAnnotation(RocketMQTransactionListener.class) + .entrySet().stream().filter(entry -> !ScopedProxyUtils.isScopedTarget(entry.getKey())) + .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); + beans.forEach(this::handleTransactionChecker); + } + + public void handleTransactionChecker(String beanName, Object bean) { + Class clazz = AopProxyUtils.ultimateTargetClass(bean); + if (!TransactionChecker.class.isAssignableFrom(bean.getClass())) { + throw new IllegalStateException(clazz + " is not instance of " + TransactionChecker.class.getName()); + } + RocketMQTransactionListener annotation = clazz.getAnnotation(RocketMQTransactionListener.class); + if (Objects.isNull(annotation)) { + throw new IllegalStateException("The transactionListener annotation is missing"); + } + //获取注解上的template,默认为RocketMQGRpcTemplate + RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) applicationContext.getBean(annotation.rocketMQTemplateBeanName()); + if ((rocketMQTemplate.getProducerBuilder()) != null) { + rocketMQTemplate.getProducerBuilder().setTransactionChecker((TransactionChecker) bean); + } + } + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java new file mode 100644 index 00000000..27888e32 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java @@ -0,0 +1,30 @@ +package org.apache.rocketmq.client.client.common; + +/** + * @author Akai + */ +public class Pair { + private T1 left; + private T2 right; + + public Pair(T1 left, T2 right) { + this.left = left; + this.right = right; + } + + public T1 getLeft() { + return left; + } + + public void setLeft(T1 left) { + this.left = left; + } + + public T2 getRight() { + return right; + } + + public void setRight(T2 right) { + this.right = right; + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java new file mode 100644 index 00000000..1ecce910 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java @@ -0,0 +1,337 @@ +package org.apache.rocketmq.client.client.core; + +import org.apache.rocketmq.client.client.common.Pair; +import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.consumer.SimpleConsumer; +import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.apis.producer.Producer; +import org.apache.rocketmq.client.apis.producer.ProducerBuilder; +import org.apache.rocketmq.client.apis.producer.SendReceipt; +import org.apache.rocketmq.client.apis.producer.Transaction; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.DisposableBean; +import org.springframework.messaging.Message; +import org.springframework.messaging.MessagingException; +import org.springframework.messaging.core.AbstractMessageSendingTemplate; +import org.springframework.messaging.support.MessageBuilder; + +import java.io.IOException; +import java.time.Duration; +import java.util.List; +import java.util.Objects; +import java.util.concurrent.CompletableFuture; + +/** + * @author Akai + */ +@SuppressWarnings({"WeakerAccess", "unused"}) +public class RocketMQClientTemplate extends AbstractMessageSendingTemplate implements DisposableBean { + + private static final Logger log = LoggerFactory.getLogger(RocketMQClientTemplate.class); + + private ProducerBuilder producerBuilder; + + private SimpleConsumerBuilder simpleConsumerBuilder; + + private Producer producer; + + private SimpleConsumer simpleConsumer; + + private RocketMQMessageConverter rocketMQMessageConverter = new RocketMQMessageConverter(); + + private String charset = "UTF-8"; + + public Producer getProducer() { + if (Objects.isNull(producer)) { + try { + return producerBuilder.build(); + } catch (ClientException e) { + throw new RuntimeException(e); + } + } + return producer; + } + + public void setProducer(Producer producer) { + this.producer = producer; + } + + + public SimpleConsumer getSimpleConsumer() { + if (Objects.isNull(simpleConsumer)) { + try { + return simpleConsumerBuilder.build(); + } catch (ClientException e) { + throw new RuntimeException(e); + } + } + return simpleConsumer; + } + + public void setSimpleConsumer(SimpleConsumer simpleConsumer) { + this.simpleConsumer = simpleConsumer; + } + + public ProducerBuilder getProducerBuilder() { + return producerBuilder; + } + + public void setProducerBuilder(ProducerBuilder producerBuilder) { + this.producerBuilder = producerBuilder; + } + + public SimpleConsumerBuilder getSimpleConsumerBuilder() { + return simpleConsumerBuilder; + } + + public void setSimpleConsumerBuilder(SimpleConsumerBuilder simpleConsumerBuilder) { + this.simpleConsumerBuilder = simpleConsumerBuilder; + } + + public RocketMQMessageConverter getRocketMQMessageConverter() { + return rocketMQMessageConverter; + } + + public void setRocketMQMessageConverter(RocketMQMessageConverter rocketMQMessageConverter) { + this.rocketMQMessageConverter = rocketMQMessageConverter; + } + + public String getCharset() { + return charset; + } + + public void setCharset(String charset) { + this.charset = charset; + } + + /** + * spring容器关闭时调用 + */ + @Override + public void destroy() throws Exception { + if (Objects.nonNull(producer)) { + producer.close(); + } + if (Objects.nonNull(simpleConsumer)) { + simpleConsumer.close(); + } + } + + @Override + protected void doSend(String destination, Message message) { + SendReceipt sendReceipt = syncSendGrpcMessage(destination, message, null, null); + if (log.isDebugEnabled()) { + log.debug("send message to `{}` finished. result:{}", destination, sendReceipt); + } + } + + /** + * @param destination formats: `topicName:tags` + * @param payload the payload to be sent + * @param messageDelayTime Time for message delay + * @return SendReceipt Synchronous Task Results + */ + public SendReceipt syncSendDelayMessage(String destination, Object payload, Duration messageDelayTime) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, messageDelayTime, null); + } + + public SendReceipt syncSendDelayMessage(String destination, String payload, Duration messageDelayTime) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, messageDelayTime, null); + } + + public SendReceipt syncSendDelayMessage(String destination, byte[] payload, Duration messageDelayTime) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, messageDelayTime, null); + } + + public SendReceipt syncSendDelayMessage(String destination, Message message, Duration messageDelayTime) { + return syncSendGrpcMessage(destination, message, messageDelayTime, null); + } + + public SendReceipt syncSendFifoMessage(String destination, Object payload, String messageGroup) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, messageGroup); + } + + public SendReceipt syncSendFifoMessage(String destination, String payload, String messageGroup) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, messageGroup); + } + + public SendReceipt syncSendFifoMessage(String destination, byte[] payload, String messageGroup) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, messageGroup); + } + + public SendReceipt syncSendFifoMessage(String destination, Message message, String messageGroup) { + return syncSendGrpcMessage(destination, message, null, messageGroup); + } + + public SendReceipt syncSendNormalMessage(String destination, Object payload) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, null); + } + + public SendReceipt syncSendNormalMessage(String destination, String payload) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, null); + } + + public SendReceipt syncSendNormalMessage(String destination, Message message) { + return syncSendGrpcMessage(destination, message, null, null); + } + + public SendReceipt syncSendNormalMessage(String destination, byte[] payload) { + Message message = MessageBuilder.withPayload(payload).build(); + return syncSendGrpcMessage(destination, message, null, null); + } + + /** + * @param destination formats: `topicName:tags` + * @param message {@link Message} the message to be sent. + * @param messageDelayTime Time for message delay + * @param messageGroup message group name + * @return SendReceipt Synchronous Task Results + */ + public SendReceipt syncSendGrpcMessage(String destination, Message message, Duration messageDelayTime, String messageGroup) { + if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { + log.error("send request message failed. destination:{}, message is null ", destination); + throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); + } + SendReceipt sendReceipt = null; + try { + org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, messageGroup); + Producer grpcProducer = this.getProducer(); + try { + sendReceipt = grpcProducer.send(rocketMsg); + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + } catch (Throwable t) { + log.error("Failed to send message", t); + } + } catch (Exception e) { + log.error("send request message failed. destination:{}, message:{} ", destination, message); + throw new MessagingException(e.getMessage(), e); + } + return sendReceipt; + } + + public CompletableFuture asyncSend(String destination, Object payload, Duration messageDelayTime) { + Message message = MessageBuilder.withPayload(payload).build(); + return asyncSend(destination, message, messageDelayTime); + } + + public CompletableFuture asyncSend(String destination, String payload, Duration messageDelayTime) { + Message message = MessageBuilder.withPayload(payload).build(); + return asyncSend(destination, message, messageDelayTime); + } + + public CompletableFuture asyncSend(String destination, byte[] payload, Duration messageDelayTime){ + Message message = MessageBuilder.withPayload(payload).build(); + return asyncSend(destination, message, messageDelayTime); + } + + /** + * 发送异步任务 + */ + public CompletableFuture asyncSend(String destination, Message message, Duration messageDelayTime) { + if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { + log.error("send request message failed. destination:{}, message is null ", destination); + throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); + } + final CompletableFuture future; + Producer grpcProducer = this.getProducer(); + try { + org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, null); + future = grpcProducer.sendAsync(rocketMsg); + } catch (Exception e) { + log.error("send request message failed. destination:{}, message:{} ", destination, message); + throw new MessagingException(e.getMessage(), e); + } + return future; + } + + public Pair sendGRpcMessageInTransaction(String destination, Object payload, Duration messageDelayTime) throws ClientException { + Message message = MessageBuilder.withPayload(payload).build(); + return sendTransactionMessage(destination, message, messageDelayTime); + } + + public Pair sendGRpcMessageInTransaction(String destination, String payload, Duration messageDelayTime) throws ClientException { + Message message = MessageBuilder.withPayload(payload).build(); + return sendTransactionMessage(destination, message, messageDelayTime); + } + + public Pair sendGRpcMessageInTransaction(String destination, byte[] payload, Duration messageDelayTime) throws ClientException { + Message message = MessageBuilder.withPayload(payload).build(); + return sendTransactionMessage(destination, message, messageDelayTime); + } + + /** + * @param destination formats: `topicName:tags` + * @param message {@link Message} the message to be sent. + * @param messageDelayTime Time for message delay + * @return CompletableFuture Asynchronous Task Results + */ + public Pair sendTransactionMessage(String destination, Message message, Duration messageDelayTime) throws ClientException { + if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { + log.error("send request message failed. destination:{}, message is null ", destination); + throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); + } + final SendReceipt sendReceipt; + Producer grpcProducer = this.getProducer(); + org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, null); + final Transaction transaction; + try { + transaction = grpcProducer.beginTransaction(); + sendReceipt = grpcProducer.send(rocketMsg, transaction); + log.info("Send transaction message successfully, messageId={}", sendReceipt.getMessageId()); + } catch (ClientException e) { + log.error("send request message failed. destination:{}, message:{} ", destination, message); + throw new RuntimeException(e); + } + return new Pair<>(sendReceipt, transaction); + } + + + //SimpleConsumer同步接收消息 + public List receive(int maxMessageNum, Duration invisibleDuration) throws ClientException { + SimpleConsumer simpleConsumer = this.getSimpleConsumer(); + return simpleConsumer.receive(maxMessageNum, invisibleDuration); + } + + + //SimpleConsumer异步接收消息 + public CompletableFuture> receiveAsync(int maxMessageNum, Duration invisibleDuration) throws ClientException, IOException { + SimpleConsumer simpleConsumer = this.getSimpleConsumer(); + CompletableFuture> listCompletableFuture = simpleConsumer.receiveAsync(maxMessageNum, invisibleDuration); + simpleConsumer.close(); + return listCompletableFuture; + } + + + //抛出异常,让用户捕获,自定义异常处理逻辑 + public void ack(MessageView message) throws ClientException { + SimpleConsumer simpleConsumer = this.getSimpleConsumer(); + simpleConsumer.ack(message); + } + + + public CompletableFuture ackAsync(MessageView messageView) { + SimpleConsumer simpleConsumer = this.getSimpleConsumer(); + return simpleConsumer.ackAsync(messageView); + } + + + private org.apache.rocketmq.client.apis.message.Message createRocketMQMessage(String destination, Message message, Duration messageDelayTime, String messageGroup) { + Message msg = this.doConvert(message.getPayload(), message.getHeaders(), null); + return RocketMQUtil.convertToClientMessage(getMessageConverter(), charset, + destination, msg, messageDelayTime, messageGroup); + } + + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java new file mode 100644 index 00000000..15a7b168 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java @@ -0,0 +1,12 @@ +package org.apache.rocketmq.client.client.core; + +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.consumer.MessageListener; +import org.apache.rocketmq.client.apis.message.MessageView; + +/** + * @author Akai + */ +public interface RocketMQListener extends MessageListener { + ConsumeResult consume(MessageView messageView); +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java new file mode 100644 index 00000000..6cbc114c --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java @@ -0,0 +1,12 @@ +package org.apache.rocketmq.client.client.core; + +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.apis.producer.TransactionChecker; +import org.apache.rocketmq.client.apis.producer.TransactionResolution; + +/** + * @author Akai + */ +public interface RocketMQTransactionChecker extends TransactionChecker { + TransactionResolution check(MessageView var1); +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java new file mode 100644 index 00000000..797da37f --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java @@ -0,0 +1,331 @@ +package org.apache.rocketmq.client.client.support; + +import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.consumer.*; +import org.apache.rocketmq.client.client.core.RocketMQListener; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.InitializingBean; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.SmartLifecycle; +import org.springframework.util.Assert; +import org.springframework.util.StringUtils; + +import java.io.IOException; +import java.time.Duration; +import java.util.Collections; +import java.util.Objects; + +/** + * @author Akai + */ +public class DefaultListenerContainer implements InitializingBean, + RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { + private final static Logger log = LoggerFactory.getLogger(DefaultListenerContainer.class); + + private ApplicationContext applicationContext; + + /** + * The name of the DefaultRocketMQListenerContainer instance + */ + private String name; + + private boolean running; + + private PushConsumer pushConsumer; + + private PushConsumerBuilder pushConsumerBuilder; + + private RocketMQListener rocketMQListener; + + private RocketMQMessageListener rocketMQMessageListener; + + String accessKey; + + String secretKey; + + String endpoints; + + String consumerGroup; + + String tag; + + String topic; + + String type; + + FilterExpressionType filterExpressionType; + + Duration requestTimeout; + + int maxCachedMessageCount = 1024; + + int maxCacheMessageSizeInBytes = 67108864; + + int consumptionThreadCount = 20; + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + @Override + public boolean isRunning() { + return running; + } + + public void setRunning(boolean running) { + this.running = running; + } + + public PushConsumer getPushConsumer() { + return pushConsumer; + } + + public void setPushConsumer(PushConsumer pushConsumer) { + this.pushConsumer = pushConsumer; + } + + public PushConsumerBuilder getPushConsumerBuilder() { + return pushConsumerBuilder; + } + + public void setPushConsumerBuilder(PushConsumerBuilder pushConsumerBuilder) { + this.pushConsumerBuilder = pushConsumerBuilder; + } + + public String getAccessKey() { + return accessKey; + } + + public void setAccessKey(String accessKey) { + this.accessKey = accessKey; + } + + public String getSecretKey() { + return secretKey; + } + + public void setSecretKey(String secretKey) { + this.secretKey = secretKey; + } + + public String getEndpoints() { + return endpoints; + } + + public void setEndpoints(String endpoints) { + this.endpoints = endpoints; + } + + public String getConsumerGroup() { + return consumerGroup; + } + + public void setConsumerGroup(String consumerGroup) { + this.consumerGroup = consumerGroup; + } + + public String getTag() { + return tag; + } + + public void setTag(String tag) { + this.tag = tag; + } + + public String getTopic() { + return topic; + } + + public void setTopic(String topic) { + this.topic = topic; + } + + public Duration getRequestTimeout() { + return requestTimeout; + } + + public void setRequestTimeout(Duration requestTimeout) { + this.requestTimeout = requestTimeout; + } + + public FilterExpressionType getFilterExpressionType() { + return filterExpressionType; + } + + public void setFilterExpressionType(FilterExpressionType filterExpressionType) { + this.filterExpressionType = filterExpressionType; + } + + public int getMaxCachedMessageCount() { + return maxCachedMessageCount; + } + + public void setMaxCachedMessageCount(int maxCachedMessageCount) { + this.maxCachedMessageCount = maxCachedMessageCount; + } + + public int getMaxCacheMessageSizeInBytes() { + return maxCacheMessageSizeInBytes; + } + + public void setMaxCacheMessageSizeInBytes(int maxCacheMessageSizeInBytes) { + this.maxCacheMessageSizeInBytes = maxCacheMessageSizeInBytes; + } + + public int getConsumptionThreadCount() { + return consumptionThreadCount; + } + + public void setConsumptionThreadCount(int consumptionThreadCount) { + this.consumptionThreadCount = consumptionThreadCount; + } + + public RocketMQListener getMessageListener() { + return rocketMQListener; + } + + public void setMessageListener(RocketMQListener rocketMQListener) { + this.rocketMQListener = rocketMQListener; + } + + public RocketMQMessageListener getRocketMQMessageListener() { + return rocketMQMessageListener; + } + + public void setRocketMQMessageListener(RocketMQMessageListener rocketMQMessageListener) { + this.rocketMQMessageListener = rocketMQMessageListener; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + private void initRocketMQPushConsumer() { + if (rocketMQMessageListener == null) { + throw new IllegalArgumentException("Property 'rocketMQMessageListener' is required"); + } + Assert.notNull(consumerGroup, "Property 'consumerGroup' is required"); + Assert.notNull(topic, "Property 'topic' is required"); + Assert.notNull(tag, "Property 'tag' is required"); + FilterExpression filterExpression = null; + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + if (StringUtils.hasLength(this.getTag())) { + filterExpression = RocketMQUtil.createFilterExpression(this.getTag(),this.getType()); + } + ClientConfiguration clientConfiguration = RocketMQUtil.createClientConfiguration(this.getAccessKey(), this.getSecretKey(), this.getEndpoints(), this.getRequestTimeout()); + + PushConsumerBuilder pushConsumerBuilder = provider.newPushConsumerBuilder() + .setClientConfiguration(clientConfiguration); + // Set the consumer group name. + if (StringUtils.hasLength(this.getConsumerGroup())) { + pushConsumerBuilder.setConsumerGroup(this.getConsumerGroup()); + } + // Set the subscription for the consumer. + if (StringUtils.hasLength(this.getTopic()) && Objects.nonNull(filterExpression)) { + pushConsumerBuilder.setSubscriptionExpressions(Collections.singletonMap(this.getTopic(), filterExpression)); + } + pushConsumerBuilder + .setConsumptionThreadCount(this.getConsumptionThreadCount()) + .setMaxCacheMessageSizeInBytes(this.getMaxCacheMessageSizeInBytes()) + .setMaxCacheMessageCount(this.getMaxCachedMessageCount()) + .setMessageListener(rocketMQListener); + this.setPushConsumerBuilder(pushConsumerBuilder); + } + + + @Override + public boolean isAutoStartup() { + return true; + } + + @Override + public void stop(Runnable callback) { + stop(); + callback.run(); + } + + @Override + public void destroy() throws Exception { + this.setRunning(false); + if (Objects.nonNull(pushConsumer)) { + pushConsumer.close(); + } + log.info("container destroyed, {}", this.toString()); + } + + @Override + public void stop() { + if (this.isRunning()) { + if (Objects.nonNull(pushConsumer)) { + try { + pushConsumer.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + setRunning(false); + } + } + + @Override + public void start() { + if (this.isRunning()) { + throw new IllegalStateException("container already running. " + name); + } + if (Objects.nonNull(pushConsumer)) { + throw new IllegalStateException("consumer has been build. " + name); + } + try { + this.pushConsumer = pushConsumerBuilder.build(); + } catch (Exception e) { + throw new IllegalStateException("Failed to start RocketMQ push consumer", e); + } + this.setRunning(true); + + log.info("running container: {}", this.toString()); + } + + + @Override + public void afterPropertiesSet() throws Exception { + initRocketMQPushConsumer(); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } + + @Override + public String toString() { + return "DefaultListenerContainer{" + + "name='" + name + '\'' + + ", running=" + running + + ", accessKey='" + accessKey + '\'' + + ", secretKey='" + secretKey + '\'' + + ", endpoints='" + endpoints + '\'' + + ", consumerGroup='" + consumerGroup + '\'' + + ", tag='" + tag + '\'' + + ", topic='" + topic + '\'' + + ", type='" + type + '\'' + + ", filterExpressionType=" + filterExpressionType + + ", requestTimeout=" + requestTimeout + + ", maxCachedMessageCount=" + maxCachedMessageCount + + ", maxCacheMessageSizeInBytes=" + maxCacheMessageSizeInBytes + + ", consumptionThreadCount=" + consumptionThreadCount + + '}'; + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java new file mode 100644 index 00000000..2edb1bec --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java @@ -0,0 +1,20 @@ +package org.apache.rocketmq.client.client.support; + +/** + * @author Akai + */ +public class RocketMQHeaders { + public static final String PREFIX = "rocketmq_"; + public static final String KEYS = "KEYS"; + public static final String TAGS = "TAGS"; + public static final String TOPIC = "TOPIC"; + public static final String MESSAGE_ID = "MESSAGE_ID"; + public static final String BORN_TIMESTAMP = "BORN_TIMESTAMP"; + public static final String BORN_HOST = "BORN_HOST"; + public static final String FLAG = "FLAG"; + public static final String QUEUE_ID = "QUEUE_ID"; + public static final String SYS_FLAG = "SYS_FLAG"; + public static final String TRANSACTION_ID = "TRANSACTION_ID"; + public static final String DELAY = "DELAY"; + public static final String WAIT = "WAIT"; +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java new file mode 100644 index 00000000..5fe89527 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java @@ -0,0 +1,9 @@ +package org.apache.rocketmq.client.client.support; + +import org.springframework.beans.factory.DisposableBean; + +/** + * @author Akai + */ +public interface RocketMQListenerContainer extends DisposableBean { +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java new file mode 100644 index 00000000..ea1aef70 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java @@ -0,0 +1,67 @@ +package org.apache.rocketmq.client.client.support; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.SerializationFeature; +import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; +import org.springframework.messaging.converter.*; +import org.springframework.util.ClassUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * @see MessageConverter + * @see CompositeMessageConverter + */ +public class RocketMQMessageConverter { + private static final boolean JACKSON_PRESENT; + private static final boolean FASTJSON_PRESENT; + + //用于检测当前项目中是否有使用到 Jackson 或 FastJson 这些 JSON 序列化/反序列化相关的类和配置 + static { + // 获取 RocketMQMessageConverter 类的类加载器,即用于加载 RocketMQMessageConverter 类的类加载器 + ClassLoader classLoader = RocketMQMessageConverter.class.getClassLoader(); + // 判断是否存在 Jackson 相关的类和配置,包括 com.fasterxml.jackson.databind.ObjectMapper 和 com.fasterxml.jackson.core.JsonGenerator + JACKSON_PRESENT = + ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && + ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); + // 判断是否存在 FastJson 相关的类和配置,包括 com.alibaba.fastjson.JSON 和 com.alibaba.fastjson.support.config.FastJsonConfig + FASTJSON_PRESENT = ClassUtils.isPresent("com.alibaba.fastjson.JSON", classLoader) && + ClassUtils.isPresent("com.alibaba.fastjson.support.config.FastJsonConfig", classLoader); + } + + private final CompositeMessageConverter messageConverter; + + public RocketMQMessageConverter() { + List messageConverters = new ArrayList<>(); + ByteArrayMessageConverter byteArrayMessageConverter = new ByteArrayMessageConverter(); + byteArrayMessageConverter.setContentTypeResolver(null); + messageConverters.add(byteArrayMessageConverter); + messageConverters.add(new StringMessageConverter()); + if (JACKSON_PRESENT) { + MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter(); + ObjectMapper mapper = converter.getObjectMapper(); + mapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS); + mapper.registerModule(new JavaTimeModule()); + converter.setObjectMapper(mapper); + messageConverters.add(converter); + } + if (FASTJSON_PRESENT) { + try { + messageConverters.add( + (org.springframework.messaging.converter.MessageConverter) ClassUtils.forName( + "com.alibaba.fastjson.support.spring.messaging.MappingFastJsonMessageConverter", + ClassUtils.getDefaultClassLoader()).newInstance()); + } catch (ClassNotFoundException | IllegalAccessException | InstantiationException ignored) { + //ignore this exception + } + } + messageConverter = new CompositeMessageConverter(messageConverters); + } + + public org.springframework.messaging.converter.MessageConverter getMessageConverter() { + return messageConverter; + } + + + } diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java new file mode 100644 index 00000000..7054052e --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java @@ -0,0 +1,152 @@ +package org.apache.rocketmq.client.client.support; + +import org.apache.rocketmq.client.client.autoconfigure.RocketMQProperties; +import org.apache.rocketmq.client.apis.*; +import org.apache.rocketmq.client.apis.consumer.FilterExpression; +import org.apache.rocketmq.client.apis.consumer.FilterExpressionType; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.messaging.MessageHeaders; +import org.springframework.messaging.converter.MessageConverter; +import org.springframework.util.ObjectUtils; +import org.springframework.util.StringUtils; + +import java.nio.charset.Charset; +import java.time.Duration; +import java.util.Objects; + +/** + * @author Akai + */ +public class RocketMQUtil { + + private static final Logger log = LoggerFactory.getLogger(RocketMQUtil.class); + + public static org.apache.rocketmq.client.apis.message.Message convertToClientMessage( + MessageConverter messageConverter, String charset, + String destination, org.springframework.messaging.Message message, Duration messageDelayTime, String messageGroup) { + Object payloadObject = message.getPayload(); + byte[] payloads; + try { + payloads = getPayloadBytes(payloadObject, messageConverter, charset, message); + } catch (Exception e) { + throw new RuntimeException("convert to gRPC message failed.", e); + } + return getAndWrapMessage(destination, message.getHeaders(), payloads, messageDelayTime, messageGroup); + } + + public static org.apache.rocketmq.client.apis.message.Message getAndWrapMessage( + String destination, MessageHeaders headers, byte[] payloads, Duration messageDelayTime, String messageGroup) { + if (payloads == null || payloads.length < 1) { + return null; + } + if (destination == null || destination.length() < 1) { + return null; + } + String[] tempArr = destination.split(":", 2); + final ClientServiceProvider provider = ClientServiceProvider.loadService(); + org.apache.rocketmq.client.apis.message.MessageBuilder messageBuilder = null; + // resolve header + if (Objects.nonNull(headers) && !headers.isEmpty()) { + Object keys = headers.get(RocketMQHeaders.KEYS); + if (ObjectUtils.isEmpty(keys)) { + keys = headers.get(toRocketHeaderKey(RocketMQHeaders.KEYS)); + } + messageBuilder = provider.newMessageBuilder() + .setTopic(tempArr[0]); + if (tempArr.length > 1) { + messageBuilder.setTag(tempArr[1]); + } + if (StringUtils.hasLength(messageGroup)) { + messageBuilder.setMessageGroup(messageGroup); + } + if (!ObjectUtils.isEmpty(keys)) { + messageBuilder.setKeys(keys.toString()); + } + if (Objects.nonNull(messageDelayTime)) { + messageBuilder.setDeliveryTimestamp(System.currentTimeMillis() + messageDelayTime.toMillis()); + } + messageBuilder.setBody(payloads); + org.apache.rocketmq.client.apis.message.MessageBuilder builder = messageBuilder; + headers.entrySet().stream().forEach(entry -> builder.addProperty(entry.getKey(), String.valueOf(entry.getValue()))); + messageBuilder = builder; + } + return messageBuilder.build(); + } + + public static byte[] getPayloadBytes(Object payloadObj, MessageConverter messageConverter, String charset, org.springframework.messaging.Message message) { + byte[] payloads; + if (null == payloadObj) { + throw new RuntimeException("the message cannot be empty"); + } + if (payloadObj instanceof String) { + payloads = ((String) payloadObj).getBytes(Charset.forName(charset)); + } else if (payloadObj instanceof byte[]) { + payloads = (byte[]) message.getPayload(); + } else { + String jsonObj = (String) messageConverter.fromMessage(message, payloadObj.getClass()); + if (null == jsonObj) { + throw new RuntimeException(String.format( + "empty after conversion [messageConverter:%s,payloadClass:%s,payloadObj:%s]", + messageConverter.getClass(), payloadObj.getClass(), payloadObj)); + } + payloads = jsonObj.getBytes(Charset.forName(charset)); + } + return payloads; + } + + public static String toRocketHeaderKey(String rawKey) { + return RocketMQHeaders.PREFIX + rawKey; + } + + public static ClientConfiguration createProducerClientConfiguration(RocketMQProperties.Producer rocketMQProducer) { + String accessKey = rocketMQProducer.getAccessKey(); + String secretKey = rocketMQProducer.getSecretKey(); + String endPoints = rocketMQProducer.getEndpoints(); + Duration requestTimeout = Duration.ofDays(rocketMQProducer.getRequestTimeout()); + // boolean sslEnabled = rocketMQProducer.isSslEnabled(); + return createClientConfiguration(accessKey, secretKey, endPoints, requestTimeout); + } + + public static ClientConfiguration createConsumerClientConfiguration(RocketMQProperties.SimpleConsumer simpleConsumer) { + String accessKey = simpleConsumer.getAccessKey(); + String secretKey = simpleConsumer.getSecretKey(); + String endPoints = simpleConsumer.getEndpoints(); + Duration requestTimeout = Duration.ofDays(simpleConsumer.getRequestTimeout()); + // boolean sslEnabled = rocketMQProducer.isSslEnabled(); + return createClientConfiguration(accessKey, secretKey, endPoints, requestTimeout); + + } + + public static ClientConfiguration createClientConfiguration(String accessKey, String secretKey, String endPoints, Duration requestTimeout) { + + SessionCredentialsProvider sessionCredentialsProvider = null; + if (StringUtils.hasLength(accessKey) && StringUtils.hasLength(secretKey)) { + sessionCredentialsProvider = + new StaticSessionCredentialsProvider(accessKey, secretKey); + } + ClientConfigurationBuilder clientConfigurationBuilder = ClientConfiguration.newBuilder() + .setEndpoints(endPoints); + if (sessionCredentialsProvider != null) { + clientConfigurationBuilder.setCredentialProvider(sessionCredentialsProvider); + } + if (Objects.nonNull(requestTimeout)) { + clientConfigurationBuilder.setRequestTimeout(requestTimeout); + } + return clientConfigurationBuilder.build(); + } + + + public static FilterExpression createFilterExpression(String tag, String type) { + if (!StringUtils.hasLength(tag) && !StringUtils.hasLength(type)) { + log.info("no filterExpression generate"); + return null; + } + if (!"tag".equalsIgnoreCase(type) && !"sql92".equalsIgnoreCase(type)) { + log.info("do not support your filterExpressionType {}", type); + } + FilterExpressionType filterExpressionType = "tag".equalsIgnoreCase(type) ? FilterExpressionType.TAG : FilterExpressionType.SQL92; + FilterExpression filterExpression= new FilterExpression(tag, filterExpressionType); + return filterExpression; + } +} diff --git a/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories b/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories new file mode 100644 index 00000000..ed8d45d4 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories @@ -0,0 +1,2 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ +org.apache.rocketmq.client.client.autoconfigure.RocketMQAutoConfiguration From 54059faf757cc51741e6e832ac0b2dc2961ba7b3 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Fri, 5 May 2023 09:57:01 +0800 Subject: [PATCH 02/13] feat:Integrate RocketMQ 5.0 client with Spring --- rocketmq-client-spring-boot-parent/pom.xml | 187 ++++++++++++++++++ rocketmq-client-spring-boot-samples/pom.xml | 72 +++++++ .../rocketmq-client-consume-demo/pom.xml | 13 ++ .../src/main/resources/application.properties | 10 + .../rocketmq-client-producer-demo/pom.xml | 13 ++ .../src/main/resources/application.properties | 7 + rocketmq-client-spring-boot-starter/pom.xml | 38 ++++ rocketmq-client-spring-boot/pom.xml | 84 ++++++++ 8 files changed, 424 insertions(+) create mode 100644 rocketmq-client-spring-boot-parent/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties create mode 100644 rocketmq-client-spring-boot-starter/pom.xml create mode 100644 rocketmq-client-spring-boot/pom.xml diff --git a/rocketmq-client-spring-boot-parent/pom.xml b/rocketmq-client-spring-boot-parent/pom.xml new file mode 100644 index 00000000..8045ee74 --- /dev/null +++ b/rocketmq-client-spring-boot-parent/pom.xml @@ -0,0 +1,187 @@ + + + + + 4.0.0 + + org.apache.rocketmq + rocketmq-spring-all + 2.2.4-SNAPSHOT + ../pom.xml + + + rocketmq-client-spring-boot-parent + pom + 2.2.4-SNAPSHOT + + rocketmq-client-spring-boot-parent + rocketmq-client-spring-boot-parent + + + ${project.basedir}/.. + 2.5.9 + 5.3.20 + + 2.2.4-SNAPSHOT + 5.1.0 + 1.7.25 + 2.11.1 + 1.2.83 + 4.13.2 + 5.0.5 + 1.8 + @ + + UTF-8 + UTF-8 + ${java.version} + ${java.version} + -Xdoclint:none + jacoco + + ${project.basedir}/../test/target/jacoco-it.exec + file:**/generated-sources/**,**/test/** + + + + + + org.springframework.boot + spring-boot + ${spring.boot.version} + + + + org.springframework.boot + spring-boot-autoconfigure + ${spring.boot.version} + + + + org.springframework.boot + spring-boot-autoconfigure-processor + ${spring.boot.version} + + + + org.springframework.boot + spring-boot-configuration-processor + ${spring.boot.version} + + + + org.springframework.boot + spring-boot-starter-test + ${spring.boot.version} + test + + + + org.springframework.boot + spring-boot-starter + ${spring.boot.version} + + + + org.springframework.boot + spring-boot-starter-validation + ${spring.boot.version} + + + + org.apache.rocketmq + rocketmq-client-spring-boot + ${rocketmq.client.spring.boot.version} + + + + org.apache.rocketmq + rocketmq-client-java + ${rocketmq.spring.client.version} + + + org.slf4j + slf4j-api + + + + + + org.apache.rocketmq + rocketmq-acl + ${rocketmq.version} + + + + org.springframework + spring-messaging + ${spring.version} + + + + org.springframework + spring-core + ${spring.version} + + + + org.springframework + spring-context + ${spring.version} + + + + org.springframework + spring-aop + ${spring.version} + + + + org.slf4j + slf4j-api + ${slf4j.version} + + + + com.fasterxml.jackson.core + jackson-databind + ${jackson.version} + + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + ${jackson.version} + + + + com.alibaba + fastjson + ${fastjson.version} + + + + junit + junit + ${junit.version} + + + + + diff --git a/rocketmq-client-spring-boot-samples/pom.xml b/rocketmq-client-spring-boot-samples/pom.xml new file mode 100644 index 00000000..8bbcdb67 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/pom.xml @@ -0,0 +1,72 @@ + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-samples + pom + 2.2.3-SNAPSHOT + + rocketmq-grpc-spring-boot-samples + rocketmq-client-spring-boot-samples + + + rocketmq-client-producer-demo + rocketmq-client-consume-demo + + + + 1.8 + 1.8 + 2.2.4-SNAPSHOT + + + + + + org.apache.rocketmq + rocketmq-client-spring-boot-starter + ${rocketmq-client-spring-boot-starter-version} + + + + + + + org.apache.maven.plugins + maven-checkstyle-plugin + 2.17 + + + validate + validate + + src/main/resources + style/rmq_checkstyle.xml + UTF-8 + true + true + + + check + + + + + + org.springframework.boot + spring-boot-maven-plugin + 2.1.0.RELEASE + + + + repackage + + + + + + + + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml new file mode 100644 index 00000000..1874a593 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-samples + 2.2.3-SNAPSHOT + + + rocketmq-client-consume-demo + + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties new file mode 100644 index 00000000..c06c338a --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties @@ -0,0 +1,10 @@ +rocketmq.simple-consumer.endpoints=localhost:8081 +rocketmq.simple-consumer.consumer-group=transGroup +rocketmq.simple-consumer.topic=transTopic +rocketmq.simple-consumer.tag=* +rocketmq.simple-consumer.filter-expression-type=tag +demo.rocketmq.endpoints=localhost:8081 +demo.rocketmq.topic=normalTopic +demo.rocketmq.consumer-group=normalGroup +demo.rocketmq.tag=* +ext.rocketmq.topic=delayTopic diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml new file mode 100644 index 00000000..85f33ec0 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml @@ -0,0 +1,13 @@ + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-samples + 2.2.3-SNAPSHOT + + + rocketmq-client-producer-demo + + \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties new file mode 100644 index 00000000..bcacd9e0 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties @@ -0,0 +1,7 @@ +rocketmq.producer.endpoints=localhost:8081 +rocketmq.producer.topic=transTopic +demo.rocketmq.fifo-topic=fifoTopic +demo.rocketmq.delay-topic=delayTopic +demo.rocketmq.trans-topic=transTopic +demo.rocketmq.normal-topic=normalTopic +demo.rocketmq.message-group=group1 \ No newline at end of file diff --git a/rocketmq-client-spring-boot-starter/pom.xml b/rocketmq-client-spring-boot-starter/pom.xml new file mode 100644 index 00000000..a2d66660 --- /dev/null +++ b/rocketmq-client-spring-boot-starter/pom.xml @@ -0,0 +1,38 @@ + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-parent + 2.2.4-SNAPSHOT + ../rocketmq-client-spring-boot-parent/pom.xml + + + rocketmq-client-spring-boot-starter + jar + + rocketmq-client-spring-boot-starter + rocketmq-client-spring-boot-starter + + + 8 + + + + + org.springframework.boot + spring-boot-starter + + + org.springframework.boot + spring-boot-starter-validation + + + org.apache.rocketmq + rocketmq-client-spring-boot + + + + + diff --git a/rocketmq-client-spring-boot/pom.xml b/rocketmq-client-spring-boot/pom.xml new file mode 100644 index 00000000..0d578c53 --- /dev/null +++ b/rocketmq-client-spring-boot/pom.xml @@ -0,0 +1,84 @@ + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-parent + 2.2.4-SNAPSHOT + ../rocketmq-client-spring-boot-parent/pom.xml + + + rocketmq-client-spring-boot + jar + + rocketmq-client-spring-boot + rocketmq-client-spring-boot + + + + org.slf4j + slf4j-api + + + org.apache.rocketmq + rocketmq-client-java + + + org.springframework.boot + spring-boot + true + + + org.springframework.boot + spring-boot-autoconfigure + true + + + org.springframework.boot + spring-boot-autoconfigure-processor + true + + + org.springframework.boot + spring-boot-configuration-processor + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework + spring-messaging + + + org.springframework + spring-core + + + org.springframework + spring-context + + + org.springframework + spring-aop + + + com.fasterxml.jackson.core + jackson-databind + + + com.fasterxml.jackson.datatype + jackson-datatype-jsr310 + + + junit + junit + test + + + + + From 14b644b9fecdcfc97287c5d730c4869b7d284cb0 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Fri, 5 May 2023 12:18:08 +0800 Subject: [PATCH 03/13] feat:Integrate RocketMQ 5.0 client with Spring --- rocketmq-client-spring-boot-samples/pom.xml | 4 ++-- .../rocketmq-client-consume-demo/pom.xml | 2 +- .../rocketmq-client-producer-demo/pom.xml | 2 +- rocketmq-spring-boot-parent/pom.xml | 1 + rocketmq-spring-boot-samples/pom.xml | 2 +- 5 files changed, 6 insertions(+), 5 deletions(-) diff --git a/rocketmq-client-spring-boot-samples/pom.xml b/rocketmq-client-spring-boot-samples/pom.xml index 8bbcdb67..b99b0548 100644 --- a/rocketmq-client-spring-boot-samples/pom.xml +++ b/rocketmq-client-spring-boot-samples/pom.xml @@ -6,9 +6,9 @@ org.apache.rocketmq rocketmq-client-spring-boot-samples pom - 2.2.3-SNAPSHOT + 2.2.4-SNAPSHOT - rocketmq-grpc-spring-boot-samples + rocketmq-client-spring-boot-samples rocketmq-client-spring-boot-samples diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml index 1874a593..5ff1942f 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml @@ -5,7 +5,7 @@ org.apache.rocketmq rocketmq-client-spring-boot-samples - 2.2.3-SNAPSHOT + 2.2.4-SNAPSHOT rocketmq-client-consume-demo diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml index 85f33ec0..3ecb5b94 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml @@ -5,7 +5,7 @@ org.apache.rocketmq rocketmq-client-spring-boot-samples - 2.2.3-SNAPSHOT + 2.2.4-SNAPSHOT rocketmq-client-producer-demo diff --git a/rocketmq-spring-boot-parent/pom.xml b/rocketmq-spring-boot-parent/pom.xml index 102238f2..a01a8142 100644 --- a/rocketmq-spring-boot-parent/pom.xml +++ b/rocketmq-spring-boot-parent/pom.xml @@ -27,6 +27,7 @@ rocketmq-spring-boot-parent + 2.2.4-SNAPSHOT pom RocketMQ Spring Boot Parent diff --git a/rocketmq-spring-boot-samples/pom.xml b/rocketmq-spring-boot-samples/pom.xml index 793eb5d1..7e7d7bbb 100644 --- a/rocketmq-spring-boot-samples/pom.xml +++ b/rocketmq-spring-boot-samples/pom.xml @@ -40,7 +40,7 @@ 1.8 1.8 - 2.2.3-SNAPSHOT + 2.2.4-SNAPSHOT From bff897f85cc1eb13b6505c9e362b56dfb8ec9b5f Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Mon, 8 May 2023 12:57:25 +0800 Subject: [PATCH 04/13] fix:CI issue --- rocketmq-client-spring-boot-samples/LICENSE | 202 ++++++++++++++++++ rocketmq-client-spring-boot-samples/pom.xml | 16 ++ .../rocketmq-client-consume-demo/pom.xml | 16 ++ .../springboot/ClientConsumeApplication.java | 18 +- .../springboot/ExtRocketMQTemplate.java | 24 ++- .../springboot/consumer/MyConsumer.java | 24 ++- .../rocketmq-client-producer-demo/pom.xml | 16 ++ .../springboot/ClientProducerApplication.java | 28 ++- .../springboot/domain/UserMessage.java | 19 +- .../style/copyright/Apache.xml | 23 ++ .../style/copyright/profiles_settings.xml | 64 ++++++ .../style/rmq_checkstyle.xml | 135 ++++++++++++ .../style/rmq_codeStyle.xml | 157 ++++++++++++++ rocketmq-client-spring-boot-starter/pom.xml | 17 ++ rocketmq-client-spring-boot/pom.xml | 16 ++ .../ExtConsumerResetConfiguration.java | 28 ++- .../ExtProducerResetConfiguration.java | 27 ++- .../annotation/RocketMQMessageListener.java | 27 ++- ...ketMQMessageListenerBeanPostProcessor.java | 24 ++- .../RocketMQTransactionListener.java | 33 +++ .../ExtConsumerResetConfiguration.java | 36 +++- .../ExtTemplateResetConfiguration.java | 29 ++- .../ListenerContainerConfiguration.java | 32 ++- .../MessageConverterConfiguration.java | 37 ++++ .../RocketMQAutoConfiguration.java | 29 ++- .../RocketMQListenerConfiguration.java | 23 +- .../autoconfigure/RocketMQProperties.java | 21 +- .../RocketMQTransactionConfiguration.java | 27 ++- .../RocketMQTransactionListener.java | 16 -- .../MessageConverterConfiguration.java | 21 -- .../rocketmq/client/client/common/Pair.java | 30 --- .../client/client/core/RocketMQListener.java | 12 -- .../core/RocketMQTransactionChecker.java | 12 -- .../client/support/RocketMQHeaders.java | 20 -- .../support/RocketMQListenerContainer.java | 9 - .../apache/rocketmq/client/common/Pair.java | 43 ++++ .../core/RocketMQClientTemplate.java | 40 ++-- .../client/core/RocketMQListener.java | 25 +++ .../core/RocketMQTransactionChecker.java | 25 +++ .../support/DefaultListenerContainer.java | 31 ++- .../client/support/RocketMQHeaders.java | 33 +++ .../support/RocketMQListenerContainer.java | 22 ++ .../support/RocketMQMessageConverter.java | 30 ++- .../{client => }/support/RocketMQUtil.java | 32 ++- .../main/resources/META-INF/spring.factories | 2 +- 45 files changed, 1294 insertions(+), 257 deletions(-) create mode 100644 rocketmq-client-spring-boot-samples/LICENSE create mode 100644 rocketmq-client-spring-boot-samples/style/copyright/Apache.xml create mode 100644 rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml create mode 100644 rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml create mode 100644 rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/annotation/ExtConsumerResetConfiguration.java (64%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/annotation/ExtProducerResetConfiguration.java (56%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/annotation/RocketMQMessageListener.java (58%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/annotation/RocketMQMessageListenerBeanPostProcessor.java (78%) create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/ExtConsumerResetConfiguration.java (82%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/ExtTemplateResetConfiguration.java (83%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/ListenerContainerConfiguration.java (79%) create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/RocketMQAutoConfiguration.java (87%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/RocketMQListenerConfiguration.java (52%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/RocketMQProperties.java (89%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/autoconfigure/RocketMQTransactionConfiguration.java (72%) delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java delete mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/core/RocketMQClientTemplate.java (92%) create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/support/DefaultListenerContainer.java (88%) create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java create mode 100644 rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/support/RocketMQMessageConverter.java (69%) rename rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/{client => }/support/RocketMQUtil.java (83%) diff --git a/rocketmq-client-spring-boot-samples/LICENSE b/rocketmq-client-spring-boot-samples/LICENSE new file mode 100644 index 00000000..7a4a3ea2 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/LICENSE @@ -0,0 +1,202 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/pom.xml b/rocketmq-client-spring-boot-samples/pom.xml index b99b0548..5254887c 100644 --- a/rocketmq-client-spring-boot-samples/pom.xml +++ b/rocketmq-client-spring-boot-samples/pom.xml @@ -1,4 +1,20 @@ + 4.0.0 diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml index 5ff1942f..4feb7fad 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml @@ -1,4 +1,20 @@ + 4.0.0 diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java index 60ce31d0..be101e06 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java @@ -1,9 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.rocketmq.samples.springboot; import org.apache.rocketmq.client.apis.ClientException; import org.apache.rocketmq.client.apis.message.MessageId; import org.apache.rocketmq.client.apis.message.MessageView; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.boot.CommandLineRunner; diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java index 478fdcf5..25b66689 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java @@ -1,12 +1,24 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.rocketmq.samples.springboot; +import org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; -import org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; - -/** - * @author Akai - */ @ExtConsumerResetConfiguration(topic = "${ext.rocketmq.topic:}") public class ExtRocketMQTemplate extends RocketMQClientTemplate { } diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java index 54d7b294..ec72952a 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java @@ -1,15 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.rocketmq.samples.springboot.consumer; - import org.apache.rocketmq.client.apis.consumer.ConsumeResult; import org.apache.rocketmq.client.apis.message.MessageView; -import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; -import org.apache.rocketmq.client.client.core.RocketMQListener; +import org.apache.rocketmq.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.core.RocketMQListener; import org.springframework.stereotype.Service; -/** - * @author Akai - */ @Service @RocketMQMessageListener(endpoints = "${demo.rocketmq.endpoints:}", topic = "${demo.rocketmq.topic:}", consumerGroup = "${demo.rocketmq.consumer-group:}", tag = "${demo.rocketmq.tag:}") diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml index 3ecb5b94..40690714 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml @@ -1,4 +1,20 @@ + 4.0.0 diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java index c9f34a84..dfc9475f 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java @@ -1,3 +1,19 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.rocketmq.samples.springboot; import org.apache.rocketmq.client.apis.ClientException; @@ -6,10 +22,10 @@ import org.apache.rocketmq.client.apis.producer.Transaction; import org.apache.rocketmq.client.apis.producer.TransactionResolution; -import org.apache.rocketmq.client.client.annotation.RocketMQTransactionListener; -import org.apache.rocketmq.client.client.common.Pair; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; -import org.apache.rocketmq.client.client.core.RocketMQTransactionChecker; +import org.apache.rocketmq.client.annotation.RocketMQTransactionListener; +import org.apache.rocketmq.client.common.Pair; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQTransactionChecker; import org.apache.rocketmq.samples.springboot.domain.UserMessage; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -136,9 +152,9 @@ void testSendTransactionMessage() throws ClientException { } catch (ClientException e) { throw new RuntimeException(e); } - sendReceipt = pair.getLeft(); + sendReceipt = pair.getSendReceipt(); System.out.printf("transactionSend to topic %s sendReceipt=%s %n", transTopic, sendReceipt); - Transaction transaction = pair.getRight(); + Transaction transaction = pair.getTransaction(); // executed local transaction if (doLocalTransaction(1)) { transaction.commit(); diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java index 88919ff1..b31e48d0 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java @@ -1,8 +1,21 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.apache.rocketmq.samples.springboot.domain; -/** - * @author Akai - */ public class UserMessage { int id; private String userName; diff --git a/rocketmq-client-spring-boot-samples/style/copyright/Apache.xml b/rocketmq-client-spring-boot-samples/style/copyright/Apache.xml new file mode 100644 index 00000000..e3e3dec3 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/style/copyright/Apache.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml b/rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml new file mode 100644 index 00000000..747c7e2b --- /dev/null +++ b/rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml @@ -0,0 +1,64 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml b/rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml new file mode 100644 index 00000000..2e9658f4 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml @@ -0,0 +1,135 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml b/rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml new file mode 100644 index 00000000..9db075e3 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml @@ -0,0 +1,157 @@ + + + + + + + \ No newline at end of file diff --git a/rocketmq-client-spring-boot-starter/pom.xml b/rocketmq-client-spring-boot-starter/pom.xml index a2d66660..c3d433de 100644 --- a/rocketmq-client-spring-boot-starter/pom.xml +++ b/rocketmq-client-spring-boot-starter/pom.xml @@ -1,4 +1,20 @@ + 4.0.0 @@ -11,6 +27,7 @@ rocketmq-client-spring-boot-starter jar + 2.2.4-SNAPSHOT rocketmq-client-spring-boot-starter rocketmq-client-spring-boot-starter diff --git a/rocketmq-client-spring-boot/pom.xml b/rocketmq-client-spring-boot/pom.xml index 0d578c53..ac7c7dc9 100644 --- a/rocketmq-client-spring-boot/pom.xml +++ b/rocketmq-client-spring-boot/pom.xml @@ -1,4 +1,20 @@ + 4.0.0 diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java similarity index 64% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java index 41238813..8615e2b6 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtConsumerResetConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java @@ -1,12 +1,28 @@ -package org.apache.rocketmq.client.client.annotation; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.annotation; import org.springframework.stereotype.Component; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.Documented; -import java.lang.annotation.*; - -/** - * @author Akai - */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java similarity index 56% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java index 82380d9c..8849d0fc 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/ExtProducerResetConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java @@ -1,12 +1,29 @@ -package org.apache.rocketmq.client.client.annotation; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.annotation; import org.springframework.stereotype.Component; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.Documented; -/** - * @author Akai - */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java similarity index 58% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java index 21796fb6..cadf4c93 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListener.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java @@ -1,10 +1,27 @@ -package org.apache.rocketmq.client.client.annotation; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.annotation; -import java.lang.annotation.*; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.Documented; -/** - * @author Akai - */ @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) @Documented diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java similarity index 78% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java index c80642f8..61f3e1d2 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQMessageListenerBeanPostProcessor.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java @@ -1,6 +1,22 @@ -package org.apache.rocketmq.client.client.annotation; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.annotation; -import org.apache.rocketmq.client.client.autoconfigure.ListenerContainerConfiguration; +import org.apache.rocketmq.client.autoconfigure.ListenerContainerConfiguration; import org.springframework.aop.support.AopUtils; import org.springframework.beans.BeansException; import org.springframework.beans.factory.InitializingBean; @@ -16,9 +32,6 @@ import java.util.function.BiFunction; import java.util.stream.Collectors; -/** - * @author Akai - */ public class RocketMQMessageListenerBeanPostProcessor implements ApplicationContextAware, BeanPostProcessor, InitializingBean { private ApplicationContext applicationContext; @@ -67,7 +80,6 @@ private void buildEnhancer() { .collect(Collectors.toList()); this.enhancer = (attrs, element) -> { Map newAttrs = attrs; - //遍历所有注解增强器,将前一次注解增强得到的结果作为下一个注解增强器的参数,最后返回多个注解增强器处理后的结果 for (AnnotationEnhancer enh : enhancers) { newAttrs = enh.apply(newAttrs, element); } diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java new file mode 100644 index 00000000..8d85f1d1 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.annotation; + +import org.springframework.stereotype.Component; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import java.lang.annotation.Documented; + +@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@Component +public @interface RocketMQTransactionListener { + String rocketMQTemplateBeanName() default "rocketMQClientTemplate"; +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java similarity index 82% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java index 4e2d028c..3545dae0 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtConsumerResetConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java @@ -1,14 +1,30 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; -import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.support.RocketMQUtil; import org.apache.rocketmq.client.apis.ClientConfiguration; import org.apache.rocketmq.client.apis.ClientServiceProvider; import org.apache.rocketmq.client.apis.consumer.FilterExpression; import org.apache.rocketmq.client.apis.consumer.SimpleConsumer; import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.framework.AopProxyUtils; @@ -31,9 +47,7 @@ import java.util.Objects; import java.util.stream.Collectors; -/** - * @author Akai - */ + @Configuration public class ExtConsumerResetConfiguration implements ApplicationContextAware, SmartInitializingSingleton { private static final Logger log = LoggerFactory.getLogger(ExtConsumerResetConfiguration.class); @@ -61,7 +75,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws @Override public void afterSingletonsInstantiated() { Map beans = this.applicationContext - .getBeansWithAnnotation(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration.class) + .getBeansWithAnnotation(org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration.class) .entrySet().stream().filter(entry -> !ScopedProxyUtils.isScopedTarget(entry.getKey())) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); beans.forEach(this::registerTemplate); @@ -73,7 +87,7 @@ private void registerTemplate(String beanName, Object bean) { if (!RocketMQClientTemplate.class.isAssignableFrom(bean.getClass())) { throw new IllegalStateException(clazz + " is not instance of " + RocketMQClientTemplate.class.getName()); } - org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation = clazz.getAnnotation(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration.class); + org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration annotation = clazz.getAnnotation(org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration.class); GenericApplicationContext genericApplicationContext = (GenericApplicationContext) applicationContext; validate(annotation, genericApplicationContext); @@ -92,7 +106,7 @@ private void registerTemplate(String beanName, Object bean) { log.info("Set real simpleConsumer to :{} {}", beanName, annotation.value()); } - private SimpleConsumerBuilder createConsumer(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation) { + private SimpleConsumerBuilder createConsumer(org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration annotation) { RocketMQProperties.SimpleConsumer simpleConsumer = rocketMQProperties.getSimpleConsumer(); String consumerGroupName = resolvePlaceholders(annotation.consumerGroup(), simpleConsumer.getConsumerGroup()); String topicName = resolvePlaceholders(annotation.topic(), simpleConsumer.getTopic()); @@ -125,7 +139,7 @@ private String resolvePlaceholders(String text, String defaultValue) { return StringUtils.hasLength(value) ? value : defaultValue; } - private void validate(org.apache.rocketmq.client.client.annotation.ExtConsumerResetConfiguration annotation, + private void validate(org.apache.rocketmq.client.annotation.ExtConsumerResetConfiguration annotation, GenericApplicationContext genericApplicationContext) { if (genericApplicationContext.isBeanNameInUse(annotation.value())) { throw new BeanDefinitionValidationException( diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java similarity index 83% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java index 75acb8a6..75bd4495 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ExtTemplateResetConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java @@ -1,13 +1,29 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.annotation.ExtProducerResetConfiguration; -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; -import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.annotation.ExtProducerResetConfiguration; +import org.apache.rocketmq.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.support.RocketMQUtil; import org.apache.rocketmq.client.apis.ClientConfiguration; import org.apache.rocketmq.client.apis.ClientServiceProvider; import org.apache.rocketmq.client.apis.producer.ProducerBuilder; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.framework.AopProxyUtils; @@ -27,9 +43,6 @@ import java.util.Map; import java.util.stream.Collectors; -/** - * @author Akai - */ @Configuration public class ExtTemplateResetConfiguration implements ApplicationContextAware, SmartInitializingSingleton { diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java similarity index 79% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java index e26f9f51..a6f46402 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/ListenerContainerConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java @@ -1,9 +1,25 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; -import org.apache.rocketmq.client.client.core.RocketMQListener; -import org.apache.rocketmq.client.client.support.DefaultListenerContainer; -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.core.RocketMQListener; +import org.apache.rocketmq.client.support.DefaultListenerContainer; +import org.apache.rocketmq.client.support.RocketMQMessageConverter; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -18,9 +34,6 @@ import java.time.Duration; import java.util.concurrent.atomic.AtomicLong; -/** - * @author Akai - */ @Configuration public class ListenerContainerConfiguration implements ApplicationContextAware { private final static Logger log = LoggerFactory.getLogger(ListenerContainerConfiguration.class); @@ -52,8 +65,7 @@ public void registerContainer(String beanName, Object bean, RocketMQMessageListe String containerBeanName = String.format("%s_%s", DefaultListenerContainer.class.getName(), counter.incrementAndGet()); GenericApplicationContext genericApplicationContext = (GenericApplicationContext) applicationContext; - genericApplicationContext.registerBean(containerBeanName, DefaultListenerContainer.class, - () -> createRocketMQListenerContainer(containerBeanName, bean, annotation)); + genericApplicationContext.registerBean(containerBeanName, DefaultListenerContainer.class, () -> createRocketMQListenerContainer(containerBeanName, bean, annotation)); DefaultListenerContainer container = genericApplicationContext.getBean(containerBeanName, DefaultListenerContainer.class); if (!container.isRunning()) { diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java new file mode 100644 index 00000000..25e5512c --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; + + +import org.apache.rocketmq.client.support.RocketMQMessageConverter; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * @see RocketMQMessageConverter + */ +@Configuration +@ConditionalOnMissingBean(RocketMQMessageConverter.class) +class MessageConverterConfiguration { + + @Bean + public RocketMQMessageConverter createMessageConverter() { + return new RocketMQMessageConverter(); + } + +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java similarity index 87% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java index 60818e24..14998046 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQAutoConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java @@ -1,13 +1,29 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; -import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.support.RocketMQUtil; import org.apache.rocketmq.client.apis.ClientConfiguration; import org.apache.rocketmq.client.apis.ClientServiceProvider; import org.apache.rocketmq.client.apis.consumer.FilterExpression; import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; import org.apache.rocketmq.client.apis.producer.ProducerBuilder; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; import org.apache.rocketmq.client.java.impl.producer.ProducerBuilderImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -32,9 +48,7 @@ import java.util.Collections; import java.util.Objects; -/** - * @author Akai - */ + @Configuration @EnableConfigurationProperties(RocketMQProperties.class) @Import({MessageConverterConfiguration.class, ListenerContainerConfiguration.class, ExtTemplateResetConfiguration.class, @@ -86,7 +100,6 @@ public ProducerBuilder producerBuilder(RocketMQProperties rocketMQProperties) { @ConditionalOnMissingBean(SimpleConsumerBuilder.class) @ConditionalOnProperty(prefix = "rocketmq", value = {"simple-consumer.endpoints"}) public SimpleConsumerBuilder simpleConsumerBuilder(RocketMQProperties rocketMQProperties) { - //此处getConsumer返回一个pushConsumer,getPullConsumer返回一个pullConsumer RocketMQProperties.SimpleConsumer simpleConsumer = rocketMQProperties.getSimpleConsumer(); final ClientServiceProvider provider = ClientServiceProvider.loadService(); String consumerGroup = simpleConsumer.getConsumerGroup(); diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java similarity index 52% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java index 37587876..c8afc127 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQListenerConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java @@ -1,6 +1,22 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.annotation.RocketMQMessageListenerBeanPostProcessor; +import org.apache.rocketmq.client.annotation.RocketMQMessageListenerBeanPostProcessor; import org.springframework.beans.factory.support.BeanDefinitionRegistry; import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.boot.autoconfigure.AutoConfigureAfter; @@ -8,9 +24,6 @@ import org.springframework.context.annotation.ImportBeanDefinitionRegistrar; import org.springframework.core.type.AnnotationMetadata; -/** - * @author Akai - */ @Configuration @AutoConfigureAfter(RocketMQAutoConfiguration.class) public class RocketMQListenerConfiguration implements ImportBeanDefinitionRegistrar { diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java similarity index 89% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java index 8851e186..64c9a6a1 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQProperties.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java @@ -1,10 +1,23 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; import org.springframework.boot.context.properties.ConfigurationProperties; -/** - * @author Akai - */ @SuppressWarnings("WeakerAccess") @ConfigurationProperties(prefix = "rocketmq") public class RocketMQProperties { diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java similarity index 72% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java index f5283012..13b35a79 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/RocketMQTransactionConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java @@ -1,8 +1,24 @@ -package org.apache.rocketmq.client.client.autoconfigure; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.autoconfigure; -import org.apache.rocketmq.client.client.annotation.RocketMQTransactionListener; +import org.apache.rocketmq.client.annotation.RocketMQTransactionListener; import org.apache.rocketmq.client.apis.producer.TransactionChecker; -import org.apache.rocketmq.client.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.aop.framework.AopProxyUtils; @@ -18,9 +34,6 @@ import java.util.Objects; import java.util.stream.Collectors; -/** - * @author Akai - */ @Configuration public class RocketMQTransactionConfiguration implements ApplicationContextAware, SmartInitializingSingleton { private final static Logger log = LoggerFactory.getLogger(RocketMQTransactionConfiguration.class); @@ -32,7 +45,6 @@ public void setApplicationContext(ApplicationContext applicationContext) throws this.applicationContext = (ConfigurableApplicationContext) applicationContext; } - //获取被@RocketMQTransactionListener标记的类 @Override public void afterSingletonsInstantiated() { Map beans = this.applicationContext.getBeansWithAnnotation(RocketMQTransactionListener.class) @@ -50,7 +62,6 @@ public void handleTransactionChecker(String beanName, Object bean) { if (Objects.isNull(annotation)) { throw new IllegalStateException("The transactionListener annotation is missing"); } - //获取注解上的template,默认为RocketMQGRpcTemplate RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) applicationContext.getBean(annotation.rocketMQTemplateBeanName()); if ((rocketMQTemplate.getProducerBuilder()) != null) { rocketMQTemplate.getProducerBuilder().setTransactionChecker((TransactionChecker) bean); diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java deleted file mode 100644 index 904cd742..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/annotation/RocketMQTransactionListener.java +++ /dev/null @@ -1,16 +0,0 @@ -package org.apache.rocketmq.client.client.annotation; - -import org.springframework.stereotype.Component; - -import java.lang.annotation.*; - -/** - * @author Akai - */ -@Target({ElementType.TYPE, ElementType.ANNOTATION_TYPE}) -@Retention(RetentionPolicy.RUNTIME) -@Documented -@Component -public @interface RocketMQTransactionListener { - String rocketMQTemplateBeanName() default "rocketMQClientTemplate"; -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java deleted file mode 100644 index 045d518f..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/autoconfigure/MessageConverterConfiguration.java +++ /dev/null @@ -1,21 +0,0 @@ -package org.apache.rocketmq.client.client.autoconfigure; - - -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; -import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -/** - * @see RocketMQMessageConverter - */ -@Configuration -@ConditionalOnMissingBean(RocketMQMessageConverter.class) -class MessageConverterConfiguration { - - @Bean - public RocketMQMessageConverter createMessageConverter() { - return new RocketMQMessageConverter(); - } - -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java deleted file mode 100644 index 27888e32..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/common/Pair.java +++ /dev/null @@ -1,30 +0,0 @@ -package org.apache.rocketmq.client.client.common; - -/** - * @author Akai - */ -public class Pair { - private T1 left; - private T2 right; - - public Pair(T1 left, T2 right) { - this.left = left; - this.right = right; - } - - public T1 getLeft() { - return left; - } - - public void setLeft(T1 left) { - this.left = left; - } - - public T2 getRight() { - return right; - } - - public void setRight(T2 right) { - this.right = right; - } -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java deleted file mode 100644 index 15a7b168..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQListener.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.apache.rocketmq.client.client.core; - -import org.apache.rocketmq.client.apis.consumer.ConsumeResult; -import org.apache.rocketmq.client.apis.consumer.MessageListener; -import org.apache.rocketmq.client.apis.message.MessageView; - -/** - * @author Akai - */ -public interface RocketMQListener extends MessageListener { - ConsumeResult consume(MessageView messageView); -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java deleted file mode 100644 index 6cbc114c..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQTransactionChecker.java +++ /dev/null @@ -1,12 +0,0 @@ -package org.apache.rocketmq.client.client.core; - -import org.apache.rocketmq.client.apis.message.MessageView; -import org.apache.rocketmq.client.apis.producer.TransactionChecker; -import org.apache.rocketmq.client.apis.producer.TransactionResolution; - -/** - * @author Akai - */ -public interface RocketMQTransactionChecker extends TransactionChecker { - TransactionResolution check(MessageView var1); -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java deleted file mode 100644 index 2edb1bec..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQHeaders.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.apache.rocketmq.client.client.support; - -/** - * @author Akai - */ -public class RocketMQHeaders { - public static final String PREFIX = "rocketmq_"; - public static final String KEYS = "KEYS"; - public static final String TAGS = "TAGS"; - public static final String TOPIC = "TOPIC"; - public static final String MESSAGE_ID = "MESSAGE_ID"; - public static final String BORN_TIMESTAMP = "BORN_TIMESTAMP"; - public static final String BORN_HOST = "BORN_HOST"; - public static final String FLAG = "FLAG"; - public static final String QUEUE_ID = "QUEUE_ID"; - public static final String SYS_FLAG = "SYS_FLAG"; - public static final String TRANSACTION_ID = "TRANSACTION_ID"; - public static final String DELAY = "DELAY"; - public static final String WAIT = "WAIT"; -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java deleted file mode 100644 index 5fe89527..00000000 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQListenerContainer.java +++ /dev/null @@ -1,9 +0,0 @@ -package org.apache.rocketmq.client.client.support; - -import org.springframework.beans.factory.DisposableBean; - -/** - * @author Akai - */ -public interface RocketMQListenerContainer extends DisposableBean { -} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java new file mode 100644 index 00000000..e9666e0a --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java @@ -0,0 +1,43 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.common; + +public class Pair { + private T1 sendReceipt; + private T2 transaction; + + public Pair(T1 sendReceipt, T2 transaction) { + this.sendReceipt = sendReceipt; + this.transaction = transaction; + } + + public T1 getSendReceipt() { + return sendReceipt; + } + + public void setLeft(T1 sendReceipt) { + this.sendReceipt = sendReceipt; + } + + public T2 getTransaction() { + return transaction; + } + + public void setTransaction(T2 transaction) { + this.transaction = transaction; + } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java similarity index 92% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java index 1ecce910..ee092c26 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/core/RocketMQClientTemplate.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java @@ -1,8 +1,24 @@ -package org.apache.rocketmq.client.client.core; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.core; -import org.apache.rocketmq.client.client.common.Pair; -import org.apache.rocketmq.client.client.support.RocketMQMessageConverter; -import org.apache.rocketmq.client.client.support.RocketMQUtil; +import org.apache.rocketmq.client.common.Pair; +import org.apache.rocketmq.client.support.RocketMQMessageConverter; +import org.apache.rocketmq.client.support.RocketMQUtil; import org.apache.rocketmq.client.apis.ClientException; import org.apache.rocketmq.client.apis.consumer.SimpleConsumer; import org.apache.rocketmq.client.apis.consumer.SimpleConsumerBuilder; @@ -25,9 +41,7 @@ import java.util.Objects; import java.util.concurrent.CompletableFuture; -/** - * @author Akai - */ + @SuppressWarnings({"WeakerAccess", "unused"}) public class RocketMQClientTemplate extends AbstractMessageSendingTemplate implements DisposableBean { @@ -108,9 +122,7 @@ public void setCharset(String charset) { this.charset = charset; } - /** - * spring容器关闭时调用 - */ + @Override public void destroy() throws Exception { if (Objects.nonNull(producer)) { @@ -231,14 +243,11 @@ public CompletableFuture asyncSend(String destination, String paylo return asyncSend(destination, message, messageDelayTime); } - public CompletableFuture asyncSend(String destination, byte[] payload, Duration messageDelayTime){ + public CompletableFuture asyncSend(String destination, byte[] payload, Duration messageDelayTime) { Message message = MessageBuilder.withPayload(payload).build(); return asyncSend(destination, message, messageDelayTime); } - /** - * 发送异步任务 - */ public CompletableFuture asyncSend(String destination, Message message, Duration messageDelayTime) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("send request message failed. destination:{}, message is null ", destination); @@ -298,14 +307,12 @@ public Pair sendTransactionMessage(String destination, } - //SimpleConsumer同步接收消息 public List receive(int maxMessageNum, Duration invisibleDuration) throws ClientException { SimpleConsumer simpleConsumer = this.getSimpleConsumer(); return simpleConsumer.receive(maxMessageNum, invisibleDuration); } - //SimpleConsumer异步接收消息 public CompletableFuture> receiveAsync(int maxMessageNum, Duration invisibleDuration) throws ClientException, IOException { SimpleConsumer simpleConsumer = this.getSimpleConsumer(); CompletableFuture> listCompletableFuture = simpleConsumer.receiveAsync(maxMessageNum, invisibleDuration); @@ -314,7 +321,6 @@ public CompletableFuture> receiveAsync(int maxMessageNum, Dura } - //抛出异常,让用户捕获,自定义异常处理逻辑 public void ack(MessageView message) throws ClientException { SimpleConsumer simpleConsumer = this.getSimpleConsumer(); simpleConsumer.ack(message); diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java new file mode 100644 index 00000000..91aa1d1a --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.core; + +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.consumer.MessageListener; +import org.apache.rocketmq.client.apis.message.MessageView; + +public interface RocketMQListener extends MessageListener { + ConsumeResult consume(MessageView messageView); +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java new file mode 100644 index 00000000..fc90cf93 --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java @@ -0,0 +1,25 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.core; + +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.apis.producer.TransactionChecker; +import org.apache.rocketmq.client.apis.producer.TransactionResolution; + +public interface RocketMQTransactionChecker extends TransactionChecker { + TransactionResolution check(MessageView var1); +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java similarity index 88% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java index 797da37f..c2466c05 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/DefaultListenerContainer.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java @@ -1,10 +1,29 @@ -package org.apache.rocketmq.client.client.support; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.support; -import org.apache.rocketmq.client.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.annotation.RocketMQMessageListener; import org.apache.rocketmq.client.apis.ClientConfiguration; import org.apache.rocketmq.client.apis.ClientServiceProvider; -import org.apache.rocketmq.client.apis.consumer.*; -import org.apache.rocketmq.client.client.core.RocketMQListener; +import org.apache.rocketmq.client.apis.consumer.FilterExpressionType; +import org.apache.rocketmq.client.apis.consumer.PushConsumer; +import org.apache.rocketmq.client.apis.consumer.PushConsumerBuilder; +import org.apache.rocketmq.client.apis.consumer.FilterExpression; +import org.apache.rocketmq.client.core.RocketMQListener; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeansException; @@ -20,9 +39,7 @@ import java.util.Collections; import java.util.Objects; -/** - * @author Akai - */ + public class DefaultListenerContainer implements InitializingBean, RocketMQListenerContainer, SmartLifecycle, ApplicationContextAware { private final static Logger log = LoggerFactory.getLogger(DefaultListenerContainer.class); diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java new file mode 100644 index 00000000..9d0145ca --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.support; + +public class RocketMQHeaders { + public static final String PREFIX = "rocketmq_"; + public static final String KEYS = "KEYS"; + public static final String TAGS = "TAGS"; + public static final String TOPIC = "TOPIC"; + public static final String MESSAGE_ID = "MESSAGE_ID"; + public static final String BORN_TIMESTAMP = "BORN_TIMESTAMP"; + public static final String BORN_HOST = "BORN_HOST"; + public static final String FLAG = "FLAG"; + public static final String QUEUE_ID = "QUEUE_ID"; + public static final String SYS_FLAG = "SYS_FLAG"; + public static final String TRANSACTION_ID = "TRANSACTION_ID"; + public static final String DELAY = "DELAY"; + public static final String WAIT = "WAIT"; +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java new file mode 100644 index 00000000..9473761f --- /dev/null +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.support; + +import org.springframework.beans.factory.DisposableBean; + +public interface RocketMQListenerContainer extends DisposableBean { +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java similarity index 69% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java index ea1aef70..5ede82d2 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQMessageConverter.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java @@ -1,9 +1,29 @@ -package org.apache.rocketmq.client.client.support; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.support; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; -import org.springframework.messaging.converter.*; +import org.springframework.messaging.converter.CompositeMessageConverter; +import org.springframework.messaging.converter.ByteArrayMessageConverter; +import org.springframework.messaging.converter.MessageConverter; +import org.springframework.messaging.converter.MappingJackson2MessageConverter; +import org.springframework.messaging.converter.StringMessageConverter; import org.springframework.util.ClassUtils; import java.util.ArrayList; @@ -17,15 +37,11 @@ public class RocketMQMessageConverter { private static final boolean JACKSON_PRESENT; private static final boolean FASTJSON_PRESENT; - //用于检测当前项目中是否有使用到 Jackson 或 FastJson 这些 JSON 序列化/反序列化相关的类和配置 static { - // 获取 RocketMQMessageConverter 类的类加载器,即用于加载 RocketMQMessageConverter 类的类加载器 ClassLoader classLoader = RocketMQMessageConverter.class.getClassLoader(); - // 判断是否存在 Jackson 相关的类和配置,包括 com.fasterxml.jackson.databind.ObjectMapper 和 com.fasterxml.jackson.core.JsonGenerator JACKSON_PRESENT = ClassUtils.isPresent("com.fasterxml.jackson.databind.ObjectMapper", classLoader) && ClassUtils.isPresent("com.fasterxml.jackson.core.JsonGenerator", classLoader); - // 判断是否存在 FastJson 相关的类和配置,包括 com.alibaba.fastjson.JSON 和 com.alibaba.fastjson.support.config.FastJsonConfig FASTJSON_PRESENT = ClassUtils.isPresent("com.alibaba.fastjson.JSON", classLoader) && ClassUtils.isPresent("com.alibaba.fastjson.support.config.FastJsonConfig", classLoader); } @@ -64,4 +80,4 @@ public org.springframework.messaging.converter.MessageConverter getMessageConver } - } +} diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java similarity index 83% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java rename to rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java index 7054052e..89ec64ef 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/client/support/RocketMQUtil.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java @@ -1,7 +1,28 @@ -package org.apache.rocketmq.client.client.support; +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.client.support; + +import org.apache.rocketmq.client.apis.ClientConfiguration; +import org.apache.rocketmq.client.apis.ClientServiceProvider; +import org.apache.rocketmq.client.apis.SessionCredentialsProvider; +import org.apache.rocketmq.client.apis.StaticSessionCredentialsProvider; +import org.apache.rocketmq.client.apis.ClientConfigurationBuilder; +import org.apache.rocketmq.client.autoconfigure.RocketMQProperties; -import org.apache.rocketmq.client.client.autoconfigure.RocketMQProperties; -import org.apache.rocketmq.client.apis.*; import org.apache.rocketmq.client.apis.consumer.FilterExpression; import org.apache.rocketmq.client.apis.consumer.FilterExpressionType; import org.slf4j.Logger; @@ -15,9 +36,6 @@ import java.time.Duration; import java.util.Objects; -/** - * @author Akai - */ public class RocketMQUtil { private static final Logger log = LoggerFactory.getLogger(RocketMQUtil.class); @@ -146,7 +164,7 @@ public static FilterExpression createFilterExpression(String tag, String type) { log.info("do not support your filterExpressionType {}", type); } FilterExpressionType filterExpressionType = "tag".equalsIgnoreCase(type) ? FilterExpressionType.TAG : FilterExpressionType.SQL92; - FilterExpression filterExpression= new FilterExpression(tag, filterExpressionType); + FilterExpression filterExpression = new FilterExpression(tag, filterExpressionType); return filterExpression; } } diff --git a/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories b/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories index ed8d45d4..872f2288 100644 --- a/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories +++ b/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories @@ -1,2 +1,2 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\ -org.apache.rocketmq.client.client.autoconfigure.RocketMQAutoConfiguration +org.apache.rocketmq.client.autoconfigure.RocketMQAutoConfiguration From e95fd3fbf916cb519a180aeb9be38b5f9df30025 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 27 May 2023 00:02:30 +0800 Subject: [PATCH 05/13] fix:remove useless LICENSE and modify the asynchronous message sending method --- rocketmq-client-spring-boot-samples/LICENSE | 202 ------------------ .../springboot/ClientProducerApplication.java | 67 ++++-- .../RocketMQAutoConfiguration.java | 2 +- .../client/core/RocketMQClientTemplate.java | 92 ++++++-- 4 files changed, 121 insertions(+), 242 deletions(-) delete mode 100644 rocketmq-client-spring-boot-samples/LICENSE diff --git a/rocketmq-client-spring-boot-samples/LICENSE b/rocketmq-client-spring-boot-samples/LICENSE deleted file mode 100644 index 7a4a3ea2..00000000 --- a/rocketmq-client-spring-boot-samples/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java index dfc9475f..1fc96d6b 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java @@ -40,6 +40,8 @@ import java.time.Duration; import java.util.Objects; import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; @SpringBootApplication public class ClientProducerApplication implements CommandLineRunner { @@ -71,6 +73,7 @@ public static void main(String[] args) { @Override public void run(String... args) throws ClientException { + testASycSendMessage(); testSendDelayMessage(); testSendFIFOMessage(); testSendNormalMessage(); @@ -78,19 +81,47 @@ public void run(String... args) throws ClientException { } void testASycSendMessage() { - CompletableFuture future = rocketMQClientTemplate.asyncSend(normalTopic, new UserMessage() - .setId(1).setUserName("name").setUserAge((byte) 3), null); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future); - CompletableFuture future1 = rocketMQClientTemplate.asyncSend(normalTopic, "normal message", null); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future1); + CompletableFuture future0 = new CompletableFuture<>(); + CompletableFuture future1 = new CompletableFuture<>(); + CompletableFuture future2 = new CompletableFuture<>(); + ExecutorService sendCallbackExecutor = Executors.newCachedThreadPool(); - CompletableFuture future2 = rocketMQClientTemplate.asyncSend(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8), null); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future2); + future0.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + future1.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + future2.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + CompletableFuture completableFuture0 = rocketMQClientTemplate.asyncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), future0); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, completableFuture0); - CompletableFuture future3 = rocketMQClientTemplate.asyncSend(normalTopic, MessageBuilder. - withPayload("test message".getBytes()).build(), null); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, future3); + CompletableFuture completableFuture1 = rocketMQClientTemplate.asyncSendFifoMessage(fifoTopic, "fifo message", + messageGroup, future1); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, completableFuture1); + + CompletableFuture completableFuture2 = rocketMQClientTemplate.asyncSendDelayMessage(delayTopic, + "delay message".getBytes(StandardCharsets.UTF_8), Duration.ofSeconds(10), future2); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, completableFuture2); } void testSendDelayMessage() { @@ -147,8 +178,9 @@ void testSendTransactionMessage() throws ClientException { Pair pair; SendReceipt sendReceipt; try { - pair = rocketMQClientTemplate.sendGRpcMessageInTransaction(transTopic, new UserMessage() - .setId(1).setUserName("name").setUserAge((byte) 3), null); + pair = rocketMQClientTemplate.sendMessageInTransaction(transTopic, MessageBuilder. + withPayload(new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)).setHeader("OrderId", 1).build()); } catch (ClientException e) { throw new RuntimeException(e); } @@ -164,11 +196,11 @@ void testSendTransactionMessage() throws ClientException { } @RocketMQTransactionListener - class TransactionListenerImpl implements RocketMQTransactionChecker { + static class TransactionListenerImpl implements RocketMQTransactionChecker { @Override public TransactionResolution check(MessageView messageView) { - if (Objects.nonNull(messageView.getProperties().get("KEY"))) { - log.info("commit transaction"); + if (Objects.nonNull(messageView.getProperties().get("OrderId"))) { + log.info("Receive transactional message check, message={}", messageView); return TransactionResolution.COMMIT; } log.info("rollback transaction"); @@ -178,10 +210,7 @@ public TransactionResolution check(MessageView messageView) { boolean doLocalTransaction(int number) { log.info("execute local transaction"); - if (number > 0) { - return true; - } - return false; + return number > 0; } } diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java index 14998046..786888f2 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java @@ -78,7 +78,7 @@ public ProducerBuilder producerBuilder(RocketMQProperties rocketMQProperties) { log.info("Init Producer Args: " + rocketMQProducer); String topic = rocketMQProducer.getTopic(); String endPoints = rocketMQProducer.getEndpoints(); - Assert.hasText(topic, "[rocketmq.producer.topic] must not be null"); + Assert.hasText(endPoints, "[rocketmq.producer.endpoints] must not be null"); ClientConfiguration clientConfiguration = RocketMQUtil.createProducerClientConfiguration(rocketMQProducer); final ClientServiceProvider provider = ClientServiceProvider.loadService(); ProducerBuilder producerBuilder; diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java index ee092c26..890c6f21 100644 --- a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java +++ b/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java @@ -233,30 +233,82 @@ public SendReceipt syncSendGrpcMessage(String destination, Message message, D return sendReceipt; } - public CompletableFuture asyncSend(String destination, Object payload, Duration messageDelayTime) { + + public CompletableFuture asyncSendWithObjectPayload(String destination, Object payload, Duration messageDelayTime, String messageGroup, CompletableFuture future) { Message message = MessageBuilder.withPayload(payload).build(); - return asyncSend(destination, message, messageDelayTime); + return asyncSend(destination, message, messageDelayTime, messageGroup, future); } - public CompletableFuture asyncSend(String destination, String payload, Duration messageDelayTime) { + public CompletableFuture asyncSendWithStringPayload(String destination, String payload, Duration messageDelayTime, String messageGroup, CompletableFuture future) { Message message = MessageBuilder.withPayload(payload).build(); - return asyncSend(destination, message, messageDelayTime); + return asyncSend(destination, message, messageDelayTime, messageGroup, future); } - public CompletableFuture asyncSend(String destination, byte[] payload, Duration messageDelayTime) { + public CompletableFuture asyncSendWithBytePayload(String destination, byte[] payload, Duration messageDelayTime, String messageGroup, CompletableFuture future) { Message message = MessageBuilder.withPayload(payload).build(); - return asyncSend(destination, message, messageDelayTime); + return asyncSend(destination, message, messageDelayTime, messageGroup, future); + } + + public CompletableFuture asyncSendWithMessagePayload(String destination, Message payload, Duration messageDelayTime, String messageGroup, CompletableFuture future) { + return asyncSend(destination, payload, messageDelayTime, messageGroup, future); + } + + public CompletableFuture asyncSendNormalMessage(String destination, Object payload, CompletableFuture future) { + return asyncSendWithObjectPayload(destination, payload, null, null, future); + } + + public CompletableFuture asyncSendNormalMessage(String destination, String payload, CompletableFuture future) { + return asyncSendWithStringPayload(destination, payload, null, null, future); + } + + public CompletableFuture asyncSendNormalMessage(String destination, byte[] payload, CompletableFuture future) { + return asyncSendWithBytePayload(destination, payload, null, null, future); + } + + public CompletableFuture asyncSendNormalMessage(String destination, Message payload, CompletableFuture future) { + return asyncSendWithMessagePayload(destination, payload, null, null, future); + } + + public CompletableFuture asyncSendFifoMessage(String destination, Object payload, String messageGroup, CompletableFuture future) { + return asyncSendWithObjectPayload(destination, payload, null, messageGroup, future); + } + + public CompletableFuture asyncSendFifoMessage(String destination, String payload, String messageGroup, CompletableFuture future) { + return asyncSendWithStringPayload(destination, payload, null, messageGroup, future); + } + + public CompletableFuture asyncSendFifoMessage(String destination, byte[] payload, String messageGroup, CompletableFuture future) { + return asyncSendWithBytePayload(destination, payload, null, messageGroup, future); + } + + public CompletableFuture asyncSendFifoMessage(String destination, Message payload, String messageGroup, CompletableFuture future) { + return asyncSendWithMessagePayload(destination, payload, null, messageGroup, future); + } + + public CompletableFuture asyncSendDelayMessage(String destination, Object payload, Duration messageDelayTime, CompletableFuture future) { + return asyncSendWithObjectPayload(destination, payload, messageDelayTime, null, future); + } + + public CompletableFuture asyncSendDelayMessage(String destination, String payload, Duration messageDelayTime, CompletableFuture future) { + return asyncSendWithStringPayload(destination, payload, messageDelayTime, null, future); + } + + public CompletableFuture asyncSendDelayMessage(String destination, byte[] payload, Duration messageDelayTime, CompletableFuture future) { + return asyncSendWithBytePayload(destination, payload, messageDelayTime, null, future); + } + + public CompletableFuture asyncSendDelayMessage(String destination, Message payload, Duration messageDelayTime, CompletableFuture future) { + return asyncSendWithMessagePayload(destination, payload, messageDelayTime, null, future); } - public CompletableFuture asyncSend(String destination, Message message, Duration messageDelayTime) { + public CompletableFuture asyncSend(String destination, Message message, Duration messageDelayTime, String messageGroup, CompletableFuture future) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("send request message failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } - final CompletableFuture future; Producer grpcProducer = this.getProducer(); try { - org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, null); + org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, messageGroup); future = grpcProducer.sendAsync(rocketMsg); } catch (Exception e) { log.error("send request message failed. destination:{}, message:{} ", destination, message); @@ -265,35 +317,35 @@ public CompletableFuture asyncSend(String destination, Message m return future; } - public Pair sendGRpcMessageInTransaction(String destination, Object payload, Duration messageDelayTime) throws ClientException { + public Pair sendMessageInTransaction(String destination, Object payload) throws ClientException { Message message = MessageBuilder.withPayload(payload).build(); - return sendTransactionMessage(destination, message, messageDelayTime); + return sendTransactionMessage(destination, message); } - public Pair sendGRpcMessageInTransaction(String destination, String payload, Duration messageDelayTime) throws ClientException { + public Pair sendMessageInTransaction(String destination, String payload) throws ClientException { Message message = MessageBuilder.withPayload(payload).build(); - return sendTransactionMessage(destination, message, messageDelayTime); + return sendTransactionMessage(destination, message); } - public Pair sendGRpcMessageInTransaction(String destination, byte[] payload, Duration messageDelayTime) throws ClientException { + public Pair sendMessageInTransaction(String destination, byte[] payload) throws ClientException { Message message = MessageBuilder.withPayload(payload).build(); - return sendTransactionMessage(destination, message, messageDelayTime); + return sendTransactionMessage(destination, message); } + /** - * @param destination formats: `topicName:tags` - * @param message {@link Message} the message to be sent. - * @param messageDelayTime Time for message delay + * @param destination formats: `topicName:tags` + * @param message {@link Message} the message to be sent. * @return CompletableFuture Asynchronous Task Results */ - public Pair sendTransactionMessage(String destination, Message message, Duration messageDelayTime) throws ClientException { + public Pair sendTransactionMessage(String destination, Message message) { if (Objects.isNull(message) || Objects.isNull(message.getPayload())) { log.error("send request message failed. destination:{}, message is null ", destination); throw new IllegalArgumentException("`message` and `message.payload` cannot be null"); } final SendReceipt sendReceipt; Producer grpcProducer = this.getProducer(); - org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, messageDelayTime, null); + org.apache.rocketmq.client.apis.message.Message rocketMsg = this.createRocketMQMessage(destination, message, null, null); final Transaction transaction; try { transaction = grpcProducer.beginTransaction(); From 85f6e2eba0a65c79782d77836a0b3e4669590ba5 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 27 May 2023 00:16:49 +0800 Subject: [PATCH 06/13] feat:Add README.md file --- rocketmq-client-spring-boot-samples/README.md | 548 ++++++++++++++++++ 1 file changed, 548 insertions(+) create mode 100644 rocketmq-client-spring-boot-samples/README.md diff --git a/rocketmq-client-spring-boot-samples/README.md b/rocketmq-client-spring-boot-samples/README.md new file mode 100644 index 00000000..af261ea9 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/README.md @@ -0,0 +1,548 @@ +# Normal消息发送 + +### 修改application.properties + +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 +**demo.rocketmq.normal-topic:**用户自定义消息发送的topic + +```properties +rocketmq.producer.endpoints=127.0.0.1:8081 +rocketmq.producer.topic=normalTopic +demo.rocketmq.normal-topic=normalTopic +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +### 编写代码 + +通过@Value注解引入配置文件参数,指定自定义topic +通过@Resource注解引入RocketMQClientTemplate容器 +通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行normal消息的发送(消息的参数类型可选:Object、String、byte[]、Message) + +```java +@SpringBootApplication +public class ClientProducerApplication implements CommandLineRunner { + + private static final Logger log = LoggerFactory.getLogger(ClientProducerApplication.class); + + @Value("${demo.rocketmq.normal-topic}") + private String normalTopic; + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + + public static void main(String[] args) { + SpringApplication.run(ClientProducerApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendNormalMessage(); + } + + //Test sending normal message + void testSendNormalMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build()); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + } + + @Data + @AllArgsConstructor + public class UserMeaasge implements Serializable { + private int id; + private String userName; + private Byte userAge; + } + +} +``` + +# FIFO消息发送 + +### 修改application.properties + +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 +**demo.rocketmq.fifo-topic:**用户自定义消息发送的topic +**demo.rocketmq.message-group=group1:**顺序消息的顺序关系通过消息组(MessageGroup)判定和识别,发送顺序消息时需要为每条消息设置归属的消息组,相同消息组的多条消息之间遵循先进先出的顺序关系,不同消息组、无消息组的消息之间不涉及顺序性。 + +```properties +rocketmq.producer.endpoints=127.0.0.1:8081 +rocketmq.producer.topic=fifoTopic +demo.rocketmq.fifo-topic=fifoTopic +demo.rocketmq.message-group=group1 +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +### 编写代码 + +通过@Value注解引入配置文件参数,指定自定义topic +通过@Resource注解引入RocketMQClientTemplate容器 +通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行fifo消息的发送(参数类型可选:Object、String、byte[]、Message) +发送fifo消息时需要设置参数:消费者组(MessageGroup) + +```java +@SpringBootApplication +public class ClientProducerApplication implements CommandLineRunner { + + private static final Logger log = LoggerFactory.getLogger(ClientProducerApplication.class); + + @Value("${demo.rocketmq.fifo-topic}") + private String fifoTopic; + + @Value("${demo.rocketmq.message-group}") + private String messageGroup; + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + + public static void main(String[] args) { + SpringApplication.run(ClientProducerApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendFIFOMessage(); + } + + //Test sending fifo message + void testSendFIFOMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, MessageBuilder. + withPayload("test message".getBytes()).build(), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, "fifo message", messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendFifoMessage(fifoTopic, "byte message".getBytes(StandardCharsets.UTF_8), messageGroup); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, sendReceipt); + } + + @Data + @AllArgsConstructor + public class UserMeaasge implements Serializable { + private int id; + private String userName; + private Byte userAge; + } + +} +``` + +# Delay消息发送 + +### 修改application.properties + +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 +**demo.rocketmq.delay-topic:**用户自定义消息发送的topic + +```java +rocketmq.producer.endpoints=127.0.0.1:8081 +rocketmq.producer.topic=delayTopic +demo.rocketmq.fifo-topic=delayTopic +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +### 编写代码 + +通过@Value注解引入配置文件参数,指定自定义topic +通过@Resource注解引入RocketMQClientTemplate容器 +通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行delay消息的发送(消息的参数类型可选:Object、String、byte[]、Message) +发送delay消息时需要指定延迟时间:DeliveryTimestamp + +```java +@SpringBootApplication +public class ClientProducerApplication implements CommandLineRunner { + + private static final Logger log = LoggerFactory.getLogger(ClientProducerApplication.class); + + @Value("${demo.rocketmq.delay-topic}") + private String delayTopic; + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + public static void main(String[] args) { + SpringApplication.run(ClientProducerApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendDelayMessage(); + } + + //Test sending delay message + void testSendDelayMessage() { + + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), Duration.ofSeconds(10)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, MessageBuilder. + withPayload("test message".getBytes()).build(), Duration.ofSeconds(20)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "this is my message", + Duration.ofSeconds(30)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "byte messages".getBytes(StandardCharsets.UTF_8), + Duration.ofSeconds(40)); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); + } + + @Data + @AllArgsConstructor + public class UserMeaasge implements Serializable { + int id; + private String userName; + private Byte userAge; + } + +} +``` + +# 事务消息发送 + +### 修改application.properties + +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 +**demo.rocketmq.delay-topic:**用户自定义消息发送的topic + +```java +rocketmq.producer.endpoints=127.0.0.1:8081 +rocketmq.producer.topic=transTopic +demo.rocketmq.trans-topic=transTopic +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +### 编写代码 + +通过@Value注解引入配置文件参数,指定自定义topic +通过@Resource注解引入RocketMQClientTemplate容器 +通过调用**RocketMQClientTemplate#sendMessageInTransaction**方法进行事务消息的发送(消息的参数类型可选:Object、String、byte[]、Message)。 +发送成功后会收到Pair类型的返回值,其左值代表返回值SendReceipt;右值代表Transaction,可以让用户根据本地事务处理结果的业务逻辑来决定commit还是rollback。 +使用注解@RocketMQTransactionListener标记一个自定义类,该类必须实现RocketMQTransactionChecker接口,并重写TransactionResolution check(MessageView messageView)方法。 + +```java + void testSendNormalMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build()); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + } + + void testSendTransactionMessage() throws ClientException { + Pair pair; + SendReceipt sendReceipt; + try { + pair = rocketMQClientTemplate.sendMessageInTransaction(transTopic, MessageBuilder. + withPayload(new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)).setHeader("OrderId", 1).build()); + } catch (ClientException e) { + throw new RuntimeException(e); + } + sendReceipt = pair.getSendReceipt(); + System.out.printf("transactionSend to topic %s sendReceipt=%s %n", transTopic, sendReceipt); + Transaction transaction = pair.getTransaction(); + // executed local transaction + if (doLocalTransaction(1)) { + transaction.commit(); + } else { + transaction.rollback(); + } + } + + @RocketMQTransactionListener + static class TransactionListenerImpl implements RocketMQTransactionChecker { + @Override + public TransactionResolution check(MessageView messageView) { + if (Objects.nonNull(messageView.getProperties().get("OrderId"))) { + log.info("Receive transactional message check, message={}", messageView); + return TransactionResolution.COMMIT; + } + log.info("rollback transaction"); + return TransactionResolution.ROLLBACK; + } + } + + boolean doLocalTransaction(int number) { + log.info("execute local transaction"); + return number > 0; + } +``` + +# 异步消息发送 + +### 修改application.properties + +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 +**demo.rocketmq.delay-topic:**用户自定义消息发送的topic + +```java +rocketmq.producer.endpoints=127.0.0.1:8081 +demo.rocketmq.fifo-topic=fifoTopic +demo.rocketmq.delay-topic=delayTopic +demo.rocketmq.normal-topic=normalTopic +demo.rocketmq.message-group=group1 +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +### 编写代码 + +```java + void testASycSendMessage() { + + CompletableFuture future0 = new CompletableFuture<>(); + CompletableFuture future1 = new CompletableFuture<>(); + CompletableFuture future2 = new CompletableFuture<>(); + ExecutorService sendCallbackExecutor = Executors.newCachedThreadPool(); + + future0.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + future1.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + future2.whenCompleteAsync((sendReceipt, throwable) -> { + if (null != throwable) { + log.error("Failed to send message", throwable); + return; + } + log.info("Send message successfully, messageId={}", sendReceipt.getMessageId()); + }, sendCallbackExecutor); + + CompletableFuture completableFuture0 = rocketMQClientTemplate.asyncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3), future0); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, completableFuture0); + + CompletableFuture completableFuture1 = rocketMQClientTemplate.asyncSendFifoMessage(fifoTopic, "fifo message", + messageGroup, future1); + System.out.printf("fifoSend to topic %s sendReceipt=%s %n", fifoTopic, completableFuture1); + + CompletableFuture completableFuture2 = rocketMQClientTemplate.asyncSendDelayMessage(delayTopic, + "delay message".getBytes(StandardCharsets.UTF_8), Duration.ofSeconds(10), future2); + System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, completableFuture2); + } +``` + +# 接收消息 + +### Push 模式 + +#### 修改application.properties + +```java +demo.rocketmq.endpoints=localhost:8081 +demo.rocketmq.topic=normalTopic +demo.rocketmq.consumer-group=normalGroup +demo.rocketmq.tag=* +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +#### 编写代码 + +```java +@Service +@RocketMQMessageListener(endpoints = "${demo.rocketmq.endpoints:}", topic = "${demo.rocketmq.topic:}", + consumerGroup = "${demo.rocketmq.consumer-group:}", tag = "${demo.rocketmq.tag:}") +public class MyConsumer implements RocketMQListener { + + @Override + public ConsumeResult consume(MessageView messageView) { + System.out.println("handle my message:" + messageView); + return ConsumeResult.SUCCESS; + } +} +``` + +### Simple 模式 + +#### 同步订阅 + +##### 修改application.properties + +```java +rocketmq.simple-consumer.endpoints=localhost:8081 +rocketmq.simple-consumer.consumer-group=normalGroup +rocketmq.simple-consumer.topic=normalTopic +rocketmq.simple-consumer.tag=* +rocketmq.simple-consumer.filter-expression-type=tag +ext.rocketmq.topic=delayTopic +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + +##### 编写代码 + +此时测验原始的RocketMQClientTemplate和我们拓展的ExtRocketMQTemplate是否有效: + +1. 首先定义拓展ExtRocketMQTemplate,需要加上@ExtConsumerResetConfiguration,并指定topic等关键字段。 + +```java +@ExtConsumerResetConfiguration(topic = "${ext.rocketmq.topic:}") +public class ExtRocketMQTemplate extends RocketMQClientTemplate { +} +``` + +2. receiveSimpleConsumerMessage方法消费topic=normalTopic的消息,receiveExtSimpleConsumerMessage方法消费topic=delayTopic的消息。 + +```java +@SpringBootApplication +public class ClientConsumeApplication implements CommandLineRunner { + private static final Logger log = LoggerFactory.getLogger(ClientConsumeApplication.class); + + @Resource + RocketMQClientTemplate rocketMQClientTemplate; + + @Resource(name = "extRocketMQTemplate") + RocketMQClientTemplate extRocketMQTemplate; + + public static void main(String[] args) { + SpringApplication.run(ClientConsumeApplication.class, args); + } + + @Override + public void run(String... args) throws Exception { + receiveSimpleConsumerMessage(); + receiveExtSimpleConsumerMessage(); + } + + public void receiveSimpleConsumerMessage() throws ClientException { + do { + final List messages = rocketMQClientTemplate.receive(16, Duration.ofSeconds(15)); + log.info("Received {} message(s)", messages.size()); + for (MessageView message : messages) { + log.info("receive message, topic:" + message.getTopic() + " messageId:" + message.getMessageId()); + final MessageId messageId = message.getMessageId(); + try { + rocketMQClientTemplate.ack(message); + log.info("Message is acknowledged successfully, messageId={}", messageId); + } catch (Throwable t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + } + } + } while (true); + } + + public void receiveExtSimpleConsumerMessage() throws ClientException { + do { + final List messages = extRocketMQTemplate.receive(16, Duration.ofSeconds(15)); + log.info("Received {} message(s)", messages.size()); + for (MessageView message : messages) { + log.info("receive message, topic:" + message.getTopic() + " messageId:" + message.getMessageId()); + final MessageId messageId = message.getMessageId(); + try { + rocketMQClientTemplate.ack(message); + log.info("Message is acknowledged successfully, messageId={}", messageId); + } catch (Throwable t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + } + } + } while (true); + } + +} +``` + +#### 异步订阅 + +##### 修改application.properties + +```java +rocketmq.simple-consumer.endpoints=localhost:8081 +rocketmq.simple-consumer.consumer-group=normalGroup +rocketmq.simple-consumer.topic=normalTopic +rocketmq.simple-consumer.tag=* +rocketmq.simple-consumer.filter-expression-type=tag +``` + +##### 编写代码 + +```java + public void receiveSimpleConsumerMessageAsynchronously() { + do { + int maxMessageNum = 16; + // Set message invisible duration after it is received. + Duration invisibleDuration = Duration.ofSeconds(15); + // Set individual thread pool for receive callback. + ExecutorService receiveCallbackExecutor = Executors.newCachedThreadPool(); + // Set individual thread pool for ack callback. + ExecutorService ackCallbackExecutor = Executors.newCachedThreadPool(); + CompletableFuture> future0; + try { + future0 = rocketMQClientTemplate.receiveAsync(maxMessageNum, invisibleDuration); + } catch (ClientException | IOException e) { + throw new RuntimeException(e); + } + future0.whenCompleteAsync(((messages, throwable) -> { + if (null != throwable) { + log.error("Failed to receive message from remote", throwable); + // Return early. + return; + } + log.info("Received {} message(s)", messages.size()); + // Using messageView as key rather than message id because message id may be duplicated. + final Map> map = + messages.stream().collect(Collectors.toMap(message -> message, rocketMQClientTemplate::ackAsync)); + for (Map.Entry> entry : map.entrySet()) { + final MessageId messageId = entry.getKey().getMessageId(); + final CompletableFuture future = entry.getValue(); + future.whenCompleteAsync((v, t) -> { + if (null != t) { + log.error("Message is failed to be acknowledged, messageId={}", messageId, t); + // Return early. + return; + } + log.info("Message is acknowledged successfully, messageId={}", messageId); + }, ackCallbackExecutor); + } + + }), receiveCallbackExecutor); + } while (true); + } +``` \ No newline at end of file From 30c66d6bbea84ef7d79c9b6334da6c78b8028391 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 27 May 2023 00:19:14 +0800 Subject: [PATCH 07/13] fix:Modify the file name from README.md to README-CN.md --- rocketmq-client-spring-boot-samples/{README.md => README-CN.md} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rocketmq-client-spring-boot-samples/{README.md => README-CN.md} (100%) diff --git a/rocketmq-client-spring-boot-samples/README.md b/rocketmq-client-spring-boot-samples/README-CN.md similarity index 100% rename from rocketmq-client-spring-boot-samples/README.md rename to rocketmq-client-spring-boot-samples/README-CN.md From 8fe64130f4580c008c81e03f4d5559322643ec33 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 27 May 2023 01:44:51 +0800 Subject: [PATCH 08/13] feat:Add test module for ACL permission control --- .../README-CN.md | 190 +++++++++++++++--- rocketmq-client-spring-boot-samples/pom.xml | 2 + .../rocketmq-client-consume-acl-demo/pom.xml | 29 +++ .../ClientConsumerACLApplication.java | 29 +++ .../springboot/consumer/ACLConsumer.java | 36 ++++ .../src/main/resources/application.properties | 7 + .../rocketmq-client-producer-acl-demo/pom.xml | 28 +++ .../ClientProducerACLApplication.java | 66 ++++++ .../springboot/domain/UserMessage.java | 50 +++++ .../src/main/resources/application.properties | 5 + 10 files changed, 415 insertions(+), 27 deletions(-) create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java create mode 100644 rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties diff --git a/rocketmq-client-spring-boot-samples/README-CN.md b/rocketmq-client-spring-boot-samples/README-CN.md index af261ea9..8a698c9e 100644 --- a/rocketmq-client-spring-boot-samples/README-CN.md +++ b/rocketmq-client-spring-boot-samples/README-CN.md @@ -1,9 +1,12 @@ + + # Normal消息发送 + + ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 -**demo.rocketmq.normal-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.normal-topic:**用户自定义消息发送的topic ```properties rocketmq.producer.endpoints=127.0.0.1:8081 @@ -14,11 +17,11 @@ demo.rocketmq.normal-topic=normalTopic > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ### 编写代码 -通过@Value注解引入配置文件参数,指定自定义topic -通过@Resource注解引入RocketMQClientTemplate容器 -通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行normal消息的发送(消息的参数类型可选:Object、String、byte[]、Message) +通过@Value注解引入配置文件参数,指定自定义topic
通过@Resource注解引入RocketMQClientTemplate容器
通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行normal消息的发送(消息的参数类型可选:Object、String、byte[]、Message) ```java @SpringBootApplication @@ -69,13 +72,15 @@ public class ClientProducerApplication implements CommandLineRunner { } ``` + + # FIFO消息发送 + + ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 -**demo.rocketmq.fifo-topic:**用户自定义消息发送的topic -**demo.rocketmq.message-group=group1:**顺序消息的顺序关系通过消息组(MessageGroup)判定和识别,发送顺序消息时需要为每条消息设置归属的消息组,相同消息组的多条消息之间遵循先进先出的顺序关系,不同消息组、无消息组的消息之间不涉及顺序性。 +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.fifo-topic:**用户自定义消息发送的topic
**demo.rocketmq.message-group=group1:**顺序消息的顺序关系通过消息组(MessageGroup)判定和识别,发送顺序消息时需要为每条消息设置归属的消息组,相同消息组的多条消息之间遵循先进先出的顺序关系,不同消息组、无消息组的消息之间不涉及顺序性。 ```properties rocketmq.producer.endpoints=127.0.0.1:8081 @@ -87,12 +92,11 @@ demo.rocketmq.message-group=group1 > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ### 编写代码 -通过@Value注解引入配置文件参数,指定自定义topic -通过@Resource注解引入RocketMQClientTemplate容器 -通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行fifo消息的发送(参数类型可选:Object、String、byte[]、Message) -发送fifo消息时需要设置参数:消费者组(MessageGroup) +通过@Value注解引入配置文件参数,指定自定义topic
通过@Resource注解引入RocketMQClientTemplate容器
通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行fifo消息的发送(参数类型可选:Object、String、byte[]、Message)
发送fifo消息时需要设置参数:消费者组(MessageGroup) ```java @SpringBootApplication @@ -146,12 +150,15 @@ public class ClientProducerApplication implements CommandLineRunner { } ``` + + # Delay消息发送 + + ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 -**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic ```java rocketmq.producer.endpoints=127.0.0.1:8081 @@ -162,12 +169,11 @@ demo.rocketmq.fifo-topic=delayTopic > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ### 编写代码 -通过@Value注解引入配置文件参数,指定自定义topic -通过@Resource注解引入RocketMQClientTemplate容器 -通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行delay消息的发送(消息的参数类型可选:Object、String、byte[]、Message) -发送delay消息时需要指定延迟时间:DeliveryTimestamp +通过@Value注解引入配置文件参数,指定自定义topic
通过@Resource注解引入RocketMQClientTemplate容器
通过调用**RocketMQClientTemplate#syncSendNormalMessage**方法进行delay消息的发送(消息的参数类型可选:Object、String、byte[]、Message)
发送delay消息时需要指定延迟时间:DeliveryTimestamp ```java @SpringBootApplication @@ -220,12 +226,15 @@ public class ClientProducerApplication implements CommandLineRunner { } ``` + + # 事务消息发送 + + ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 -**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic ```java rocketmq.producer.endpoints=127.0.0.1:8081 @@ -236,13 +245,11 @@ demo.rocketmq.trans-topic=transTopic > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ### 编写代码 -通过@Value注解引入配置文件参数,指定自定义topic -通过@Resource注解引入RocketMQClientTemplate容器 -通过调用**RocketMQClientTemplate#sendMessageInTransaction**方法进行事务消息的发送(消息的参数类型可选:Object、String、byte[]、Message)。 -发送成功后会收到Pair类型的返回值,其左值代表返回值SendReceipt;右值代表Transaction,可以让用户根据本地事务处理结果的业务逻辑来决定commit还是rollback。 -使用注解@RocketMQTransactionListener标记一个自定义类,该类必须实现RocketMQTransactionChecker接口,并重写TransactionResolution check(MessageView messageView)方法。 +通过@Value注解引入配置文件参数,指定自定义topic
通过@Resource注解引入RocketMQClientTemplate容器
通过调用**RocketMQClientTemplate#sendMessageInTransaction**方法进行事务消息的发送(消息的参数类型可选:Object、String、byte[]、Message)。
发送成功后会收到Pair类型的返回值,其左值代表返回值SendReceipt;右值代表Transaction,可以让用户根据本地事务处理结果的业务逻辑来决定commit还是rollback。
使用注解@RocketMQTransactionListener标记一个自定义类,该类必须实现RocketMQTransactionChecker接口,并重写TransactionResolution check(MessageView messageView)方法。 ```java void testSendNormalMessage() { @@ -301,12 +308,15 @@ demo.rocketmq.trans-topic=transTopic } ``` + + # 异步消息发送 + + ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。 -**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic ```java rocketmq.producer.endpoints=127.0.0.1:8081 @@ -319,6 +329,8 @@ demo.rocketmq.message-group=group1 > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ### 编写代码 ```java @@ -367,10 +379,16 @@ demo.rocketmq.message-group=group1 } ``` + + # 接收消息 + + ### Push 模式 + + #### 修改application.properties ```java @@ -383,6 +401,8 @@ demo.rocketmq.tag=* > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + #### 编写代码 ```java @@ -399,10 +419,16 @@ public class MyConsumer implements RocketMQListener { } ``` + + ### Simple 模式 + + #### 同步订阅 + + ##### 修改application.properties ```java @@ -417,6 +443,8 @@ ext.rocketmq.topic=delayTopic > 注意: > 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + ##### 编写代码 此时测验原始的RocketMQClientTemplate和我们拓展的ExtRocketMQTemplate是否有效: @@ -489,8 +517,12 @@ public class ClientConsumeApplication implements CommandLineRunner { } ``` + + #### 异步订阅 + + ##### 修改application.properties ```java @@ -501,6 +533,8 @@ rocketmq.simple-consumer.tag=* rocketmq.simple-consumer.filter-expression-type=tag ``` + + ##### 编写代码 ```java @@ -545,4 +579,106 @@ rocketmq.simple-consumer.filter-expression-type=tag }), receiveCallbackExecutor); } while (true); } +``` + + + +# ACL功能 + + + +## Producer端 + + + +### 修改application.properties + +```java +rocketmq.producer.endpoints=localhost:8081 +rocketmq.producer.topic=normalTopic +rocketmq.producer.access-key=yourAccessKey +rocketmq.producer.secret-key=yourSecretKey +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + + +### 编写代码 + +```java +@SpringBootApplication +public class ClientProducerACLApplication implements CommandLineRunner { + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + + @Value("${demo.acl.rocketmq.normal-topic}") + private String normalTopic; + + + public static void main(String[] args) { + SpringApplication.run(ClientProducerACLApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendNormalMessage(); + } + + void testSendNormalMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build()); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + } +} + +``` + + + +## Consumer端 + + + +### 修改application.properties + +```java +demo.acl.rocketmq.endpoints=localhost:8081 +demo.acl.rocketmq.topic=normalTopic +demo.acl.rocketmq.consumer-group=normalGroup +demo.acl.rocketmq.tag=* +demo.acl.rocketmq.access-key=yourAccessKey +demo.acl.rocketmq.secret-key=yourSecretKey +``` + +> 注意: +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 + + + +### 编写代码 + +```java +@Service +@RocketMQMessageListener(accessKey = "${demo.acl.rocketmq.access-key:}", secretKey = "${demo.acl.rocketmq.secret-key:}", endpoints = "${demo.acl.rocketmq.endpoints:}", topic = "${demo.acl.rocketmq.topic:}", + consumerGroup = "${demo.acl.rocketmq.consumer-group:}", tag = "${demo.acl.rocketmq.tag:}") +public class ACLConsumer implements RocketMQListener { + @Override + public ConsumeResult consume(MessageView messageView) { + System.out.println("handle my acl message:" + messageView); + return ConsumeResult.SUCCESS; + } +} ``` \ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/pom.xml b/rocketmq-client-spring-boot-samples/pom.xml index 5254887c..0e144730 100644 --- a/rocketmq-client-spring-boot-samples/pom.xml +++ b/rocketmq-client-spring-boot-samples/pom.xml @@ -30,6 +30,8 @@ rocketmq-client-producer-demo rocketmq-client-consume-demo + rocketmq-client-consume-acl-demo + rocketmq-client-producer-acl-demo diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml new file mode 100644 index 00000000..c39ce685 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml @@ -0,0 +1,29 @@ + + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-samples + 2.2.4-SNAPSHOT + + rocketmq-client-consume-acl-demo + + + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java new file mode 100644 index 00000000..544d5903 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.samples.springboot; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ClientConsumerACLApplication { + + public static void main(String[] args) { + SpringApplication.run(ClientConsumerACLApplication.class, args); + } + +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java new file mode 100644 index 00000000..f6d314f1 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java @@ -0,0 +1,36 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.samples.springboot.consumer; + + +import org.apache.rocketmq.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.core.RocketMQListener; +import org.springframework.stereotype.Service; + +@Service +@RocketMQMessageListener(accessKey = "${demo.acl.rocketmq.access-key:}", secretKey = "${demo.acl.rocketmq.secret-key:}", endpoints = "${demo.acl.rocketmq.endpoints:}", topic = "${demo.acl.rocketmq.topic:}", + consumerGroup = "${demo.acl.rocketmq.consumer-group:}", tag = "${demo.acl.rocketmq.tag:}") +public class ACLConsumer implements RocketMQListener { + @Override + public ConsumeResult consume(MessageView messageView) { + System.out.println("handle my acl message:" + messageView); + return ConsumeResult.SUCCESS; + } +} + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties new file mode 100644 index 00000000..cf7a0586 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties @@ -0,0 +1,7 @@ +demo.acl.rocketmq.endpoints=localhost:8081 +demo.acl.rocketmq.topic=normalTopic +demo.acl.rocketmq.consumer-group=normalGroup +demo.acl.rocketmq.tag=* +demo.acl.rocketmq.access-key=yourAccessKey +demo.acl.rocketmq.secret-key=yourSecretKey + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml new file mode 100644 index 00000000..87adb351 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml @@ -0,0 +1,28 @@ + + + + 4.0.0 + + org.apache.rocketmq + rocketmq-client-spring-boot-samples + 2.2.4-SNAPSHOT + + + rocketmq-client-producer-acl-demo + diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java new file mode 100644 index 00000000..0d16dc28 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.samples.springboot; + +import org.apache.rocketmq.client.apis.ClientException; +import org.apache.rocketmq.client.apis.producer.SendReceipt; +import org.apache.rocketmq.client.core.RocketMQClientTemplate; +import org.apache.rocketmq.samples.springboot.domain.UserMessage; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.messaging.support.MessageBuilder; + +import javax.annotation.Resource; +import java.nio.charset.StandardCharsets; + +@SpringBootApplication +public class ClientProducerACLApplication implements CommandLineRunner { + + @Resource + private RocketMQClientTemplate rocketMQClientTemplate; + + @Value("${demo.acl.rocketmq.normal-topic}") + private String normalTopic; + + + public static void main(String[] args) { + SpringApplication.run(ClientProducerACLApplication.class, args); + } + + @Override + public void run(String... args) throws ClientException { + testSendNormalMessage(); + } + + void testSendNormalMessage() { + SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() + .setId(1).setUserName("name").setUserAge((byte) 3)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + + sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. + withPayload("test message".getBytes()).build()); + System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); + } +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java new file mode 100644 index 00000000..b31e48d0 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.samples.springboot.domain; + +public class UserMessage { + int id; + private String userName; + private Byte userAge; + + public int getId() { + return id; + } + + public UserMessage setId(int id) { + this.id = id; + return this; + } + + public String getUserName() { + return userName; + } + + public UserMessage setUserName(String userName) { + this.userName = userName; + return this; + } + + public Byte getUserAge() { + return userAge; + } + + public UserMessage setUserAge(Byte userAge) { + this.userAge = userAge; + return this; + } +} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties new file mode 100644 index 00000000..72f893e2 --- /dev/null +++ b/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties @@ -0,0 +1,5 @@ +rocketmq.producer.endpoints=localhost:8081 +rocketmq.producer.topic=normalTopic +rocketmq.producer.access-key=yourAccessKey +rocketmq.producer.secret-key=yourSecretKey + From 43bd589cecea12cabe4e01c870c8113ee5214a1b Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Fri, 2 Jun 2023 16:13:57 +0800 Subject: [PATCH 09/13] fix:Remove unnecessary Code in UserGuide And change the module Name --- pom.xml | 6 +-- .../pom.xml | 8 ++-- .../README-CN.md | 48 +++++++------------ .../pom.xml | 20 ++++---- .../pom.xml | 4 +- .../ClientConsumerACLApplication.java | 0 .../springboot/consumer/ACLConsumer.java | 0 .../src/main/resources/application.properties | 0 .../rocketmq-v5-client-consume-demo}/pom.xml | 4 +- .../springboot/ClientConsumeApplication.java | 0 .../springboot/ExtRocketMQTemplate.java | 0 .../springboot/consumer/MyConsumer.java | 0 .../src/main/resources/application.properties | 0 .../pom.xml | 4 +- .../ClientProducerACLApplication.java | 0 .../springboot/domain/UserMessage.java | 0 .../src/main/resources/application.properties | 0 .../rocketmq-v5-client-producer-demo}/pom.xml | 4 +- .../springboot/ClientProducerApplication.java | 0 .../springboot/domain/UserMessage.java | 0 .../src/main/resources/application.properties | 0 .../style/copyright/Apache.xml | 0 .../style/copyright/profiles_settings.xml | 0 .../style/rmq_checkstyle.xml | 0 .../style/rmq_codeStyle.xml | 0 .../pom.xml | 12 ++--- .../pom.xml | 10 ++-- .../ExtConsumerResetConfiguration.java | 0 .../ExtProducerResetConfiguration.java | 0 .../annotation/RocketMQMessageListener.java | 0 ...ketMQMessageListenerBeanPostProcessor.java | 0 .../RocketMQTransactionListener.java | 0 .../ExtConsumerResetConfiguration.java | 0 .../ExtTemplateResetConfiguration.java | 0 .../ListenerContainerConfiguration.java | 0 .../MessageConverterConfiguration.java | 0 .../RocketMQAutoConfiguration.java | 0 .../RocketMQListenerConfiguration.java | 0 .../autoconfigure/RocketMQProperties.java | 0 .../RocketMQTransactionConfiguration.java | 0 .../apache/rocketmq/client/common/Pair.java | 0 .../client/core/RocketMQClientTemplate.java | 0 .../client/core/RocketMQListener.java | 0 .../core/RocketMQTransactionChecker.java | 0 .../support/DefaultListenerContainer.java | 0 .../client/support/RocketMQHeaders.java | 0 .../support/RocketMQListenerContainer.java | 0 .../support/RocketMQMessageConverter.java | 0 .../rocketmq/client/support/RocketMQUtil.java | 0 .../main/resources/META-INF/spring.factories | 0 50 files changed, 52 insertions(+), 68 deletions(-) rename {rocketmq-client-spring-boot-parent => rocketmq-v5-client-spring-boot-parent}/pom.xml (96%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/README-CN.md (89%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/pom.xml (78%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo}/pom.xml (90%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo}/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo}/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo}/src/main/resources/application.properties (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo}/pom.xml (90%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo}/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo}/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo}/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo}/src/main/resources/application.properties (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo}/pom.xml (89%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo}/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo}/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo}/src/main/resources/application.properties (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo}/pom.xml (90%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo}/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo}/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java (100%) rename {rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo => rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo}/src/main/resources/application.properties (100%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/style/copyright/Apache.xml (100%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/style/copyright/profiles_settings.xml (100%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/style/rmq_checkstyle.xml (100%) rename {rocketmq-client-spring-boot-samples => rocketmq-v5-client-spring-boot-samples}/style/rmq_codeStyle.xml (100%) rename {rocketmq-client-spring-boot-starter => rocketmq-v5-client-spring-boot-starter}/pom.xml (81%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/pom.xml (91%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/common/Pair.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java (100%) rename {rocketmq-client-spring-boot => rocketmq-v5-client-spring-boot}/src/main/resources/META-INF/spring.factories (100%) diff --git a/pom.xml b/pom.xml index 099d9052..43e278fc 100644 --- a/pom.xml +++ b/pom.xml @@ -215,9 +215,9 @@ rocketmq-spring-boot-parent rocketmq-spring-boot rocketmq-spring-boot-starter - rocketmq-client-spring-boot - rocketmq-client-spring-boot-parent - rocketmq-client-spring-boot-starter + rocketmq-v5-client-spring-boot + rocketmq-v5-client-spring-boot-parent + rocketmq-v5-client-spring-boot-starter diff --git a/rocketmq-client-spring-boot-parent/pom.xml b/rocketmq-v5-client-spring-boot-parent/pom.xml similarity index 96% rename from rocketmq-client-spring-boot-parent/pom.xml rename to rocketmq-v5-client-spring-boot-parent/pom.xml index 8045ee74..a0a10fd5 100644 --- a/rocketmq-client-spring-boot-parent/pom.xml +++ b/rocketmq-v5-client-spring-boot-parent/pom.xml @@ -26,12 +26,12 @@ ../pom.xml - rocketmq-client-spring-boot-parent + rocketmq-v5-client-spring-boot-parent pom 2.2.4-SNAPSHOT - rocketmq-client-spring-boot-parent - rocketmq-client-spring-boot-parent + rocketmq-v5-client-spring-boot-parent + rocketmq-v5-client-spring-boot-parent ${project.basedir}/.. @@ -106,7 +106,7 @@ org.apache.rocketmq - rocketmq-client-spring-boot + rocketmq-v5-client-spring-boot ${rocketmq.client.spring.boot.version} diff --git a/rocketmq-client-spring-boot-samples/README-CN.md b/rocketmq-v5-client-spring-boot-samples/README-CN.md similarity index 89% rename from rocketmq-client-spring-boot-samples/README-CN.md rename to rocketmq-v5-client-spring-boot-samples/README-CN.md index 8a698c9e..9933129a 100644 --- a/rocketmq-client-spring-boot-samples/README-CN.md +++ b/rocketmq-v5-client-spring-boot-samples/README-CN.md @@ -6,7 +6,7 @@ ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.normal-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:** 用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.normal-topic:** 用户自定义消息发送的topic ```properties rocketmq.producer.endpoints=127.0.0.1:8081 @@ -80,7 +80,7 @@ public class ClientProducerApplication implements CommandLineRunner { ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.fifo-topic:**用户自定义消息发送的topic
**demo.rocketmq.message-group=group1:**顺序消息的顺序关系通过消息组(MessageGroup)判定和识别,发送顺序消息时需要为每条消息设置归属的消息组,相同消息组的多条消息之间遵循先进先出的顺序关系,不同消息组、无消息组的消息之间不涉及顺序性。 +**rocketmq.producer.topic:** 用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.fifo-topic:** 用户自定义消息发送的topic
**demo.rocketmq.message-group=group1:** 顺序消息的顺序关系通过消息组(MessageGroup)判定和识别,发送顺序消息时需要为每条消息设置归属的消息组,相同消息组的多条消息之间遵循先进先出的顺序关系,不同消息组、无消息组的消息之间不涉及顺序性。 ```properties rocketmq.producer.endpoints=127.0.0.1:8081 @@ -158,9 +158,9 @@ public class ClientProducerApplication implements CommandLineRunner { ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:** 用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:** 用户自定义消息发送的topic -```java +```class rocketmq.producer.endpoints=127.0.0.1:8081 rocketmq.producer.topic=delayTopic demo.rocketmq.fifo-topic=delayTopic @@ -234,9 +234,9 @@ public class ClientProducerApplication implements CommandLineRunner { ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:** 用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:** 用户自定义消息发送的topic -```java +```class rocketmq.producer.endpoints=127.0.0.1:8081 rocketmq.producer.topic=transTopic demo.rocketmq.trans-topic=transTopic @@ -251,23 +251,7 @@ demo.rocketmq.trans-topic=transTopic 通过@Value注解引入配置文件参数,指定自定义topic
通过@Resource注解引入RocketMQClientTemplate容器
通过调用**RocketMQClientTemplate#sendMessageInTransaction**方法进行事务消息的发送(消息的参数类型可选:Object、String、byte[]、Message)。
发送成功后会收到Pair类型的返回值,其左值代表返回值SendReceipt;右值代表Transaction,可以让用户根据本地事务处理结果的业务逻辑来决定commit还是rollback。
使用注解@RocketMQTransactionListener标记一个自定义类,该类必须实现RocketMQTransactionChecker接口,并重写TransactionResolution check(MessageView messageView)方法。 -```java - void testSendNormalMessage() { - SendReceipt sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, new UserMessage() - .setId(1).setUserName("name").setUserAge((byte) 3)); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); - - sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "normal message"); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); - - sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, "byte message".getBytes(StandardCharsets.UTF_8)); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); - - sendReceipt = rocketMQClientTemplate.syncSendNormalMessage(normalTopic, MessageBuilder. - withPayload("test message".getBytes()).build()); - System.out.printf("normalSend to topic %s sendReceipt=%s %n", normalTopic, sendReceipt); - } - +```class void testSendTransactionMessage() throws ClientException { Pair pair; SendReceipt sendReceipt; @@ -316,9 +300,9 @@ demo.rocketmq.trans-topic=transTopic ### 修改application.properties -**rocketmq.producer.topic:**用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:**用户自定义消息发送的topic +**rocketmq.producer.topic:** 用于给生产者设置topic名称(可选,但建议使用),生产者可以在消息发布之前**预取**topic路由。
**demo.rocketmq.delay-topic:** 用户自定义消息发送的topic -```java +```class rocketmq.producer.endpoints=127.0.0.1:8081 demo.rocketmq.fifo-topic=fifoTopic demo.rocketmq.delay-topic=delayTopic @@ -333,7 +317,7 @@ demo.rocketmq.message-group=group1 ### 编写代码 -```java +```class void testASycSendMessage() { CompletableFuture future0 = new CompletableFuture<>(); @@ -391,7 +375,7 @@ demo.rocketmq.message-group=group1 #### 修改application.properties -```java +```class demo.rocketmq.endpoints=localhost:8081 demo.rocketmq.topic=normalTopic demo.rocketmq.consumer-group=normalGroup @@ -431,7 +415,7 @@ public class MyConsumer implements RocketMQListener { ##### 修改application.properties -```java +```class rocketmq.simple-consumer.endpoints=localhost:8081 rocketmq.simple-consumer.consumer-group=normalGroup rocketmq.simple-consumer.topic=normalTopic @@ -525,7 +509,7 @@ public class ClientConsumeApplication implements CommandLineRunner { ##### 修改application.properties -```java +```class rocketmq.simple-consumer.endpoints=localhost:8081 rocketmq.simple-consumer.consumer-group=normalGroup rocketmq.simple-consumer.topic=normalTopic @@ -537,7 +521,7 @@ rocketmq.simple-consumer.filter-expression-type=tag ##### 编写代码 -```java +```class public void receiveSimpleConsumerMessageAsynchronously() { do { int maxMessageNum = 16; @@ -593,7 +577,7 @@ rocketmq.simple-consumer.filter-expression-type=tag ### 修改application.properties -```java +```class rocketmq.producer.endpoints=localhost:8081 rocketmq.producer.topic=normalTopic rocketmq.producer.access-key=yourAccessKey @@ -654,7 +638,7 @@ public class ClientProducerACLApplication implements CommandLineRunner { ### 修改application.properties -```java +```class demo.acl.rocketmq.endpoints=localhost:8081 demo.acl.rocketmq.topic=normalTopic demo.acl.rocketmq.consumer-group=normalGroup diff --git a/rocketmq-client-spring-boot-samples/pom.xml b/rocketmq-v5-client-spring-boot-samples/pom.xml similarity index 78% rename from rocketmq-client-spring-boot-samples/pom.xml rename to rocketmq-v5-client-spring-boot-samples/pom.xml index 0e144730..02b00837 100644 --- a/rocketmq-client-spring-boot-samples/pom.xml +++ b/rocketmq-v5-client-spring-boot-samples/pom.xml @@ -20,32 +20,32 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples pom 2.2.4-SNAPSHOT - rocketmq-client-spring-boot-samples - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples - rocketmq-client-producer-demo - rocketmq-client-consume-demo - rocketmq-client-consume-acl-demo - rocketmq-client-producer-acl-demo + rocketmq-v5-client-producer-demo + rocketmq-v5-client-consume-demo + rocketmq-v5-client-consume-acl-demo + rocketmq-v5-client-producer-acl-demo 1.8 1.8 - 2.2.4-SNAPSHOT + 2.2.4-SNAPSHOT org.apache.rocketmq - rocketmq-client-spring-boot-starter - ${rocketmq-client-spring-boot-starter-version} + rocketmq-v5-client-spring-boot-starter + ${rocketmq-v5-client-spring-boot-starter-version} diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/pom.xml similarity index 90% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/pom.xml index 4feb7fad..082fd24e 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/pom.xml +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/pom.xml @@ -20,10 +20,10 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples 2.2.4-SNAPSHOT + rocketmq-v5-client-consume-acl-demo - rocketmq-client-consume-demo
diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumerACLApplication.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/src/main/resources/application.properties rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/pom.xml similarity index 90% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/pom.xml index c39ce685..2e549a6d 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-acl-demo/pom.xml +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/pom.xml @@ -20,10 +20,10 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples 2.2.4-SNAPSHOT - rocketmq-client-consume-acl-demo + rocketmq-v5-client-consume-demo
diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ExtRocketMQTemplate.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-consume-demo/src/main/resources/application.properties rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/pom.xml similarity index 89% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/pom.xml index 87adb351..c7e2cd1d 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/pom.xml +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/pom.xml @@ -20,9 +20,9 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples 2.2.4-SNAPSHOT - rocketmq-client-producer-acl-demo + rocketmq-v5-client-producer-acl-demo
diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-acl-demo/src/main/resources/application.properties rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/pom.xml similarity index 90% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/pom.xml index 40690714..d6a68592 100644 --- a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/pom.xml +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/pom.xml @@ -20,10 +20,10 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-samples + rocketmq-v5-client-spring-boot-samples 2.2.4-SNAPSHOT - rocketmq-client-producer-demo + rocketmq-v5-client-producer-demo
\ No newline at end of file diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/domain/UserMessage.java diff --git a/rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties similarity index 100% rename from rocketmq-client-spring-boot-samples/rocketmq-client-producer-demo/src/main/resources/application.properties rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties diff --git a/rocketmq-client-spring-boot-samples/style/copyright/Apache.xml b/rocketmq-v5-client-spring-boot-samples/style/copyright/Apache.xml similarity index 100% rename from rocketmq-client-spring-boot-samples/style/copyright/Apache.xml rename to rocketmq-v5-client-spring-boot-samples/style/copyright/Apache.xml diff --git a/rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml b/rocketmq-v5-client-spring-boot-samples/style/copyright/profiles_settings.xml similarity index 100% rename from rocketmq-client-spring-boot-samples/style/copyright/profiles_settings.xml rename to rocketmq-v5-client-spring-boot-samples/style/copyright/profiles_settings.xml diff --git a/rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml b/rocketmq-v5-client-spring-boot-samples/style/rmq_checkstyle.xml similarity index 100% rename from rocketmq-client-spring-boot-samples/style/rmq_checkstyle.xml rename to rocketmq-v5-client-spring-boot-samples/style/rmq_checkstyle.xml diff --git a/rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml b/rocketmq-v5-client-spring-boot-samples/style/rmq_codeStyle.xml similarity index 100% rename from rocketmq-client-spring-boot-samples/style/rmq_codeStyle.xml rename to rocketmq-v5-client-spring-boot-samples/style/rmq_codeStyle.xml diff --git a/rocketmq-client-spring-boot-starter/pom.xml b/rocketmq-v5-client-spring-boot-starter/pom.xml similarity index 81% rename from rocketmq-client-spring-boot-starter/pom.xml rename to rocketmq-v5-client-spring-boot-starter/pom.xml index c3d433de..a8d638bf 100644 --- a/rocketmq-client-spring-boot-starter/pom.xml +++ b/rocketmq-v5-client-spring-boot-starter/pom.xml @@ -20,17 +20,17 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-parent + rocketmq-v5-client-spring-boot-parent 2.2.4-SNAPSHOT - ../rocketmq-client-spring-boot-parent/pom.xml + ../rocketmq-v5-client-spring-boot-parent/pom.xml - rocketmq-client-spring-boot-starter + rocketmq-v5-client-spring-boot-starter jar 2.2.4-SNAPSHOT - rocketmq-client-spring-boot-starter - rocketmq-client-spring-boot-starter + rocketmq-v5-client-spring-boot-starter + rocketmq-v5-client-spring-boot-starter 8 @@ -47,7 +47,7 @@ org.apache.rocketmq - rocketmq-client-spring-boot + rocketmq-v5-client-spring-boot
diff --git a/rocketmq-client-spring-boot/pom.xml b/rocketmq-v5-client-spring-boot/pom.xml similarity index 91% rename from rocketmq-client-spring-boot/pom.xml rename to rocketmq-v5-client-spring-boot/pom.xml index ac7c7dc9..960189a6 100644 --- a/rocketmq-client-spring-boot/pom.xml +++ b/rocketmq-v5-client-spring-boot/pom.xml @@ -20,16 +20,16 @@ 4.0.0 org.apache.rocketmq - rocketmq-client-spring-boot-parent + rocketmq-v5-client-spring-boot-parent 2.2.4-SNAPSHOT - ../rocketmq-client-spring-boot-parent/pom.xml + ../rocketmq-v5-client-spring-boot-parent/pom.xml - rocketmq-client-spring-boot + rocketmq-v5-client-spring-boot jar - rocketmq-client-spring-boot - rocketmq-client-spring-boot + rocketmq-v5-client-spring-boot + rocketmq-v5-client-spring-boot diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtConsumerResetConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/ExtProducerResetConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListenerBeanPostProcessor.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQTransactionListener.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtConsumerResetConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ExtTemplateResetConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/ListenerContainerConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/MessageConverterConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQListenerConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQProperties.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQTransactionConfiguration.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/common/Pair.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQClientTemplate.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQListener.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/core/RocketMQTransactionChecker.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/DefaultListenerContainer.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQHeaders.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQListenerContainer.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQMessageConverter.java diff --git a/rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java similarity index 100% rename from rocketmq-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java rename to rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java diff --git a/rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories b/rocketmq-v5-client-spring-boot/src/main/resources/META-INF/spring.factories similarity index 100% rename from rocketmq-client-spring-boot/src/main/resources/META-INF/spring.factories rename to rocketmq-v5-client-spring-boot/src/main/resources/META-INF/spring.factories From e021e059dbc6fc44eaf339f41b8fc47775ec8305 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 3 Jun 2023 18:29:49 +0800 Subject: [PATCH 10/13] fix:fix license checker --- .../rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.java | 1 - .../rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java | 1 - 2 files changed, 2 deletions(-) diff --git a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.java index 9f10438e..a8c7379c 100644 --- a/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.java +++ b/rocketmq-spring-boot/src/main/java/org/apache/rocketmq/spring/autoconfigure/RocketMQAutoConfiguration.java @@ -14,7 +14,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package org.apache.rocketmq.spring.autoconfigure; import org.apache.rocketmq.client.AccessChannel; diff --git a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java index 786888f2..11763c88 100644 --- a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java +++ b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/autoconfigure/RocketMQAutoConfiguration.java @@ -48,7 +48,6 @@ import java.util.Collections; import java.util.Objects; - @Configuration @EnableConfigurationProperties(RocketMQProperties.class) @Import({MessageConverterConfiguration.class, ListenerContainerConfiguration.class, ExtTemplateResetConfiguration.class, From 892076f46064f47270d7812c708fafce27228b3e Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Mon, 5 Jun 2023 11:59:01 +0800 Subject: [PATCH 11/13] fix:fix license checker --- .licenserc.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/.licenserc.yaml b/.licenserc.yaml index ba91d1fa..5eec96d9 100644 --- a/.licenserc.yaml +++ b/.licenserc.yaml @@ -33,6 +33,7 @@ header: - 'src/test/**/*.log' - '*/src/test/resources/META-INF/service/*' - '*/src/main/resources/META-INF/service/*' + - '*/src/main/resources/META-INF/spring/*' - '**/*/spring.factories' - '**/target/**' - '**/*.iml' From 34be0c018c96f94eb5ea5b9ea31db2afd6f74a8b Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sat, 24 Jun 2023 23:44:01 +0800 Subject: [PATCH 12/13] fix:Modify and supplement some defects in the testing module code --- .../springboot/consumer/ACLConsumer.java | 5 +-- .../src/main/resources/application.properties | 4 +-- .../{MyConsumer.java => FifoConsumer.java} | 8 ++--- .../springboot/consumer/TransConsumer.java | 34 +++++++++++++++++++ .../src/main/resources/application.properties | 16 +++++---- .../ClientProducerACLApplication.java | 2 +- .../src/main/resources/application.properties | 4 +-- .../springboot/ClientProducerApplication.java | 6 ++-- .../src/main/resources/application.properties | 2 +- .../annotation/RocketMQMessageListener.java | 2 +- .../rocketmq/client/support/RocketMQUtil.java | 3 +- 11 files changed, 62 insertions(+), 24 deletions(-) rename rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/{MyConsumer.java => FifoConsumer.java} (79%) create mode 100644 rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/TransConsumer.java diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java index f6d314f1..2e583b7b 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/ACLConsumer.java @@ -24,8 +24,9 @@ import org.springframework.stereotype.Service; @Service -@RocketMQMessageListener(accessKey = "${demo.acl.rocketmq.access-key:}", secretKey = "${demo.acl.rocketmq.secret-key:}", endpoints = "${demo.acl.rocketmq.endpoints:}", topic = "${demo.acl.rocketmq.topic:}", - consumerGroup = "${demo.acl.rocketmq.consumer-group:}", tag = "${demo.acl.rocketmq.tag:}") +@RocketMQMessageListener(accessKey = "${demo.acl.rocketmq.access-key:}", secretKey = "${demo.acl.rocketmq.secret-key:}", + tag = "${demo.acl.rocketmq.tag:}", topic = "${demo.acl.rocketmq.topic:}", + endpoints = "${demo.acl.rocketmq.endpoints:}", consumerGroup = "${demo.acl.rocketmq.consumer-group:}") public class ACLConsumer implements RocketMQListener { @Override public ConsumeResult consume(MessageView messageView) { diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties index cf7a0586..6aea301a 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-acl-demo/src/main/resources/application.properties @@ -1,7 +1,7 @@ demo.acl.rocketmq.endpoints=localhost:8081 demo.acl.rocketmq.topic=normalTopic demo.acl.rocketmq.consumer-group=normalGroup +demo.acl.rocketmq.access-key=RocketMQ +demo.acl.rocketmq.secret-key=12345678 demo.acl.rocketmq.tag=* -demo.acl.rocketmq.access-key=yourAccessKey -demo.acl.rocketmq.secret-key=yourSecretKey diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/FifoConsumer.java similarity index 79% rename from rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java rename to rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/FifoConsumer.java index ec72952a..ac33a726 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/MyConsumer.java +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/FifoConsumer.java @@ -23,13 +23,13 @@ import org.springframework.stereotype.Service; @Service -@RocketMQMessageListener(endpoints = "${demo.rocketmq.endpoints:}", topic = "${demo.rocketmq.topic:}", - consumerGroup = "${demo.rocketmq.consumer-group:}", tag = "${demo.rocketmq.tag:}") -public class MyConsumer implements RocketMQListener { +@RocketMQMessageListener(endpoints = "${demo.fifo.rocketmq.endpoints:}", topic = "${demo.fifo.rocketmq.topic:}", + consumerGroup = "${demo.fifo.rocketmq.consumer-group:}", tag = "${demo.fifo.rocketmq.tag:}") +public class FifoConsumer implements RocketMQListener { @Override public ConsumeResult consume(MessageView messageView) { - System.out.println("handle my message:" + messageView); + System.out.println("handle my fifo message:" + messageView); return ConsumeResult.SUCCESS; } } diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/TransConsumer.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/TransConsumer.java new file mode 100644 index 00000000..1ef973af --- /dev/null +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/consumer/TransConsumer.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.rocketmq.samples.springboot.consumer; + + +import org.apache.rocketmq.client.annotation.RocketMQMessageListener; +import org.apache.rocketmq.client.apis.consumer.ConsumeResult; +import org.apache.rocketmq.client.apis.message.MessageView; +import org.apache.rocketmq.client.core.RocketMQListener; +import org.springframework.stereotype.Service; + +@Service +@RocketMQMessageListener(endpoints = "${demo.trans.rocketmq.endpoints:}", topic = "${demo.trans.rocketmq.topic:}", + consumerGroup = "${demo.trans.rocketmq.consumer-group:}", tag = "${demo.trans.rocketmq.tag:}") +public class TransConsumer implements RocketMQListener { + public ConsumeResult consume(MessageView messageView) { + System.out.println("handle my transaction message:" + messageView); + return ConsumeResult.SUCCESS; + } +} diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties index c06c338a..39c6a0b1 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/resources/application.properties @@ -1,10 +1,14 @@ rocketmq.simple-consumer.endpoints=localhost:8081 -rocketmq.simple-consumer.consumer-group=transGroup -rocketmq.simple-consumer.topic=transTopic +rocketmq.simple-consumer.consumer-group=normalGroup +rocketmq.simple-consumer.topic=normalTopic rocketmq.simple-consumer.tag=* rocketmq.simple-consumer.filter-expression-type=tag -demo.rocketmq.endpoints=localhost:8081 -demo.rocketmq.topic=normalTopic -demo.rocketmq.consumer-group=normalGroup -demo.rocketmq.tag=* +demo.fifo.rocketmq.endpoints=localhost:8081 +demo.fifo.rocketmq.topic=fifoTopic +demo.fifo.rocketmq.consumer-group=fifoGroup +demo.fifo.rocketmq.tag=* +demo.trans.rocketmq.endpoints=localhost:8081 +demo.trans.rocketmq.topic=transTopic +demo.trans.rocketmq.consumer-group=transGroup +demo.trans.rocketmq.tag=* ext.rocketmq.topic=delayTopic diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java index 0d16dc28..66b4f2ca 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerACLApplication.java @@ -35,7 +35,7 @@ public class ClientProducerACLApplication implements CommandLineRunner { @Resource private RocketMQClientTemplate rocketMQClientTemplate; - @Value("${demo.acl.rocketmq.normal-topic}") + @Value("${rocketmq.producer.topic}") private String normalTopic; diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties index 72f893e2..962bc26e 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-acl-demo/src/main/resources/application.properties @@ -1,5 +1,5 @@ rocketmq.producer.endpoints=localhost:8081 rocketmq.producer.topic=normalTopic -rocketmq.producer.access-key=yourAccessKey -rocketmq.producer.secret-key=yourSecretKey +rocketmq.producer.access-key=RocketMQ +rocketmq.producer.secret-key=12345678 diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java index 1fc96d6b..f03df016 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientProducerApplication.java @@ -130,15 +130,15 @@ void testSendDelayMessage() { System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, MessageBuilder. - withPayload("test message".getBytes()).build(), Duration.ofSeconds(20)); + withPayload("test message".getBytes()).build(), Duration.ofSeconds(30)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "this is my message", - Duration.ofSeconds(30)); + Duration.ofSeconds(60)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "byte messages".getBytes(StandardCharsets.UTF_8), - Duration.ofSeconds(40)); + Duration.ofSeconds(90)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); } diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties index bcacd9e0..36fc218f 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-producer-demo/src/main/resources/application.properties @@ -1,5 +1,5 @@ rocketmq.producer.endpoints=localhost:8081 -rocketmq.producer.topic=transTopic +rocketmq.producer.topic=normalTopic demo.rocketmq.fifo-topic=fifoTopic demo.rocketmq.delay-topic=delayTopic demo.rocketmq.trans-topic=transTopic diff --git a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java index cadf4c93..89107aa1 100644 --- a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java +++ b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/annotation/RocketMQMessageListener.java @@ -66,7 +66,7 @@ /** * The load balancing group for the simple consumer. */ - String consumerGroup(); + String consumerGroup() default ""; /** * The requestTimeout of client,it is 3s by default. diff --git a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java index 89ec64ef..10d977aa 100644 --- a/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java +++ b/rocketmq-v5-client-spring-boot/src/main/java/org/apache/rocketmq/client/support/RocketMQUtil.java @@ -86,8 +86,7 @@ public static org.apache.rocketmq.client.apis.message.Message getAndWrapMessage( } messageBuilder.setBody(payloads); org.apache.rocketmq.client.apis.message.MessageBuilder builder = messageBuilder; - headers.entrySet().stream().forEach(entry -> builder.addProperty(entry.getKey(), String.valueOf(entry.getValue()))); - messageBuilder = builder; + headers.forEach((key, value) -> builder.addProperty(key, String.valueOf(value))); } return messageBuilder.build(); } From 75a9c3fc525c2940c1765eac6ffc55e4a2a44e81 Mon Sep 17 00:00:00 2001 From: RYE <1294566108@qq.com> Date: Sun, 25 Jun 2023 00:23:31 +0800 Subject: [PATCH 13/13] fix:Modify User Guide --- .../README-CN.md | 26 +++++++++---------- .../springboot/ClientConsumeApplication.java | 1 + 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/rocketmq-v5-client-spring-boot-samples/README-CN.md b/rocketmq-v5-client-spring-boot-samples/README-CN.md index 9933129a..59698fcf 100644 --- a/rocketmq-v5-client-spring-boot-samples/README-CN.md +++ b/rocketmq-v5-client-spring-boot-samples/README-CN.md @@ -203,15 +203,15 @@ public class ClientProducerApplication implements CommandLineRunner { System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, MessageBuilder. - withPayload("test message".getBytes()).build(), Duration.ofSeconds(20)); + withPayload("test message".getBytes()).build(), Duration.ofSeconds(30)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "this is my message", - Duration.ofSeconds(30)); + Duration.ofSeconds(60)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); sendReceipt = rocketMQClientTemplate.syncSendDelayMessage(delayTopic, "byte messages".getBytes(StandardCharsets.UTF_8), - Duration.ofSeconds(40)); + Duration.ofSeconds(90)); System.out.printf("delaySend to topic %s sendReceipt=%s %n", delayTopic, sendReceipt); } @@ -376,10 +376,10 @@ demo.rocketmq.message-group=group1 #### 修改application.properties ```class -demo.rocketmq.endpoints=localhost:8081 -demo.rocketmq.topic=normalTopic -demo.rocketmq.consumer-group=normalGroup -demo.rocketmq.tag=* +demo.fifo.rocketmq.endpoints=localhost:8081 +demo.fifo.rocketmq.topic=fifoTopic +demo.fifo.rocketmq.consumer-group=fifoGroup +demo.fifo.rocketmq.tag=* ``` > 注意: @@ -391,13 +391,13 @@ demo.rocketmq.tag=* ```java @Service -@RocketMQMessageListener(endpoints = "${demo.rocketmq.endpoints:}", topic = "${demo.rocketmq.topic:}", - consumerGroup = "${demo.rocketmq.consumer-group:}", tag = "${demo.rocketmq.tag:}") -public class MyConsumer implements RocketMQListener { +@RocketMQMessageListener(endpoints = "${demo.fifo.rocketmq.endpoints:}", topic = "${demo.fifo.rocketmq.topic:}", + consumerGroup = "${demo.fifo.rocketmq.consumer-group:}", tag = "${demo.fifo.rocketmq.tag:}") +public class FifoConsumer implements RocketMQListener { @Override public ConsumeResult consume(MessageView messageView) { - System.out.println("handle my message:" + messageView); + System.out.println("handle my fifo message:" + messageView); return ConsumeResult.SUCCESS; } } @@ -585,7 +585,7 @@ rocketmq.producer.secret-key=yourSecretKey ``` > 注意: -> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口,并修改AccessKey与SecretKey为真实数据 @@ -648,7 +648,7 @@ demo.acl.rocketmq.secret-key=yourSecretKey ``` > 注意: -> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口 +> 请将上述示例配置中的127.0.0.1:8081替换成真实RocketMQ的endpoints地址与端口,并修改AccessKey与SecretKey为真实数据 diff --git a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java index be101e06..8b2bd661 100644 --- a/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java +++ b/rocketmq-v5-client-spring-boot-samples/rocketmq-v5-client-consume-demo/src/main/java/org/apache/rocketmq/samples/springboot/ClientConsumeApplication.java @@ -54,6 +54,7 @@ public static void main(String[] args) { public void run(String... args) throws Exception { receiveSimpleConsumerMessage(); receiveExtSimpleConsumerMessage(); + //receiveSimpleConsumerMessageAsynchronously(); } public void receiveSimpleConsumerMessage() throws ClientException {