Skip to content

[ISSUE #396]support namespace #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 1, 2021
Merged
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/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.2.1-SNAPSHOT</version>
<version>2.2.2-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-consume-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.2.1-SNAPSHOT</version>
<version>2.2.2-SNAPSHOT</version>
</parent>

<artifactId>rocketmq-produce-demo</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@
* The name value of message trace topic.If you don't config,you can use the default trace topic name.
*/
String customizedTraceTopic() default TRACE_TOPIC_PLACEHOLDER;

/**
* The namespace of consumer.
*/
String namespace() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,8 @@
* The property of "tlsEnable" default false.
*/
String tlsEnable() default "false";
/**
* The namespace of producer.
*/
String namespace() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,4 +127,9 @@
* The property of "tlsEnable" default false.
*/
String tlsEnable() default "false";

/**
* The namespace of consumer.
*/
String namespace() default "";
}
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ private DefaultLitePullConsumer createConsumer(ExtRocketMQConsumerConfiguration
groupName, topicName, messageModel, selectorType, selectorExpression, ak, sk, pullBatchSize, useTLS);
litePullConsumer.setEnableMsgTrace(annotation.enableMsgTrace());
litePullConsumer.setCustomizedTraceTopic(resolvePlaceholders(annotation.customizedTraceTopic(), consumerConfig.getCustomizedTraceTopic()));
litePullConsumer.setNamespace(annotation.namespace());
return litePullConsumer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private DefaultMQProducer createProducer(ExtRocketMQTemplateConfiguration annota
producer.setCompressMsgBodyOverHowmuch(annotation.compressMessageBodyThreshold() == -1 ? producerConfig.getCompressMessageBodyThreshold() : annotation.compressMessageBodyThreshold());
producer.setRetryAnotherBrokerWhenNotStoreOK(annotation.retryNextServer());
producer.setUseTLS(useTLS);

producer.setNamespace(annotation.namespace());
return producer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public DefaultMQProducer defaultMQProducer(RocketMQProperties rocketMQProperties
producer.setCompressMsgBodyOverHowmuch(producerConfig.getCompressMessageBodyThreshold());
producer.setRetryAnotherBrokerWhenNotStoreOK(producerConfig.isRetryNextServer());
producer.setUseTLS(producerConfig.isTlsEnable());

producer.setNamespace(producerConfig.getNamespace());
return producer;
}

Expand Down Expand Up @@ -146,6 +146,7 @@ public DefaultLitePullConsumer defaultLitePullConsumer(RocketMQProperties rocket
groupName, topicName, messageModel, selectorType, selectorExpression, ak, sk, pullBatchSize, useTLS);
litePullConsumer.setEnableMsgTrace(consumerConfig.isEnableMsgTrace());
litePullConsumer.setCustomizedTraceTopic(consumerConfig.getCustomizedTraceTopic());
litePullConsumer.setNamespace(consumerConfig.getNamespace());
return litePullConsumer;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,11 @@ public static class Producer {
*/
private String group;

/**
* Namespace for this MQ Producer instance.
*/
private String namespace;

/**
* Millis of send message timeout.
*/
Expand Down Expand Up @@ -232,6 +237,14 @@ public boolean isTlsEnable() {
public void setTlsEnable(boolean tlsEnable) {
this.tlsEnable = tlsEnable;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}
}

public Consumer getConsumer() {
Expand All @@ -248,6 +261,11 @@ public static final class Consumer {
*/
private String group;

/**
* Namespace for this MQ Consumer instance.
*/
private String namespace;

/**
* Topic name of consumer.
*/
Expand Down Expand Up @@ -403,6 +421,14 @@ public boolean isTlsEnable() {
public void setTlsEnable(boolean tlsEnable) {
this.tlsEnable = tlsEnable;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ public class DefaultRocketMQListenerContainer implements InitializingBean,
private int maxReconsumeTimes;
private int replyTimeout;
private String tlsEnable;
private String namespace;

public long getSuspendCurrentQueueTimeMillis() {
return suspendCurrentQueueTimeMillis;
Expand Down Expand Up @@ -226,6 +227,7 @@ public void setRocketMQMessageListener(RocketMQMessageListener anno) {
this.maxReconsumeTimes = anno.maxReconsumeTimes();
this.replyTimeout = anno.replyTimeout();
this.tlsEnable = anno.tlsEnable();
this.namespace = anno.namespace();
}

public ConsumeMode getConsumeMode() {
Expand Down Expand Up @@ -256,6 +258,14 @@ public void setTlsEnable(String tlsEnable) {
this.tlsEnable = tlsEnable;
}

public String getNamespace() {
return namespace;
}

public void setNamespace(String namespace) {
this.namespace = namespace;
}

public DefaultMQPushConsumer getConsumer() {
return consumer;
}
Expand Down Expand Up @@ -344,13 +354,14 @@ public void setApplicationContext(ApplicationContext applicationContext) throws
public String toString() {
return "DefaultRocketMQListenerContainer{" +
"consumerGroup='" + consumerGroup + '\'' +
", namespace='" + namespace + '\'' +
", nameServer='" + nameServer + '\'' +
", topic='" + topic + '\'' +
", consumeMode=" + consumeMode +
", selectorType=" + selectorType +
", selectorExpression='" + selectorExpression + '\'' +
", messageModel=" + messageModel + '\'' +
", tlsEnable=" + tlsEnable +
", messageModel=" + messageModel + '\'' +
", tlsEnable=" + tlsEnable +
'}';
}

Expand Down Expand Up @@ -579,7 +590,7 @@ private void initRocketMQPushConsumer() throws MQClientException {
this.applicationContext.getEnvironment().
resolveRequiredPlaceholders(this.rocketMQMessageListener.customizedTraceTopic()));
}

consumer.setNamespace(namespace);
consumer.setInstanceName(RocketMQUtil.getInstanceName(nameServer));

String customizedNameServer = this.applicationContext.getEnvironment().resolveRequiredPlaceholders(this.rocketMQMessageListener.nameServer());
Expand Down