Skip to content
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

[Enhancement] ConsumeMessageConcurrentlyService#submitConsumeRequest code should be more concise #8070

Open
1 task done
biningo opened this issue Apr 26, 2024 · 0 comments · May be fixed by #8071
Open
1 task done

Comments

@biningo
Copy link

biningo commented Apr 26, 2024

Before Creating the Enhancement Request

  • I have confirmed that this should be classified as an enhancement rather than a bug/feature.

Summary

ConsumeMessageConcurrentlyService#submitConsumeRequest code should be more concise.

  1. Because the consumeExecutor uses a LinkedBlockingQueue, so as with ConsumeMessageConcurrentlyService#submitConsumeRequestLater , exception catching is unnecessary.
  2. The code for submitting messages to the consumer in batches should be more concise.
    public void submitConsumeRequest(
    final List<MessageExt> msgs,
    final ProcessQueue processQueue,
    final MessageQueue messageQueue,
    final boolean dispatchToConsume) {
    final int consumeBatchSize = this.defaultMQPushConsumer.getConsumeMessageBatchMaxSize();
    if (msgs.size() <= consumeBatchSize) {
    ConsumeRequest consumeRequest = new ConsumeRequest(msgs, processQueue, messageQueue);
    try {
    this.consumeExecutor.submit(consumeRequest);
    } catch (RejectedExecutionException e) {
    this.submitConsumeRequestLater(consumeRequest);
    }
    } else {
    for (int total = 0; total < msgs.size(); ) {
    List<MessageExt> msgThis = new ArrayList<>(consumeBatchSize);
    for (int i = 0; i < consumeBatchSize; i++, total++) {
    if (total < msgs.size()) {
    msgThis.add(msgs.get(total));
    } else {
    break;
    }
    }
    ConsumeRequest consumeRequest = new ConsumeRequest(msgThis, processQueue, messageQueue);
    try {
    this.consumeExecutor.submit(consumeRequest);
    } catch (RejectedExecutionException e) {
    for (; total < msgs.size(); total++) {
    msgThis.add(msgs.get(total));
    }
    this.submitConsumeRequestLater(consumeRequest);
    }
    }
    }
    }

    private void submitConsumeRequestLater(final ConsumeRequest consumeRequest
    ) {
    this.scheduledExecutorService.schedule(new Runnable() {
    @Override
    public void run() {
    ConsumeMessageConcurrentlyService.this.consumeExecutor.submit(consumeRequest);
    }
    }, 5000, TimeUnit.MILLISECONDS);
    }

Motivation

.

Describe the Solution You'd Like

I will optimise the submitConsumeRequest and remove unnecessary exception catching.

Describe Alternatives You've Considered

.

Additional Context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant