Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion rocketmq-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<packaging>pom</packaging>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>

<name>RocketMQ Spring Boot Samples</name>
<description>Samples for RocketMQ Spring Boot</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-consume-acl-demo</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion rocketmq-spring-boot-samples/rocketmq-consume-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-consume-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-consumer-pull-simple-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-consumer-push-simple-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-produce-acl-demo</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion rocketmq-spring-boot-samples/rocketmq-produce-demo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-produce-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-spring-boot-samples</artifactId>
<version>2.3.2-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-producer-simple-demo</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion rocketmq-v5-client-spring-boot-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<packaging>pom</packaging>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>

<name>rocketmq-v5-client-spring-boot-samples</name>
<description>rocketmq-v5-client-spring-boot-samples</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>
<artifactId>rocketmq-v5-client-consume-acl-demo</artifactId>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-consume-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-consume-simple-subscribe-muliti-topic-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-consumer-push-simple-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-consumer-simple-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-producer-acl-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-producer-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.apache.rocketmq</groupId>
<artifactId>rocketmq-v5-client-spring-boot-samples</artifactId>
<version>2.3.6-SNAPSHOT</version>
<version>2.3.7-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-v5-client-producer-simple-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ private void registerTemplate(String beanName, Object bean) {
ProducerBuilder producerBuilder = createProducer(annotation);
RocketMQClientTemplate rocketMQTemplate = (RocketMQClientTemplate) bean;
rocketMQTemplate.setProducerBuilder(producerBuilder);
rocketMQTemplate.initProducer();
rocketMQTemplate.setMessageConverter(rocketMQMessageConverter.getMessageConverter());
String topic = environment.resolvePlaceholders(annotation.topic());
log.info("Set real producer to {} using topic {}", beanName, topic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.DisposableBean;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessagingException;
import org.springframework.messaging.core.AbstractMessageSendingTemplate;
Expand All @@ -43,7 +44,7 @@


@SuppressWarnings({"WeakerAccess", "unused"})
public class RocketMQClientTemplate extends AbstractMessageSendingTemplate<String> implements DisposableBean {
public class RocketMQClientTemplate extends AbstractMessageSendingTemplate<String> implements DisposableBean, InitializingBean {

private static final Logger log = LoggerFactory.getLogger(RocketMQClientTemplate.class);

Expand All @@ -61,15 +62,8 @@ public class RocketMQClientTemplate extends AbstractMessageSendingTemplate<Strin

public Producer getProducer() {
if (Objects.isNull(producer)) {
synchronized (RocketMQClientTemplate.class) {
if (Objects.isNull(producer)) {
try {
this.producer = producerBuilder.build();
} catch (ClientException e) {
throw new RuntimeException(e);
}
}
}
throw new IllegalStateException(
"Producer is not initialized. Please check rocketmq.producer configuration.");
}
return producer;
}
Expand Down Expand Up @@ -106,6 +100,29 @@ public void setProducerBuilder(ProducerBuilder producerBuilder) {
this.producerBuilder = producerBuilder;
}

/**
* Build the producer during initialization so that connection/route prefetch
* happens at startup rather than on the first message send.
*/
public void initProducer() {
if (Objects.nonNull(producerBuilder) && Objects.isNull(producer)) {
synchronized (RocketMQClientTemplate.class) {
if (Objects.isNull(producer)) {
try {
this.producer = producerBuilder.build();
} catch (ClientException e) {
throw new RuntimeException(e);
}
}
}
}
}

@Override
public void afterPropertiesSet() throws Exception {
initProducer();
}

public SimpleConsumerBuilder getSimpleConsumerBuilder() {
return simpleConsumerBuilder;
}
Expand Down
Loading