Git Product home page Git Product logo

spring-boot-reactive-example's Introduction

Spring-boot Reactive Example

ตัวอย่างการเขียน Java Spring-boot Reactive (WebFlux) ซึ่งเป็นการเขียน Spring-boot แบบ Non-Blocking I/O หรือ Asynchronous

Reactive Spring

เชิญชวน

อยากเชิญชวน คนที่มีความรู้ความสามารถด้านใดด้านหนึ่งตามที่ตัวเองถนัด ทำตัวอย่างอะไรทำนองนี้ไว้
เพื่อให้ผู้เริ่มต้น หรือมือใหม่ได้มีตัวอย่างอ้างอิงที่สามารถเอาไปประยุกต์ใช้ได้

ตัวผมเองก็ใช้อันนี้สอนน้อง ๆ สอนเด็กฝึกงานที่บริษัท อีกทั้งเอาไว้ทบทวนตัวเองด้วย
กับเห็นว่ามันมีประโยชน์สำหรับทุกคน เลยแชร์ไว้ครับ

ปัญหา / ข้อเสนอแนะ

หากพบปัญหา หรือ ต้องการให้ทำอะไรเพิ่ม รบกวนช่วยเปิด issue หรือ fork/pull request ให้ด้วยน่ะครับ
ขอบคุณครับ :)

การสนันสนุน หรือ Donate

สำหรับคนที่นำ Repository นี้ไปใช้ในการเรียนรู้ หรือสร้างสรรค์ผลงานให้เกิดมูลค่า
ถ้าอยากที่จะสนับสนุนหรือ Support Repository นี้ สามารถทำได้ 3 ทางครับ คือ

  1. ผ่านทาง Prompt Pay QR Code
  2. ผ่านบัญชีธนาคาร
  3. ผ่านทาง Buy Me a Coffee

ทั้งนี้เพื่อเป็นค่ากาแฟ และค่าแพมเพิส (ผ้าอนามัย) ลูกสาวครับ 😍

Prompt Pay QR

บัญชีธนาคาร

ธนาคารไทยพาณิชย์
เลขที่บัญชี 274-214985-3
ชื่อบัญชี นายจิตกร พิทักษ์เมธากุล

By Me a Coffee

คลิกที่ปุ่มนี้

ถ้ามีข้อสงสัยอะไร สามารถ Inbox ไปสอบถามใน Facebook ส่วนตัวได้ครับ
https://www.facebook.com/jittagornp

Spring

https://spring.io

Spring เป็น Framework ฝั่งภาษา Java สำหรับใช้เขียน Web และ Back-end Application ที่ได้รับความนิยมอย่างมากในปัจจุบัน มีระบบนิเวศ หรือ Ecosystem ต่าง ๆ มากมาย ทำให้สามารถนำ Spring ไปใช้สร้างสรรค์ผลงานต่าง ๆ ได้อย่างรวดเร็ว

Spring-boot

https://spring.io/projects/spring-boot

Spring-boot เป็น Subset (Project นึง) ของ Spring Framework เป็นการเอา Ecosystem ต่าง ๆ ของ Spring ที่มีอยู่ มาประกอบร่างรวมกัน เพื่อให้ใช้งาน Spring ได้ง่ายขึ้น โดยมีจุดเด่นดังนี้

  1. สามารถใช้ Spring-boot ทำ Stand Alone หรือ Micro Service Application ได้
  2. มี Embeded Application Server ภายในตัว สามารถ Start ตัวเองได้ โดยไม่ต้องพึ่งพา Application Server จากภายนอก
  3. มีระบบ Auto Configuration
  4. Config ง่าย
  5. ใช้งานง่าย
  6. Deploy ง่าย
  7. อื่น ๆ

Spring-boot มี 2 แบบ คือ

  1. แบบ Servlet Stack
  2. แบบ Reactive Stack

Servlet Stack

  • เป็นการเขียน Code แบบ Blocking I/O
  • ใช้ Web MVC เป็น Base
  • เขียนง่าย ตรงไปตรงมา
  • Application Server จะใช้เทคนิคในการจัดการ Request/Response ด้วย Thread Pool Connection

Reactive Stack

  • เป็นการเขียน Code แบบ Non-Blocking I/O
  • เขียน Code แบบ Reactive (เป็นการเขียนโปรแกรมรูปแบบหนึ่ง ที่ตอบสนองต่อเหตุการณ์ที่เกิดขึ้น)
  • ใช้ WebFlux เป็น Base
  • เขียน/เข้าใจ ยากกว่าแบบ Servlet Stack
  • Application Server จะใช้เทคนิคในการจัดการ Request/Response ด้วย Event Loop
  • กิน Resources (CPU, RAM) น้อยกว่าแบบ Servlet Stack
  • รองรับ Concurrent ได้มากกว่าแบบ Servlet Stack

Spring-boot Reactive

สามารถเขียนได้ 2 แบบ คือ

  1. แบบ Annotated Controllers
  2. แบบ Functional Endpoints

จากตัวอย่าง โดยส่วนมากจะใช้เป็นแบบ Annotated Controllers

เอกสาร Spring-boot Reactive

สำหรับคนที่เขียน Spring-boot ใหม่ ๆ แล้วสงสัยว่า เราจะรู้ได้ยังไงว่าเราสามารถ Config Application Properties อะไรได้บ้าง ให้ดูจากหน้านี้

ข้อแตกต่าง

WebFlux Performance

Prerequisites

สิ่งที่ต้องรู้ก่อนเขียน Spring-boot Reactive

ตัวอย่างการเขียน Reactor

เริ่ม

Code บางตัวอาจจะไม่สามารถเอาไป Run ได้เลย เนื่องจากต้องเตรียม environment ต่าง ๆ ให้พร้อมก่อน เช่น Postgresql, Mongodb, Redis เป็นต้น ต้องมี database หรือ data source ปลายทางก่อน

ให้เรียนรู้/ดูตัวอย่างตามลำดับต่อไปนี้

spring-boot-reactive-example's People

Contributors

jittagornp 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.