Skip to content

Moved the producer initialization to an earlier stage; it is no longe… - #783

Open
panzhi33 wants to merge 1 commit into
apache:masterfrom
panzhi33:master
Open

panzhi33 wants to merge 1 commit into
apache:masterfrom
panzhi33:master

Conversation

@panzhi33

Copy link
Copy Markdown
Contributor

…r initialized at the time of sending a message.

What is the purpose of the change

XXXXX

Brief changelog

XX

Verifying this change

XXXX

Follow this checklist to help us incorporate your contribution quickly and easily. Notice, it would be helpful if you could finish the following 5 checklist(the last one is not necessary)before request the community to review your PR.

  • Make sure there is a Github issue filed for the change (usually before you start working on it). Trivial changes like typos do not require a Github issue. Your pull request should address just this issue, without pulling in other changes - one PR resolves one issue.
  • Format the pull request title like [ISSUE #123] Fix UnknownException when host config not exist. Each commit in the pull request should have a meaningful subject line and body.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit-test(over 80% coverage) to verify your logic correction, more mock a little better when cross module dependency exist.
  • Run mvn -B clean apache-rat:check findbugs:findbugs checkstyle:checkstyle to make sure basic checks pass. Run mvn clean install -DskipITs to make sure unit-test pass. Run mvn clean test-compile failsafe:integration-test to make sure integration-test pass.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

…r initialized at the time of sending a message.

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Reviewed PR #783. Changes look reasonable overall.

Notes

\n- [Info] Synchronized blocks added — ensure lock ordering is consistent to avoid deadlocks


Automated review by github-manager-bot

@RockteMQ-AI RockteMQ-AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

This PR moves producer initialization from lazy (on first send) to eager (at Spring context startup via InitializingBean). This is a meaningful behavioral change with trade-offs worth discussing.

Findings

  • [Warning] RocketMQClientTemplate.java — The initProducer() method is now called during afterPropertiesSet(), meaning the producer is built at Spring startup. If the broker is unreachable at startup, the application will fail to start. Previously, lazy init would defer this failure to first send. Consider whether this is acceptable for all deployment scenarios (e.g., blue-green deployments where broker may not be ready when app container starts).

  • [Info] RocketMQClientTemplate.java — The getProducer() now throws IllegalStateException if producer is null, replacing the previous silent lazy-init fallback. This is a good improvement for fail-fast behavior, but the error message could be more descriptive — consider adding context like "Producer not initialized; ensure initProducer() completed successfully".

  • [Info] ExtTemplateResetConfiguration.java — Calling rocketMQTemplate.initProducer() after setting the producer builder is correct, but consider adding a guard to prevent double initialization if initProducer() is called multiple times (e.g., via reset + Spring lifecycle overlap).

  • [Info] Sample version bumps (2.3.2/2.3.6 → 2.3.7-SNAPSHOT) are mixed in with the core change. Consider separating version bumps into a dedicated commit for cleaner history.

Suggestions

// In initProducer(), add a guard:
public void initProducer() {
    synchronized (RocketMQClientTemplate.class) {
        if (this.producer != null) {
            log.debug("Producer already initialized, skipping re-initialization");
            return;
        }
        // ... existing init logic
    }
}

Automated review by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants