国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

Dubbo hystrix 熔斷降級 示例

這篇具有很好參考價值的文章主要介紹了Dubbo hystrix 熔斷降級 示例。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

目錄

Pom

應(yīng)用啟動類

接口

服務(wù)提供者

消費者

總結(jié)

因為jar包沖突問題報錯?java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.([Ljava/lang/Object;)V

解決方式修改低版本springboot

改成如下

版本對照

全代碼

pom

啟動

實現(xiàn)

yml






Pom

 <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-hystrix</artifactId>
            <version>1.4.4.RELEASE</version>
        </dependency>

應(yīng)用啟動類

@SpringBootApplication
@EnableHystrix
public class ProviderApplication {

有需要加上這個

@EnableDubbo(scanBasePackages = {"org.apache.dubbo.spring.boot.provider.impl"})

接口

package org.apache.dubbo.spring.boot.api;

public interface HelloService {

    String sayHello(String name);

}

服務(wù)提供者

@Service(version = "1.0.0")
public class HelloServiceImpl implements HelloService {

    @HystrixCommand(commandProperties = {
                    @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
                    @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000") })
    @Override
    public String sayHello(String name) {
        // System.out.println("async provider received: " + name);
        // return "annotation: hello, " + name;
        throw new RuntimeException("Exception to show hystrix enabled.");
    }
}

消費者

有超時熔斷跳轉(zhuǎn)到 reliable 方法

   @Reference(version = "1.0.0")
private HelloService demoService;


    @HystrixCommand(fallbackMethod = "reliable")
    public String doSayHello(String name) {
        return demoService.sayHello(name);
}


    public String reliable(String name) {
        return "hystrix fallback value";
    }

總結(jié)

  • 對于dubbo provider的@Service是一個spring bean,直接在上面配置@HystrixCommand即可
  • 對于dubbo consumer的@Reference,可以通過加一層簡單的spring method包裝,配置@HystrixCommand即可
  • Hystrix本身提供HystrixCommandAspect來集成Spring AOP,配置了@HystrixCommand@HystrixCollapser的spring method都會被Hystrix處理

ok

持續(xù)更新文章來源地址http://www.zghlxwxcb.cn/news/detail-520977.html

因為jar包沖突問題報錯?java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

16:46:41.593 [main] DEBUG org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - Application failed to start due to an exception
java.lang.NoSuchMethodError: org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:102)
	at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:68)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:176)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:169)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:143)
	at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:131)
	at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:85)
	at org.springframework.boot.SpringApplicationRunListeners.lambda$environmentPrepared$2(SpringApplicationRunListeners.java:66)
	at java.util.ArrayList.forEach(ArrayList.java:1249)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:120)
	at org.springframework.boot.SpringApplicationRunListeners.doWithListeners(SpringApplicationRunListeners.java:114)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:65)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:343)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:301)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1303)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1292)
	at com.example.demo.DemoApplication.main(DemoApplication.java:15)
16:46:41.599 [main] ERROR org.springframework.boot.diagnostics.LoggingFailureAnalysisReporter - 

***************************
APPLICATION FAILED TO START
***************************

Description:

An attempt was made to call a method that does not exist. The attempt was made from the following location:

    org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:161)

