mirror of
https://gitee.com/mirrors/Spring-Cloud-Alibaba.git
synced 2021-06-26 13:25:11 +08:00
fix spring-cloud-starter-bus-rocketmq in 1.x
This commit is contained in:
parent
a59011fa93
commit
eb72043b9f
@ -16,19 +16,20 @@
|
||||
*/
|
||||
package org.springframework.cloud.bus.rocketmq.env;
|
||||
|
||||
import static org.springframework.cloud.bus.SpringCloudBusClient.INPUT;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.env.EnvironmentPostProcessor;
|
||||
import org.springframework.cloud.bus.BusEnvironmentPostProcessor;
|
||||
import org.springframework.cloud.bus.SpringCloudBusClient;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.env.ConfigurableEnvironment;
|
||||
import org.springframework.core.env.MapPropertySource;
|
||||
import org.springframework.core.env.MutablePropertySources;
|
||||
import org.springframework.core.env.PropertySource;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* The lowest precedence {@link EnvironmentPostProcessor} configures default RocketMQ Bus
|
||||
* Properties that will be appended into {@link SpringApplication#defaultProperties}
|
||||
@ -64,9 +65,16 @@ public class RocketMQBusEnvironmentPostProcessor
|
||||
|
||||
private void configureDefaultProperties(Map<String, Object> source) {
|
||||
// Required Properties
|
||||
String groupBindingPropertyName = createBindingPropertyName(
|
||||
SpringCloudBusClient.INPUT, "group");
|
||||
String groupBindingPropertyName = createBindingPropertyName(INPUT, "group");
|
||||
String broadcastingPropertyName = createRocketMQPropertyName(INPUT,
|
||||
"broadcasting");
|
||||
source.put(groupBindingPropertyName, "rocketmq-bus-group");
|
||||
source.put(broadcastingPropertyName, "true");
|
||||
}
|
||||
|
||||
private String createRocketMQPropertyName(String channel, String propertyName) {
|
||||
return "spring.cloud.stream.rocketmq.bindings." + INPUT + ".consumer."
|
||||
+ propertyName;
|
||||
}
|
||||
|
||||
private String createBindingPropertyName(String channel, String propertyName) {
|
||||
|
@ -82,6 +82,12 @@ public class RocketMQMessageChannelBinder extends
|
||||
MessageChannel errorChannel) throws Exception {
|
||||
if (producerProperties.getExtension().getEnabled()) {
|
||||
|
||||
// if producerGroup is empty, using destination
|
||||
String extendedProducerGroup = producerProperties.getExtension().getGroup();
|
||||
String producerGroup = StringUtils.isEmpty(extendedProducerGroup)
|
||||
? destination.getName()
|
||||
: extendedProducerGroup;
|
||||
|
||||
RocketMQBinderConfigurationProperties mergedProperties = RocketMQBinderUtils
|
||||
.mergeProperties(rocketBinderConfigurationProperties,
|
||||
rocketMQProperties);
|
||||
@ -110,8 +116,7 @@ public class RocketMQMessageChannelBinder extends
|
||||
if (!StringUtils.isEmpty(ak) && !StringUtils.isEmpty(sk)) {
|
||||
RPCHook rpcHook = new AclClientRPCHook(
|
||||
new SessionCredentials(ak, sk));
|
||||
producer = new DefaultMQProducer(
|
||||
producerProperties.getExtension().getGroup(), rpcHook,
|
||||
producer = new DefaultMQProducer(producerGroup, rpcHook,
|
||||
mergedProperties.isEnableMsgTrace(),
|
||||
mergedProperties.getCustomizedTraceTopic());
|
||||
producer.setVipChannelEnabled(false);
|
||||
@ -119,8 +124,7 @@ public class RocketMQMessageChannelBinder extends
|
||||
RocketMQUtil.getInstanceName(rpcHook, destination.getName()));
|
||||
}
|
||||
else {
|
||||
producer = new DefaultMQProducer(
|
||||
producerProperties.getExtension().getGroup());
|
||||
producer = new DefaultMQProducer(producerGroup);
|
||||
producer.setVipChannelEnabled(
|
||||
producerProperties.getExtension().getVipChannelEnabled());
|
||||
}
|
||||
@ -141,8 +145,7 @@ public class RocketMQMessageChannelBinder extends
|
||||
}
|
||||
|
||||
RocketMQMessageHandler messageHandler = new RocketMQMessageHandler(
|
||||
rocketMQTemplate, destination.getName(),
|
||||
producerProperties.getExtension().getGroup(),
|
||||
rocketMQTemplate, destination.getName(), producerGroup,
|
||||
producerProperties.getExtension().getTransactional(),
|
||||
instrumentationManager);
|
||||
messageHandler.setBeanFactory(this.getApplicationContext().getBeanFactory());
|
||||
|
Loading…
x
Reference in New Issue
Block a user