<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ## 原理 [14.user-center模塊](11.user-center%E6%A8%A1%E5%9D%97.md) ## 改依賴 將eureka-client依賴替換alibaba服務發現組件 ![](https://img.kancloud.cn/5f/5e/5f5ec9bdfc91f2bb9357177053b74b5f_1907x390.png) ![](https://img.kancloud.cn/61/e4/61e44265ba2b0deb32fd11a526fe886b_1605x621.png) ``` <!-- 選用nacos時打開--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <!--alibaba sentinel--> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-sentinel</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> ``` ## 改配置 * eureka client與 nacos client區別 ![](https://img.kancloud.cn/f2/e9/f2e902ade981313193951b159d7fc434_1887x782.png) * 使用公共配置 ![](https://img.kancloud.cn/3a/60/3a60cca5ea27e586830282a4c1713d82_1374x646.png) * user-center配置 ![](https://img.kancloud.cn/1f/9d/1f9d9ddb2bcb8ac83a5f24bcfcba01cf_1920x522.png) * user-center.yaml ![](https://img.kancloud.cn/08/60/086099e6a0dc07d4fc893eff35a45d69_1920x517.png) ``` #端口配置 server: port: 7000 #固定端口 # port: ${randomServerPort.value[7000,7005]} #隨機端口 spring: datasource: # JDBC 配置(驅動類自動從url的mysql識別,數據源類型自動識別) url: jdbc:mysql://59.110.164.254:3306/user-center?useUnicode=true&characterEncoding=utf-8&allowMultiQueries=true&useSSL=false username: root password: root driver-class-name: com.mysql.cj.jdbc.Driver #連接池配置(通常來說,只需要修改initialSize、minIdle、maxActive initial-size: 1 max-active: 20 min-idle: 1 # 配置獲取連接等待超時的時間 max-wait: 60000 #打開PSCache,并且指定每個連接上PSCache的大小 pool-prepared-statements: true max-pool-prepared-statement-per-connection-size: 20 validation-query: SELECT 'x' test-on-borrow: false test-on-return: false test-while-idle: true #配置間隔多久才進行一次檢測,檢測需要關閉的空閑連接,單位是毫秒 time-between-eviction-runs-millis: 60000 #配置一個連接在池中最小生存的時間,單位是毫秒 min-evictable-idle-time-millis: 300000 filters: stat,wall # WebStatFilter配置,說明請參考Druid Wiki,配置_配置WebStatFilter #是否啟用StatFilter默認值true web-stat-filter.enabled: true web-stat-filter.url-pattern: /* web-stat-filter.exclusions: "*.js , *.gif ,*.jpg ,*.png ,*.css ,*.ico , /druid/*" web-stat-filter.session-stat-max-count: 1000 web-stat-filter.profile-enable: true # StatViewServlet配置 #展示Druid的統計信息,StatViewServlet的用途包括:1.提供監控信息展示的html頁面2.提供監控信息的JSON API #是否啟用StatViewServlet默認值true stat-view-servlet.enabled: true #根據配置中的url-pattern來訪問內置監控頁面,如果是上面的配置,內置監控頁面的首頁是/druid/index.html例如: #http://110.76.43.235:9000/druid/index.html #http://110.76.43.235:8080/mini-web/druid/index.html stat-view-servlet.url-pattern: /druid/* #允許清空統計數據 stat-view-servlet.reset-enable: true stat-view-servlet.login-username: admin stat-view-servlet.login-password: admin #StatViewSerlvet展示出來的監控信息比較敏感,是系統運行的內部情況,如果你需要做訪問控制,可以配置allow和deny這兩個參數 #deny優先于allow,如果在deny列表中,就算在allow列表中,也會被拒絕。如果allow沒有配置或者為空,則允許所有訪問 #配置的格式 #<IP> #或者<IP>/<SUB_NET_MASK_size>其中128.242.127.1/24 #24表示,前面24位是子網掩碼,比對的時候,前面24位相同就匹配,不支持IPV6。 #stat-view-servlet.allow= #stat-view-servlet.deny=128.242.127.1/24,128.242.128.1 # Spring監控配置,說明請參考Druid Github Wiki,配置_Druid和Spring關聯監控配置 #aop-patterns= # Spring監控AOP切入點,如x.y.z.service.*,配置多個英文逗號分隔 ################### mysq end ########################## # zipkin: # base-url: http://127.0.0.1:11008 redis: ################### redis 單機版 start ########################## host: 59.110.164.254 port: 6379 timeout: 6000 database: 8 lettuce: pool: max-active: 10 # 連接池最大連接數(使用負值表示沒有限制),如果賦值為-1,則表示不限制;如果pool已經分配了maxActive個jedis實例,則此時pool的狀態為exhausted(耗盡) max-idle: 8 # 連接池中的最大空閑連接 ,默認值也是8 max-wait: 100 # # 等待可用連接的最大時間,單位毫秒,默認值為-1,表示永不超時。如果超過等待時間,則直接拋出JedisConnectionException min-idle: 2 # 連接池中的最小空閑連接 ,默認值也是0 shutdown-timeout: 100ms ################### redis 單機版 end ########################## # cluster: # nodes: 130.75.131.237:7000,130.75.131.238:7000,130.75.131.239:7000,130.75.131.237:7001,130.75.131.238:7001,130.75.131.239:7001 # #130.75.131.237:7000,130.75.131.238:7000,130.75.131.239:7000,130.75.131.237:7001,130.75.131.238:7001,130.75.131.239:7001 # #192.168.3.157:7000,192.168.3.158:7000,192.168.3.159:7000,192.168.3.157:7001,192.168.3.158:7001,192.168.3.159:7001 # timeout: 1000 # 連接超時時間(毫秒) # lettuce: # pool: # max-active: 10 # 連接池最大連接數(使用負值表示沒有限制),如果賦值為-1,則表示不限制;如果pool已經分配了maxActive個jedis實例,則此時pool的狀態為exhausted(耗盡) # max-idle: 8 # 連接池中的最大空閑連接 ,默認值也是8 # max-wait: 100 # # 等待可用連接的最大時間,單位毫秒,默認值為-1,表示永不超時。如果超過等待時間,則直接拋出JedisConnectionException # min-idle: 2 # 連接池中的最小空閑連接 ,默認值也是0 # shutdown-timeout: 100ms mybatis-plus: global-config: banner: false configuration: log-impl: org.apache.ibatis.logging.stdout.StdOutImpl mapper-locations: classpath*:com/open/**/dao/*.xml security: oauth2: ignored: /users-anon/** , /doc.html ,/document.html ,/users/save token: store: type: redis #設置最大超時時間 ribbon: ServerListRefreshInterval: 10 #刷新服務列表源的間隔時間 OkToRetryOnAllOperations: true MaxAutoRetries: 1 MaxAutoRetriesNextServer: 1 ReadTimeout: 16000 ConnectTimeout: 16000 #設置最大容錯超時時間 hystrix: command: default: execution: timeout: enabled: true isolation: thread: timeoutInMilliseconds: 16000 logging: level: com.open.capacity: INFO org.hibernate: INFO org.hibernate.type.descriptor.sql.BasicBinder: TRACE org.hibernate.type.descriptor.sql.BasicExtractor: TRACE # com.neusoft: DEBUG # com.netflix: DEBUG #用于心跳檢測輸出的日志 ``` * 配置中心的優先級 Spring Cloud Alibaba Nacos Config 目前提供了三種配置能力從 Nacos 拉取相關的配置。 1: 通過內部相關規則(應用名、擴展名 )自動生成相關的 Data Id 配置 2: 通過?spring.cloud.nacos.config.ext-config[n].data-id?的方式支持多個擴展 Data Id 的配置,多個 Data Id 同時配置時,他的優先級關系是?spring.cloud.nacos.config.ext-config[n].data-id?其中 n 的值越大,優先級越高。(2.1>2.2>2.3) 3: 通過?spring.cloud.nacos.config.shared-dataids?支持多個共享 Data Id 的配置 當三種方式共同使用時,他們的一個優先級關系是:1 > 2 >3,如圖所示: ![](https://img.kancloud.cn/f0/91/f09129b7636ac1eb7e8ac2dbb1684d12_1112x585.png) ## 啟動項目 ![](https://img.kancloud.cn/79/5c/795c038925def788182eabd2e5f7cead_1920x463.png) ## nacos 源碼分析 ### 自動裝配 ![](https://img.kancloud.cn/3b/58/3b58a43996b3771f0651ae9ea424f3ca_1739x343.png) #### 注冊邏輯 * ->com.alibaba.cloud.nacos.registry.NacosServiceRegistryAutoConfiguration.nacosAutoServiceRegistration(NacosServiceRegistry, AutoServiceRegistrationProperties, NacosRegistration) * -->org.springframework.cloud.client.serviceregistry.AbstractAutoServiceRegistration.register() * --->org.springframework.cloud.alibaba.nacos.registry.NacosServiceRegistry.register(Registration) * ---->com.alibaba.nacos.client.naming.net.NamingProxy.registerService(String, String, Instance) ``` public void registerService(String serviceName, String groupName, Instance instance) throws NacosException { NAMING_LOGGER.info("[REGISTER-SERVICE] {} registering service {} with instance: {}", namespaceId, serviceName, instance); final Map<String, String> params = new HashMap<String, String>(9); params.put(CommonParams.NAMESPACE_ID, namespaceId); params.put(CommonParams.SERVICE_NAME, serviceName); params.put(CommonParams.GROUP_NAME, groupName); params.put(CommonParams.CLUSTER_NAME, instance.getClusterName()); params.put("ip", instance.getIp()); params.put("port", String.valueOf(instance.getPort())); params.put("weight", String.valueOf(instance.getWeight())); params.put("enable", String.valueOf(instance.isEnabled())); params.put("healthy", String.valueOf(instance.isHealthy())); params.put("ephemeral", String.valueOf(instance.isEphemeral())); params.put("metadata", JSON.toJSONString(instance.getMetadata())); reqAPI(UtilAndComs.NACOS_URL_INSTANCE, params, HttpMethod.POST); } ``` #### 心跳檢測 * -> java.util.concurrent.ScheduledExecutorService.schedule(Runnable, long, TimeUnit) ``` public long sendBeat(BeatInfo beatInfo) { try { if (NAMING_LOGGER.isDebugEnabled()) { NAMING_LOGGER.debug("[BEAT] {} sending beat to server: {}", namespaceId, beatInfo.toString()); } Map<String, String> params = new HashMap<String, String>(4); params.put("beat", JSON.toJSONString(beatInfo)); params.put(CommonParams.NAMESPACE_ID, namespaceId); params.put(CommonParams.SERVICE_NAME, beatInfo.getServiceName()); String result = reqAPI(UtilAndComs.NACOS_URL_BASE + "/instance/beat", params, HttpMethod.PUT); JSONObject jsonObject = JSON.parseObject(result); if (jsonObject != null) { return jsonObject.getLong("clientBeatInterval"); } } catch (Exception e) { NAMING_LOGGER.error("[CLIENT-BEAT] failed to send beat: " + JSON.toJSONString(beatInfo), e); } return 0L; } ``` #### 健康檢測 * com.alibaba.cloud.nacos.endpoint.NacosDiscoveryEndpointAutoConfiguration.nacosDiscoveryHealthIndicator(NacosDiscoveryProperties) ``` public boolean serverHealthy() { try { String result = reqAPI(UtilAndComs.NACOS_URL_BASE + "/operator/metrics", new HashMap<String, String>(2)); JSONObject json = JSON.parseObject(result); String serverStatus = json.getString("status"); return "UP".equals(serverStatus); } catch (Exception e) { return false; } } ``` ## user-center 內部原理請參考03.模塊詳解部分
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看