-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
rocketmq message grayscale support 5.1.x
Signed-off-by: chengyouling <[email protected]>
- Loading branch information
1 parent
214a423
commit 0d86f2a
Showing
11 changed files
with
436 additions
and
51 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
.../grayscale/rocketmq/declarer/client51/RocketMqV51LitePullConsumerConstructorDeclarer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 io.sermant.mq.grayscale.rocketmq.declarer.client51; | ||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import io.sermant.mq.grayscale.rocketmq.interceptor.client51.RocketMqV51ConsumerConstructorInterceptor; | ||
|
||
/** | ||
* 5.1.x client lite pull consumer set gray consumer group declarer | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-07 | ||
**/ | ||
public class RocketMqV51LitePullConsumerConstructorDeclarer extends AbstractPluginDeclarer { | ||
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.DefaultLitePullConsumer"; | ||
|
||
private static final String[] METHOD_PARAM_TYPES = { | ||
"java.lang.String", | ||
"org.apache.rocketmq.remoting.RPCHook" | ||
}; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.isConstructor() | ||
.and(MethodMatcher.paramTypesEqual(METHOD_PARAM_TYPES)), | ||
new RocketMqV51ConsumerConstructorInterceptor()) | ||
}; | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...t/mq/grayscale/rocketmq/declarer/client51/RocketMqV51PullConsumerConstructorDeclarer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 io.sermant.mq.grayscale.rocketmq.declarer.client51; | ||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import io.sermant.mq.grayscale.rocketmq.interceptor.client51.RocketMqV51ConsumerConstructorInterceptor; | ||
|
||
/** | ||
* 5.1.x client pull consumer set gray consumer group declarer | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-07 | ||
**/ | ||
public class RocketMqV51PullConsumerConstructorDeclarer extends AbstractPluginDeclarer { | ||
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.DefaultMQPullConsumer"; | ||
|
||
private static final String[] METHOD_PARAM_TYPES = { | ||
"java.lang.String", | ||
"org.apache.rocketmq.remoting.RPCHook" | ||
}; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.isConstructor() | ||
.and(MethodMatcher.paramTypesEqual(METHOD_PARAM_TYPES)), | ||
new RocketMqV51ConsumerConstructorInterceptor()) | ||
}; | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
...t/mq/grayscale/rocketmq/declarer/client51/RocketMqV51PushConsumerConstructorDeclarer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 io.sermant.mq.grayscale.rocketmq.declarer.client51; | ||
|
||
import io.sermant.core.plugin.agent.declarer.AbstractPluginDeclarer; | ||
import io.sermant.core.plugin.agent.declarer.InterceptDeclarer; | ||
import io.sermant.core.plugin.agent.matcher.ClassMatcher; | ||
import io.sermant.core.plugin.agent.matcher.MethodMatcher; | ||
import io.sermant.mq.grayscale.rocketmq.interceptor.client51.RocketMqV51ConsumerConstructorInterceptor; | ||
|
||
/** | ||
* 5.1.x client push consumer set gray consumer group declarer | ||
* | ||
* @author chengyouling | ||
* @since 2024-09-07 | ||
**/ | ||
public class RocketMqV51PushConsumerConstructorDeclarer extends AbstractPluginDeclarer { | ||
private static final String ENHANCE_CLASS = "org.apache.rocketmq.client.consumer.DefaultMQPushConsumer"; | ||
|
||
private static final String PARAMETER_STRING = "java.lang.String"; | ||
|
||
private static final String PARAMETER_HOOK = "org.apache.rocketmq.remoting.RPCHook"; | ||
|
||
private static final String PARAMETER_STRATEGY = "org.apache.rocketmq.client.consumer.AllocateMessageQueueStrategy"; | ||
|
||
private static final String[] METHOD_PARAM_TYPES = { | ||
PARAMETER_STRING, | ||
PARAMETER_HOOK, | ||
PARAMETER_STRATEGY, | ||
"boolean", | ||
PARAMETER_STRING | ||
}; | ||
|
||
@Override | ||
public ClassMatcher getClassMatcher() { | ||
return ClassMatcher.nameEquals(ENHANCE_CLASS); | ||
} | ||
|
||
@Override | ||
public InterceptDeclarer[] getInterceptDeclarers(ClassLoader classLoader) { | ||
return new InterceptDeclarer[]{ | ||
InterceptDeclarer.build(MethodMatcher.isConstructor() | ||
.and(MethodMatcher.paramTypesEqual(METHOD_PARAM_TYPES)), | ||
new RocketMqV51ConsumerConstructorInterceptor()) | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...mq/grayscale/rocketmq/interceptor/client51/RocketMqV51ConsumerConstructorInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Copyright (C) 2024-2024 Sermant Authors. All rights reserved. | ||
* | ||
* 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 | ||
* | ||
* http://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 io.sermant.mq.grayscale.rocketmq.interceptor.client51; | ||
|
||
import io.sermant.core.plugin.agent.entity.ExecuteContext; | ||
import io.sermant.core.plugin.agent.interceptor.AbstractInterceptor; | ||
import io.sermant.core.utils.StringUtils; | ||
import io.sermant.mq.grayscale.config.MqGrayConfigCache; | ||
import io.sermant.mq.grayscale.rocketmq.utils.RocketMqGrayscaleConfigUtils; | ||
|
||
/** | ||
* upper 5.1.x DefaultMQPushConsumer/DefaultLitePullConsumer/DefaultMQPullConsumer Constructor method interceptor | ||
* gray scene reset consumerGroup with grayGroupTag | ||
* | ||
* @author chengyouling | ||
* @since 2024-05-27 | ||
**/ | ||
public class RocketMqV51ConsumerConstructorInterceptor extends AbstractInterceptor { | ||
@Override | ||
public ExecuteContext before(ExecuteContext context) throws Exception { | ||
if (!MqGrayConfigCache.getCacheConfig().isEnabled()) { | ||
return context; | ||
} | ||
String grayGroupTag = RocketMqGrayscaleConfigUtils.getGrayGroupTag(); | ||
if (StringUtils.isEmpty(grayGroupTag)) { | ||
return context; | ||
} | ||
String originGroup = (String) context.getArguments()[0]; | ||
context.getArguments()[0] | ||
= originGroup.contains("_" + grayGroupTag) ? originGroup : originGroup + "_" + grayGroupTag; | ||
return context; | ||
} | ||
|
||
@Override | ||
public ExecuteContext after(ExecuteContext context) throws Exception { | ||
return context; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.