-
Notifications
You must be signed in to change notification settings - Fork 12k
[ISSUE #11089] Share consumption executors for Proxy internal clients #11090
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
lollipopjin
merged 8 commits into
apache:develop
from
qianye1001:codex/share-proxy-consume-executor
Sep 11, 2026
+578
−181
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a70b6cc
[ISSUE #11089] Share consumption executors for Proxy internal clients
qianye1001 a7637a4
[ISSUE #11089] Isolate Proxy discard handling and avoid monitor pinning
qianye1001 a5615f0
[ISSUE #11089] Use injected consumption executors directly
qianye1001 0353f4f
[ISSUE #11089] Extract shared consumption executor management
qianye1001 69ed7e0
[ISSUE #11089] Simplify discarded consumption failure handling
qianye1001 9aa51ab
[ISSUE #11089] Preserve queued system messages in shared executor
qianye1001 b3c92c9
[ISSUE #11089] Keep shared consumption core threads alive
qianye1001 23400f0
[ISSUE #11089] Clarify external consumption executor contract
qianye1001 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
81 changes: 81 additions & 0 deletions
81
...src/main/java/org/apache/rocketmq/client/impl/consumer/AbstractConsumeMessageService.java
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You 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 org.apache.rocketmq.client.impl.consumer; | ||
|
|
||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.LinkedBlockingQueue; | ||
| import java.util.concurrent.ThreadFactory; | ||
| import java.util.concurrent.ThreadPoolExecutor; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.rocketmq.client.consumer.DefaultMQPushConsumer; | ||
| import org.apache.rocketmq.common.utils.ThreadUtils; | ||
|
|
||
| public abstract class AbstractConsumeMessageService implements ConsumeMessageService { | ||
| protected final DefaultMQPushConsumer defaultMQPushConsumer; | ||
| protected final ExecutorService consumeExecutor; | ||
| private final boolean ownsConsumeExecutor; | ||
|
|
||
| protected AbstractConsumeMessageService(DefaultMQPushConsumer defaultMQPushConsumer, ThreadFactory threadFactory) { | ||
| this.defaultMQPushConsumer = defaultMQPushConsumer; | ||
| ExecutorService externalExecutor = defaultMQPushConsumer.getConsumeExecutor(); | ||
| this.ownsConsumeExecutor = externalExecutor == null; | ||
| if (this.ownsConsumeExecutor) { | ||
| this.consumeExecutor = new ThreadPoolExecutor( | ||
| defaultMQPushConsumer.getConsumeThreadMin(), | ||
| defaultMQPushConsumer.getConsumeThreadMax(), | ||
| 1000 * 60, | ||
| TimeUnit.MILLISECONDS, | ||
| new LinkedBlockingQueue<>(), | ||
| threadFactory); | ||
| } else { | ||
| this.consumeExecutor = externalExecutor; | ||
| } | ||
| } | ||
|
|
||
| protected static String getConsumerGroupTag(String consumerGroup) { | ||
| return (consumerGroup.length() > 100 ? consumerGroup.substring(0, 100) : consumerGroup) + "_"; | ||
| } | ||
|
|
||
| protected void shutdownConsumeExecutor(long awaitTerminateMillis) { | ||
| if (this.ownsConsumeExecutor) { | ||
| ThreadUtils.shutdownGracefully(this.consumeExecutor, awaitTerminateMillis, TimeUnit.MILLISECONDS); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void updateCorePoolSize(int corePoolSize) { | ||
| if (this.ownsConsumeExecutor | ||
| && corePoolSize > 0 | ||
| && corePoolSize <= Short.MAX_VALUE | ||
| && corePoolSize < this.defaultMQPushConsumer.getConsumeThreadMax()) { | ||
| ((ThreadPoolExecutor) this.consumeExecutor).setCorePoolSize(corePoolSize); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public void incCorePoolSize() { | ||
| } | ||
|
|
||
| @Override | ||
| public void decCorePoolSize() { | ||
| } | ||
|
|
||
| @Override | ||
| public int getCorePoolSize() { | ||
| return this.ownsConsumeExecutor ? ((ThreadPoolExecutor) this.consumeExecutor).getCorePoolSize() : -1; | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里感觉引入了不必要的抽象
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
不然要写 4 次,+ 100 行