Giter VIP home page Giter VIP logo

spring-cloud-mall's Introduction

spring-cloud-mall

基于spring-Netflix-cloud开的商城,总结一些典型的案例和开发中遇到的坑

环境

idea / jdk1.8 / spring Netflix cloud(Finchley-2.0.6) / mysql5.7 /

1.1 简介

项目名称 项目简介
erureka-server erueka注册中心;
fegin-api fegin调用的一个整合包;
mall-common 公共模块,pojo
mall-gateway gateway网关模块;
mall-consumer 消费者
mall-product 生产者

1.2 解决依赖自己common的jar包,但是依赖他的使用maven install 报包找不到错误的问题(启动正常打包却失败)

  1. 给自己打jar的加一个打包名称
    <build>
        <finalName>mall-common</finalName>
    </build>
  1. 给父工程增加maven插件: execute
    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>none</phase>
                    </execution>
                </executions>
                <configuration>
                    <classifier>execute</classifier>
                </configuration>
            </plugin>
        </plugins>
    </build>

2. 一个请求是如何流转到数据库的

在这里插入图片描述 请求地址:http://127.0.0.1:8888/test/test/hello/1

  1. 首先请求到达gateway由断言(predicates)接收到对应的请求后
  2. 使用ribbon对这次请求进行分发到 MALL-CONSUMER
  3. 其中的一个消费者开始处理这个请求
  4. 最后请求根据ribbon的处理到达生产者

3. ribbon fegin Hystrix 三者组合后调用时的超时时间设置

##===================重试机制===============================


spring.cloud.loadbalancer.retry.enabled=true
##断路器超时时间       这次请求不允许超过的总时间
#断路器超时时间 必须大于 ribbon(1+1+1)*ribbon.ReadTimeout 否则ribbon还没有重试完就被断路器给走降级了
hystrix.command.default.execution.isolation.thread.timeoutInMilliseconds=1000

##请求连接超时时间     请求到提供者返回不能超过的时间
ribbon.ConnectTimeout=200
##请求处理超时时间     请求到提供者后处理的不能超过的时间
ribbon.ReadTimeout=200
##对所有操作请求都进行重试

  #对所有操作请求都进行重试
  #设置为true时,会对所有的请求进行重试,若为false只会对get请求进行重试
  #如果是putpost等写操作,
  #如果服务器接口没做幂等性,会产生不好的结果,所以OkToRetryOnAllOperations慎用。
  #默认情况下,GET方式请求无论是连接异常还是读取异常,都会进行重试
  #非GET方式请求,只有连接异常时,才会进行重试


ribbon.OkToRetryOnAllOperations=true
##切换实例的重试次数
ribbon.MaxAutoRetriesNextServer=2
##对当前实例的重试次数,首次调用不包括在内
ribbon.MaxAutoRetries=1

##==================重试机制===============================

4. gateway实现动态配置网关

官方教程讲的都是提前在配置文件中配置网关,而在实际工作中不可能随便重启网关服务,这时动态配置就急需要解决; 动态网关配置:redis mysql gateway2.0.1; 具体代码在mall-gateway模块

spring-cloud-mall's People

Contributors

ssy-githup avatar

Stargazers

 avatar  avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.