Skip to content

Commit

Permalink
[ISSUE #612] Support Springboot 3.X
Browse files Browse the repository at this point in the history
1. Replace `@PostConstruct` with constructor
2. log format style
3. Springboot 3.x autoconfigure
  • Loading branch information
pangxiao1 committed Jan 12, 2024
1 parent bc96d49 commit 7354c24
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.AutoConfigureBefore;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
Expand All @@ -48,8 +47,6 @@
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;

import javax.annotation.PostConstruct;

@Configuration
@EnableConfigurationProperties(RocketMQProperties.class)
@ConditionalOnClass({MQAdmin.class})
Expand All @@ -66,17 +63,20 @@ public class RocketMQAutoConfiguration implements ApplicationContextAware {
public static final String PRODUCER_BEAN_NAME = "defaultMQProducer";
public static final String CONSUMER_BEAN_NAME = "defaultLitePullConsumer";

@Autowired
private Environment environment;
private final Environment environment;

private ApplicationContext applicationContext;

public RocketMQAutoConfiguration(Environment environment) {
this.environment = environment;
checkProperties();
}

@Override
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
this.applicationContext = applicationContext;
}

@PostConstruct
public void checkProperties() {
String nameServer = environment.getProperty("rocketmq.name-server", String.class);
log.debug("rocketmq.nameServer = {}", nameServer);
Expand Down Expand Up @@ -117,7 +117,7 @@ public DefaultMQProducer defaultMQProducer(RocketMQProperties rocketMQProperties
producer.setUseTLS(producerConfig.isTlsEnable());
producer.setNamespace(producerConfig.getNamespace());
producer.setInstanceName(producerConfig.getInstanceName());
log.info(String.format("a producer (%s) init on namesrv %s", groupName,nameServer));
log.info("a producer ({}) init on namesrv {}", groupName, nameServer);
return producer;
}

Expand Down Expand Up @@ -149,7 +149,7 @@ public DefaultLitePullConsumer defaultLitePullConsumer(RocketMQProperties rocket
litePullConsumer.setCustomizedTraceTopic(consumerConfig.getCustomizedTraceTopic());
litePullConsumer.setNamespace(consumerConfig.getNamespace());
litePullConsumer.setInstanceName(consumerConfig.getInstanceName());
log.info(String.format("a pull consumer(%s sub %s) init on namesrv %s", groupName, topicName,nameServer));
log.info("a pull consumer({} sub {}) init on namesrv {}", groupName, topicName, nameServer);
return litePullConsumer;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.apache.rocketmq.client.autoconfigure.RocketMQAutoConfiguration

0 comments on commit 7354c24

Please sign in to comment.