The following method did not exist:

    org.springframework.boot.builder.SpringApplicationBuilder.<init>([Ljava/lang/Object;)V

The calling method's class, org.springframework.cloud.bootstrap.BootstrapApplicationListener, was loaded from the following location:

    jar:file:/C:/Users/ext.jianghaoyu1/.m2/repository/org/springframework/cloud/spring-cloud-context/1.3.6.RELEASE/spring-cloud-context-1.3.6.RELEASE.jar!/org/springframework/cloud/bootstrap/BootstrapApplicationListener.class

The called method's class, org.springframework.boot.builder.SpringApplicationBuilder, is available from the following locations:

    jar:file:/C:/Users/ext.jianghaoyu1/.m2/repository/org/springframework/boot/spring-boot/2.7.10/spring-boot-2.7.10.jar!/org/springframework/boot/builder/SpringApplicationBuilder.class

The called method's class hierarchy was loaded from the following locations:

    org.springframework.boot.builder.SpringApplicationBuilder: file:/C:/Users/ext.jianghaoyu1/.m2/repository/org/springframework/boot/spring-boot/2.7.10/spring-boot-2.7.10.jar


Action:

Correct the classpath of your application so that it contains compatible versions of the classes org.springframework.cloud.bootstrap.BootstrapApplicationListener and org.springframework.boot.builder.SpringApplicationBuilder


進程已結(jié)束,退出代碼1

解決方式修改低版本springboot

<parent>
? ? <groupId>org.springframework.boot</groupId>
? ? <artifactId>spring-boot-starter-parent</artifactId>
? ? <version>2.0.0.RELEASE</version>
? ? <relativePath/> <!-- lookup parent from repository -->
</parent>

改成如下

<parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <version>1.5.3.RELEASE</version>
       <relativePath/> <!-- lookup parent from repository -->
</parent>

版本對照

Dubbo hystrix 熔斷降級 示例,java,spring boot,dubbo prometheus grafana,dubbo,hystrix,java

ok

持續(xù)更新

全代碼

pom

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.example</groupId>
    <artifactId>demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>demo-p</name>
    <description>Demo project for Apache Dubbo</description>

    <properties>
        <java.version>1.8</java.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <dubbo.version>3.1.8</dubbo.version>
        <spring-boot.version>1.5.3.RELEASE</spring-boot.version>
        <hystrix-starter.version>1.4.7.RELEASE</hystrix-starter.version>

    </properties>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-dependencies</artifactId>
                <version>${spring-boot.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-bom</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
            <dependency>
                <groupId>org.apache.dubbo</groupId>
                <artifactId>dubbo-dependencies-zookeeper</artifactId>
                <version>${dubbo.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

    <dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter</artifactId>

        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-dependencies-zookeeper</artifactId>
            <type>pom</type>
        </dependency>
        <dependency>
            <groupId>org.apache.dubbo</groupId>
            <artifactId>dubbo-spring-boot-starter</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-hystrix</artifactId>
            <version>${hystrix-starter.version}</version>
        </dependency>


    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.8.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                    <encoding>UTF-8</encoding>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <version>${spring-boot.version}</version>
            </plugin>
        </plugins>
    </build>

</project>

啟動

package com.example.demo;


import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;

@SpringBootApplication
@EnableDubbo
@EnableHystrix
public class DemoApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoApplication.class, args);
    }

}

實現(xiàn)

package com.example.demo.dubbo.service;

import com.example.demo.dubbo.api.DemoService;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.apache.dubbo.config.annotation.DubboService;

@DubboService
public class DemoServiceImpl implements DemoService {

    @HystrixCommand(commandProperties = {
            @HystrixProperty(name = "circuitBreaker.requestVolumeThreshold", value = "10"),
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds", value = "2000")
    })
    @Override
    public String sayHello(String name) {
        return "Hello " + name;
    }
}

yml

server:
  port: 8101
dubbo:
  application:
    name: dubbo-springBoot-demo-provider
  protocol:
    name: dubbo
    port: -1
  registry:
    address: zookeeper://localhost:2181




  management:
    endpoints:
      web:
        exposure:
          include: "*"
    metrics:
      tags:
        application: ${spring.application.name}





ok

持續(xù)更新

