Skip to content

The clientIP attribute of ClientConfig supports setting through Syste… #9262

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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

WhyStart
Copy link

@WhyStart WhyStart commented Mar 19, 2025

…mProperty.

Which Issue(s) This PR Fixes

ref #3294

Brief Description

In a springboot+rocketmq project, starting up and loading topics on Windows is very slow, especially on computers that have virtual machines installed, with an average of 4 seconds to load each topic. After learning from some materials that this is due to network adapter issues, I think we can pass the clientIP through System.property. If it's not passed that way, then we can obtain the LocalIP through NetworkUtil.getLocalAddress(). By manually passing the clientIP, we can avoid the lengthy time consumption of calling NetworkUtil.getLocalAddress() for each topic.

    public ClientConfig() {
        String ip = System.getProperty("rocketmq.client.ip");
        if (ip != null && !ip.trim().isEmpty()) {
            clientIP = ip;
        } else {
            clientIP = NetworkUtil.getLocalAddress();
        }
    }

How Did You Test This Change?

    @Test
    public void testClientIpOverrideWithSystemProperty() {
        String ip = "192.168.8.8";
        System.setProperty("rocketmq.client.ip", ip);
        ClientConfig clientConfig = new ClientConfig();
        assertEquals(ip, clientConfig.getClientIP());
        System.clearProperty("rocketmq.client.ip");
        clientConfig = new ClientConfig();
        assertEquals(NetworkUtil.getLocalAddress(), clientConfig.getClientIP());
    }

@WhyStart
Copy link
Author

@lollipopjin could you assist with reviewing this PR?

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.

1 participant