Spring Cloud มีอะไรบ้าง?
Cloud Native เป็นรูปแบบของการพัฒนาที่ส่งเสริมให้เกิด best practice สำหรับ continuous delivery และ value-driven development กฎระเบียบที่เกี่ยวข้องกับการสร้าง 12-factor Application ที่เป็นแนวปฏิบัติสำหรับการพัฒนาที่มีเป้าหมาย delivery และ operation โดยใช้ declarative programming และ management และ monitoring ซึ่ง Spring Cloud ช่วยอำนวยความสะดวกในรูปแบบการพัฒนาเหล่านี้ในรูปแบบต่างๆ
Spring Cloud
Spring Cloud มีเป้าหมายสร้าง solution สำหรับ commonly encounter pattern เมื่อสร้างระบบบน Cloud ซึ่งมีคุณสมบัติที่สำคัญดังนี้
- Distributed/versioned configuration
- Service registration and discovery
- Routing
- Service-to-service calls
- Load balancing
- Circuit Breakers
- Distributed messaging
Spring Cloud ไม่ใช้เพียงโครงการเดียว แต่เป็นกลุ่มของโครงการย่อยที่มีเป้าหมายที่จะแก้ปัญหาเกี่ยวกับการใช้งาน application บน Clould มีโครงการหลักๆ ดังนี้
Spring Cloud Config
เป็นจุดศูนย์กลางสำหรับจัดการ external configuration ด้วย Git repository โดยใช้ Client/Server map กับ Spring Environment
และ PropertySource
ได้โดยตรง
Spring Cloud Netflix
เป็นโครงการที่รวมกันของหลาหลาย component ของ Netflix OSS เช่น
- Eureka (Service Discovery)
- Hystrix (Circuit Braker)
- Zuul (Intelligent Routing)
- Ribbon (Client Side Load Balancing)
- Archaius (External Configuration)
Spring Cloud Bus
เป็น event bus สำหรับเชื่อมโยง service กับ service เข้าด้วยกันด้วย distributed messaging ใช้สำหรับกระจายการเปลี่ยนแปลงสถานะตลอดทั้ง cluster (เช่น Config Change Events ..)
Spring Cloud Sleuth
เป็น Distributed tracing สำหรับ Spring Cloud application ด้วย Dapper, Zipkin, และ HTrace ซึ่งสามารถ capture dataใน log หรือส่งข้อมูลไปยัง remote collector service
Spring Cloud Data Flow
เป็น toolkit สำหรับสร้าง data integration และ real-time data processing pipeline โดยมี DSL, GUI และ REST API ให้
Spring Cloud Stream
ทำให้สามารถใช้งาน Spring-based application กับ message broker อย่างเช่น Apache Kafka หรือ RabbitMQ ได้
นอกจากนี้ยังมีโครงการอื่นๆ ของ Spring Cloud อีก ดังนี้
Spring Cloud Cloudfoundry — integrated กับ Pivotal Could Foundry
Spring Cloud Open Service Broker — Service Broker สำหรับ Could Foundry
Spring Cloud Cluster — Leadership eclection
Spring Cloud Consul — Service discovery ด้วย Hashicorp Consul
Spring Cloud Security — load-balanced OAuth2 rest client
Spring Cloud Task — Short lived microservice
Spring Cloud Vault — integrated กับ Hashicorp Vault
Spring Cloud Zookeeper — Service discovery ด้วย Apache Zookeeper
Spring Cloud AWS — integrated กับ Amazon Web Service
Spring Cloud Connectors — สร้าง PaaS appplication
Spring Could CLI — CLI สำหรับ Spring Cloud
Spring Cloud Contract — implement Customer Driven Contract approach
Spring Cloud Gateway — Intelligent router โดยใช้ Project Reactor
Spring Cloud OpenFeign — integrated กับ OpenFeign
Spring Cloud Pipelines — สร้าง pipeline สำหรับ CI/CD
Spring Cloud Function — สร้าง business logic ด้วย functions
Spring Could Config
เป็นการสร้างจุดศูนย์กลางจัดการ external configuration ด้วย Git repository โดยใช้ Client/Server map กับ Spring Environment
ได้โดยตรง ซึ่งจะต้องมีทั้ง Server สำหรับเก็บ config และ Client สำหรับเรียกใช้งาน config จาก Server
Config Server
ในส่วนของ Server configuration นั้นจะใช้ @EnableConfigServer annotation เพื่อเปิดใช้งาน และใน application properties กำหนดให้ git.uri เป็นที่อยู่ของ Git repository ที่เก็บ configuration ของ client ไว้ (ในที่นี้ใช้ local Git) โดยชื่อของ configuration จะต้องตรงกับชื่อของ client
application.properties
server.port=8888spring.cloud.config.server.git.uri=${HOME}/repos/config
Config Client
ในส่วนของ Client นั้นใช้ @RefreshScope annotation เพื่อ trigger refresh event และใน bootstrap properties กำหนด config.uri เป็นที่อยู่ของ Config Server (ในที่นี้คือ localhost:8888) และกำหนดชื่อของ Application ให้ตรงกับชื่อของ configuration ใน Git repository
bootstrap.properties
spring.application.name=a-bootiful-client
spring.cloud.config.uri=http://localhost:8888
นี่เป็นเพียงตัวอย่างเบื้องต้นสำหรับ Spring Cloud