openfeign依据consul中的服务找到对应的pod的ip:port。蓝绿怎么做? ```mermaid flowchart TD subgraph Client Side A[Spring Boot App with OpenFeign] -->|Call my-service| B[Spring Cloud LoadBalancer] end subgraph Consul B -->|Query my-service instances| C[Consul Service Discovery] C -->|Return instances with tags/meta| D[Instance List with version info] end subgraph K8s Cluster D -->|Filter version=blue/green| E[Service Selector / LoadBalancer] subgraph Blue Deployment E --> F[Pod Blue 1] E --> G[Pod Blue 2] end subgraph Green Deployment E --> H[Pod Green 1] E --> I[Pod Green 2] end end %% Optional: Gateway / Ingress for traffic control subgraph Gateway/Ingress Layer J[Ingress / Service Mesh] -.-> E J -->|Route 90% blue, 10% green| F J -->|Route 90% blue, 10% green| H end ``` ❓ 蓝系统weight 0,绿系统100%,但蓝系统的kafka还在消费,topic被蓝系统消费掉了,会不会产生问题? 没有问题。如果蓝绿规划为同一消费者组,并且消费是密等的,被谁消费掉无所谓。 💡 最佳实践: 1. 蓝绿切换时,不仅切换 HTTP 流量,还要 优雅下线旧版本 Kafka 消费器 2. 消费逻辑保持幂等,避免蓝绿切换引发重复处理 redis: 共享 Redis + 蓝绿系统写入隔离 mysql: ```mermaid flowchart TD subgraph ClientSide A[HTTP_Request] -->|flow_0_percent| B[Blue_System_old_version] A -->|flow_100_percent| C[Green_System_new_version] end subgraph MySQLCluster D[(MySQL_Primary_Cluster)] end %% Blue system behavior B -->|finish_old_transactions| D B -->|use_old_schema_fields| D %% Green system behavior C -->|handle_new_requests| D C -->|use_new_schema_fields| D %% Notes subgraph Notes N1[Blue system flow 0 but finishes old transactions to ensure data consistency] N2[Blue/Green share MySQL, schema must be backward compatible] N3[Write operations should be idempotent to avoid conflicts] end ```