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

重写ribbonrule,负载均衡获取的服务错误 #493

Open
hualan77 opened this issue Nov 7, 2021 · 1 comment
Open

重写ribbonrule,负载均衡获取的服务错误 #493

hualan77 opened this issue Nov 7, 2021 · 1 comment

Comments

@hualan77
Copy link

hualan77 commented Nov 7, 2021

自定义ribbon为RandomRule,
image
消费方是user,需要依次调用其他两个微服务instr 和infra, 第一次远程调用正常,第二次远程调用instr,负载到的服务却是infra,如下图
image
注意到掉用instr和infra的RandomRule是一个,想问下什么原因,如何处理?
pom依赖如下:

<properties>
        <spring.cloud-version>Hoxton.SR8</spring.cloud-version>
    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring.cloud-version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.10.1</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <version>2.3.2.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>com.google.code.gson</groupId>
            <artifactId>gson</artifactId>
            <version>2.6.2</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-openfeign</artifactId>
        </dependency>
    </dependencies>
@hualan77 hualan77 changed the title 重写ribbonrule,负载均衡获取的 重写ribbonrule,负载均衡获取的服务错误 Nov 7, 2021
@hualan77
Copy link
Author

spring默认扫描配置类为单例模式,配置为原生模式就可以解决问题。或者按照官网不要将其RibbonConfig放在spring扫描的包下,同时配置ribbon配置为自定义的ribbonConfig,那么会在远程调用时进行初始化,也能解决上面的问题。

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

No branches or pull requests

1 participant