到了這里,關(guān)于Dubbo hystrix 熔斷降級 示例的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • SpringCloud(四)Hystrix服務(wù)降級、熔斷、監(jiān)控頁面

    SpringCloud(四)Hystrix服務(wù)降級、熔斷、監(jiān)控頁面

    官方文檔:https://cloud.spring.io/spring-cloud-static/spring-cloud-netflix/1.3.5.RELEASE/single/spring-cloud-netflix.html#_circuit_breaker_hystrix_clients 我們知道,微服務(wù)之間是可以進行相互調(diào)用的,那么如果出現(xiàn)了下面的情況會導(dǎo)致什么問題? 由于位于最底端的服務(wù)提供者E發(fā)生故障,那么此時會直接導(dǎo)

    2024年02月17日
    瀏覽(26)
  • Hystrix入門使用 服務(wù)熔斷 服務(wù)降級 服務(wù)雪崩

    Hystrix入門使用 服務(wù)熔斷 服務(wù)降級 服務(wù)雪崩

    hystrix停止更新,理念優(yōu)秀。 分布式系統(tǒng)面臨的問題: 對于復(fù)雜的分布式體系,有數(shù)十個依賴,依賴不可避免的錯誤。 服務(wù)會出現(xiàn)雪崩, 高可用受到破壞 。 Hystrix就是用于解決分布式系統(tǒng)延遲和容錯的開源庫。 保證在一個依賴出現(xiàn)問題,不會導(dǎo)致整體的服務(wù)失敗,避免級聯(lián)故

    2024年02月07日
    瀏覽(31)
  • 微服務(wù):Springboot集成Hystrix實現(xiàn)熔斷、降級、隔離

    微服務(wù):Springboot集成Hystrix實現(xiàn)熔斷、降級、隔離

    在分布式微服務(wù)的項目中,常常會有多個服務(wù)復(fù)用,產(chǎn)生多個服務(wù)調(diào)用的情況。比如A服務(wù)調(diào)用B服務(wù),B服務(wù)調(diào)用C服務(wù)。服務(wù)調(diào)用鏈路長了必然會增加服務(wù)超時的概率,服務(wù)的超時阻塞會一直占用線程資源,大量的阻塞會直接消耗完服務(wù)線程,嚴(yán)重情況下會導(dǎo)致服務(wù)直接宕機從

    2024年02月12日
    瀏覽(19)
  • SpringCloud-Hystrix服務(wù)熔斷與降級工作原理&源碼

    在微服務(wù)架構(gòu)中,根據(jù)業(yè)務(wù)來拆分成一個個的服務(wù),服務(wù)與服務(wù)之間可以相互調(diào)用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign來調(diào)用。為了保證其高可用,單個服務(wù)通常會集群部署。由于網(wǎng)絡(luò)原因或者自身的原因,服務(wù)并不能保證100%可用,如果單個服務(wù)出現(xiàn)問題,調(diào)用這

    2024年02月14日
    瀏覽(24)
  • 【OpenFeign】OpenFeign結(jié)合Hystrix和Sentinel實現(xiàn)熔斷降級

    OpenFeign可以與Hystrix和Sentinel結(jié)合使用,實現(xiàn)降級和熔斷。 使用OpenFeign需要引入OpenFeign的依賴: spring-cloud-starter-openfeign 引入的依賴如下: 默認(rèn)已經(jīng)自動引入了hystrix的依賴,不再需要單獨再引入hystrix了。 降級方法的類需要實現(xiàn)FeignClient的接口,同時這個類需要注入到Spring容器

    2024年02月11日
    瀏覽(30)
  • 【從0到1設(shè)計一個網(wǎng)關(guān)】基于Hystrix實現(xiàn)熔斷降級

    上文我們已經(jīng)成功實現(xiàn)了請求重試與請求限流,接下來我們開始實現(xiàn)熔斷與服務(wù)降級。 熔斷與服務(wù)降級,在SpringCloud中設(shè)計到的就是我們的hystrix,這里我們也將會考慮配合hystrix來實現(xiàn)熔斷與服務(wù)降級。 如果不了解hystix的可以先進行一下了解。 由于這里我是用的是基于hystr

    2024年02月05日
    瀏覽(22)
  • Spring Boot Dubbo Zookeeper

    Common 公共依賴 定義接口(用戶服務(wù)注冊使用) Provider 首先需要依賴Common yml 實現(xiàn)定義的接口(Service是apache.dubbo) 啟動類(@EnableDubbo) Consumer 首先需要依賴Common Controller(@Reference注解) 安裝腳本

    2024年02月11日
    瀏覽(44)
  • 【微服務(wù)筆記10】微服務(wù)組件之Hystrix實現(xiàn)服務(wù)降級和服務(wù)熔斷

    【微服務(wù)筆記10】微服務(wù)組件之Hystrix實現(xiàn)服務(wù)降級和服務(wù)熔斷

    這篇文章,主要介紹微服務(wù)組件之Hystrix實現(xiàn)服務(wù)降級和服務(wù)熔斷。 目錄 一、服務(wù)降級 1.1、什么是服務(wù)降級 1.2、實現(xiàn)服務(wù)降級 (1)引入依賴 (2)編寫Service層代碼 (3)編寫Controller層代碼 (4)運行測試 (5)fallbackMethod屬性 二、服務(wù)熔斷 2.1、什么是服務(wù)熔斷 2.2、實現(xiàn)服務(wù)

    2023年04月11日
    瀏覽(22)
  • SpringCloud-Hystrix服務(wù)熔斷與降級工作原理&源碼 | 京東物流技術(shù)團隊

    SpringCloud-Hystrix服務(wù)熔斷與降級工作原理&源碼 | 京東物流技術(shù)團隊

    在微服務(wù)架構(gòu)中,根據(jù)業(yè)務(wù)來拆分成一個個的服務(wù),服務(wù)與服務(wù)之間可以相互調(diào)用(RPC),在Spring Cloud可以用RestTemplate+Ribbon和Feign來調(diào)用。為了保證其高可用,單個服務(wù)通常會集群部署。由于網(wǎng)絡(luò)原因或者自身的原因,服務(wù)并不能保證100%可用,如果單個服務(wù)出現(xiàn)問題,調(diào)用這

    2024年02月14日
    瀏覽(26)
  • Dubbo Spring Boot Starter 開發(fā)微服務(wù)應(yīng)用

    Dubbo Spring Boot Starter 開發(fā)微服務(wù)應(yīng)用

    系統(tǒng):Windows、Linux、MacOS JDK 8 及以上(推薦使用 JDK17) Git IntelliJ IDEA(可選) Docker (可選) 在本任務(wù)中,將分為 3 個子模塊進行獨立開發(fā),模擬生產(chǎn)環(huán)境下的部署架構(gòu)。 如上所示,共有 3 個模塊,其中? interface ?模塊被? consumer ?和? provider ?兩個模塊共同依賴,存儲 RPC

    2024年02月12日
    瀏覽(27)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包