rollback null group support, it makes some mistakes.

pull/2501/head
sorie 3 years ago
parent 244fbc978f
commit ac80858241

@ -18,6 +18,7 @@ spring:
processor-out-0: processor-out-0:
producer: producer:
group: output_2 group: output_2
bindings: bindings:
producer-out-0: producer-out-0:
destination: num destination: num
@ -28,6 +29,7 @@ spring:
group: processor_group group: processor_group
consumer-in-0: consumer-in-0:
destination: square destination: square
group: consumer_group
logging: logging:
level: level:

@ -16,9 +16,6 @@
package com.alibaba.cloud.stream.binder.rocketmq; package com.alibaba.cloud.stream.binder.rocketmq;
import java.util.UUID;
import com.alibaba.cloud.stream.binder.rocketmq.constant.RocketMQConst;
import com.alibaba.cloud.stream.binder.rocketmq.custom.RocketMQBeanContainerCache; import com.alibaba.cloud.stream.binder.rocketmq.custom.RocketMQBeanContainerCache;
import com.alibaba.cloud.stream.binder.rocketmq.extend.ErrorAcknowledgeHandler; import com.alibaba.cloud.stream.binder.rocketmq.extend.ErrorAcknowledgeHandler;
import com.alibaba.cloud.stream.binder.rocketmq.integration.inbound.RocketMQInboundChannelAdapter; import com.alibaba.cloud.stream.binder.rocketmq.integration.inbound.RocketMQInboundChannelAdapter;
@ -31,7 +28,6 @@ import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQExtendedBindi
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties; import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQProducerProperties;
import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner; import com.alibaba.cloud.stream.binder.rocketmq.provisioning.RocketMQTopicProvisioner;
import com.alibaba.cloud.stream.binder.rocketmq.utils.RocketMQUtils; import com.alibaba.cloud.stream.binder.rocketmq.utils.RocketMQUtils;
import org.apache.rocketmq.common.protocol.NamespaceUtil;
import org.springframework.cloud.stream.binder.AbstractMessageChannelBinder; import org.springframework.cloud.stream.binder.AbstractMessageChannelBinder;
import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider; import org.springframework.cloud.stream.binder.BinderSpecificPropertiesProvider;
@ -52,7 +48,6 @@ import org.springframework.messaging.MessageHandler;
import org.springframework.messaging.MessagingException; import org.springframework.messaging.MessagingException;
import org.springframework.util.StringUtils; import org.springframework.util.StringUtils;
/** /**
* A {@link org.springframework.cloud.stream.binder.Binder} that uses RocketMQ as the * A {@link org.springframework.cloud.stream.binder.Binder} that uses RocketMQ as the
* underlying middleware. * underlying middleware.
@ -118,17 +113,15 @@ public class RocketMQMessageChannelBinder extends
String group, String group,
ExtendedConsumerProperties<RocketMQConsumerProperties> extendedConsumerProperties) ExtendedConsumerProperties<RocketMQConsumerProperties> extendedConsumerProperties)
throws Exception { throws Exception {
boolean anonymous = !StringUtils.hasLength(group); /**
/*** * todo support anymous consumer
* When using DLQ, at least the group property must be provided for proper naming of the DLQ destination * but anymous consumer will create diff SubscriptionGroup
* According to https://docs.spring.io/spring-cloud-stream/docs/3.2.1/reference/html/spring-cloud-stream.html#spring-cloud-stream-reference * consumption progress will be recalculated.
*/ */
if (anonymous && NamespaceUtil.isDLQTopic(destination.getName())) { if (!StringUtils.hasLength(group)) {
throw new RuntimeException( throw new RuntimeException(
"group must be configured for DLQ" + destination.getName()); "'group must be configured for channel " + destination.getName());
} }
group = anonymous ? nextDefaultConsumerGroup() : group;
RocketMQUtils.mergeRocketMQProperties(binderConfigurationProperties, RocketMQUtils.mergeRocketMQProperties(binderConfigurationProperties,
extendedConsumerProperties.getExtension()); extendedConsumerProperties.getExtension());
extendedConsumerProperties.getExtension().setGroup(group); extendedConsumerProperties.getExtension().setGroup(group);
@ -184,14 +177,6 @@ public class RocketMQMessageChannelBinder extends
}; };
} }
/**
* generate next default consumer group.
* @return next default consumer group name.
*/
private static String nextDefaultConsumerGroup() {
return RocketMQConst.DEFAULT_GROUP + UUID.randomUUID().toString();
}
/** /**
* Binders can return an {@link ErrorMessageStrategy} for building error messages; * Binders can return an {@link ErrorMessageStrategy} for building error messages;
* binder implementations typically might add extra headers to the error message. * binder implementations typically might add extra headers to the error message.
@ -222,4 +207,5 @@ public class RocketMQMessageChannelBinder extends
public Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass() { public Class<? extends BinderSpecificPropertiesProvider> getExtendedPropertiesEntryClass() {
return this.extendedBindingProperties.getExtendedPropertiesEntryClass(); return this.extendedBindingProperties.getExtendedPropertiesEntryClass();
} }
} }

@ -31,7 +31,7 @@ public class RocketMQConst extends MessageConst {
/** /**
* Default group for SCS RocketMQ Binder. * Default group for SCS RocketMQ Binder.
*/ */
public static final String DEFAULT_GROUP = "anonymous"; public static final String DEFAULT_GROUP = "binder_default_group_name";
/** /**
* user args for SCS RocketMQ Binder. * user args for SCS RocketMQ Binder.

@ -1,90 +0,0 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* 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
*
* https://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 com.alibaba.cloud.stream.binder.rocketmq;
import javax.annotation.Resource;
import com.alibaba.cloud.stream.binder.rocketmq.autoconfigurate.ExtendedBindingHandlerMappingsProviderConfiguration;
import com.alibaba.cloud.stream.binder.rocketmq.autoconfigurate.RocketMQBinderAutoConfiguration;
import com.alibaba.cloud.stream.binder.rocketmq.properties.RocketMQConsumerProperties;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.ImportAutoConfiguration;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.cloud.stream.binder.ExtendedConsumerProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.core.MessageProducer;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.NONE;
@SpringBootTest(classes = RocketMQMessageChannelBinderTest.TestConfig.class,
webEnvironment = NONE,
properties = {
"spring.cloud.stream.rocketmq.binder.name-server=127.0.0.1:9876",
"spring.cloud.stream.bindings.output.destination=TopicOrderTest",
"spring.cloud.stream.bindings.output.content-type=application/json",
"spring.cloud.stream.bindings.input1.destination=TopicOrderTest",
"spring.cloud.stream.bindings.input1.content-type=application/json",
"spring.cloud.stream.bindings.input1.group=test-group1",
"spring.cloud.stream.rocketmq.bindings.input1.consumer.push.orderly=true",
"spring.cloud.stream.bindings.input1.consumer.maxAttempts=1",
"spring.cloud.stream.bindings.input2.destination=TopicOrderTest",
"spring.cloud.stream.bindings.input2.content-type=application/json",
"spring.cloud.stream.bindings.input2.group=test-group2",
"spring.cloud.stream.rocketmq.bindings.input2.consumer.push.orderly=false",
"spring.cloud.stream.rocketmq.bindings.input2.consumer.subscription=tag1"
})
public class RocketMQMessageChannelBinderTest {
@Resource
RocketMQMessageChannelBinder binder;
@Test
public void createConsumerEndpoint() throws Exception {
TestConsumerDestination destination = new TestConsumerDestination("test");
MessageProducer consumerEndpoint = binder.createConsumerEndpoint(destination, "test",
new ExtendedConsumerProperties<>(new RocketMQConsumerProperties()));
Assertions.assertNotNull(consumerEndpoint);
}
@Test
public void createAnymousConsumerEndpoint() throws Exception {
TestConsumerDestination destination = new TestConsumerDestination("test");
MessageProducer consumerEndpoint = binder.createConsumerEndpoint(destination, null,
new ExtendedConsumerProperties<>(new RocketMQConsumerProperties()));
Assertions.assertNotNull(consumerEndpoint);
}
@Test
public void createDLQAnymousConsumerEndpoint() throws Exception {
TestConsumerDestination destination = new TestConsumerDestination("%DLQ%test");
Assertions.assertThrows(RuntimeException.class, () -> {
MessageProducer consumerEndpoint = binder.createConsumerEndpoint(destination, null,
new ExtendedConsumerProperties<>(new RocketMQConsumerProperties()));
});
}
@Configuration
@EnableAutoConfiguration
@ImportAutoConfiguration({ ExtendedBindingHandlerMappingsProviderConfiguration.class,
RocketMQBinderAutoConfiguration.class})
public static class TestConfig {
}
}

@ -1,32 +0,0 @@
/*
* Copyright 2013-2022 the original author or authors.
*
* 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
*
* https://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 com.alibaba.cloud.stream.binder.rocketmq;
import org.springframework.cloud.stream.provisioning.ConsumerDestination;
public class TestConsumerDestination implements ConsumerDestination {
private String name;
public TestConsumerDestination(String name) {
this.name = name;
}
@Override
public String getName() {
return name;
}
}
Loading…
Cancel
Save