<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Takdanai jirawanichkul on Medium]]></title>
        <description><![CDATA[Stories by Takdanai jirawanichkul on Medium]]></description>
        <link>https://medium.com/@takdanai.3473?source=rss-da4e73901a95------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*-e6zDsZ0UdzlfsqQsoNIWA.jpeg</url>
            <title>Stories by Takdanai jirawanichkul on Medium</title>
            <link>https://medium.com/@takdanai.3473?source=rss-da4e73901a95------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 17:57:56 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@takdanai.3473/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[ออกแบบ OpenAPI ง่ายๆโดยใช้ Stoplight Studio]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B8%AD%E0%B8%AD%E0%B8%81%E0%B9%81%E0%B8%9A%E0%B8%9A-openapi-%E0%B8%87%E0%B9%88%E0%B8%B2%E0%B8%A2%E0%B9%86%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-stoplight-studio-c3e7d15e0bca?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/c3e7d15e0bca</guid>
            <category><![CDATA[stoplight-studio]]></category>
            <category><![CDATA[open-api]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Thu, 26 Mar 2020 05:38:31 GMT</pubDate>
            <atom:updated>2020-03-26T05:51:23.222Z</atom:updated>
            <content:encoded><![CDATA[<p>ในการพัฒนาโปรแกรม ขั้นตอนที่สำคัญก็คือการออกแบบ ถ้าเราพัฒนาโปรแกรมไปก่อนที่จะออกแบบให้ดีแต่แรก เราก็จะประสบปัญหาต่างๆ ว่าตรงนี้เราลืมคิดไป จะเพิ่มก็ไปมีปัญหากับส่วนอื่นๆ หรือจะเป็นการทำงานร่วมกันเป็นทีม การทำงานร่วมกันหลายๆคนก็ควรที่จะมีเครื่องมือที่ช่วยกำหนดทิศทางให้ไปในทางเดียวกัน</p><p>จะดีกว่าไหมถ้าเราใช้เครื่องมือที่ช่วยเราออกแบบ API ให้ง่ายขึ้น มีมาตราฐาน และทุกคนสามารถเข้าถึงได้ ในบทความนี้จะเป็นมาลองใช้เจ้า Stoplight studio กัน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*l8HF15wS1ZjzN89RaQpFXw.png" /><figcaption><a href="https://stoplight.io/">https://stoplight.io</a></figcaption></figure><p>ตัว Stoplight Studio สามารถช่วยให้การพัฒนาเร็วขึ้น และ แบ่งปันไปให้คนอื่นๆได้อย่างรวดเร็ว</p><p>ในการทำงานเกี่ยวกับการออกแบบ API มีส่วนสำคัญที่ 3 ส่วนใหญ่ๆ ได้แก่</p><ol><li><strong>API Design</strong><br>เราสามารถออกแบบ API ได้อย่างรวดเร็ว และสามารถใช้ OpenAPI เพื่อช่วยให้เราออกแบบได้ไปในทิศทางเดียวกัน และ มีมาตราฐานของ REST APIs โดยที่เราแทบไม่ต้องใช้ทักษะ Coding กันเลย</li><li><strong>API Documentation</strong><br>ในขณะที่เรากำลังออกแบบอยู่เราสามารถ ทำเอกสารอธิบายควบคู่ไปด้วยได้เลย</li><li><strong>API Mocking</strong><br>หลังจากที่เราออกแบบเสร็จเรียบร้อย เราก็สามารถนำสิ่งที่เราออกแบบมา ทดสอบจริงได้อีกด้วย</li></ol><p>หลังจากที่เราได้รู้จักกับ Stoplight Studio เบื้องต้นกันแล้ว เรามาลองออกแบบ API และมาทดสอบกันเลยดีกว่า</p><h3>1. ติดตั้ง Stoplight Studio</h3><p>โดยเข้าไปที่เว็ปไซต์ <a href="https://stoplight.io/studio/">https://stoplight.io/studio</a> ได้เลย โดยโปรแกรมนี้สามารถรองรับได้หลาย platform ทั้งหน้าเว็ป และติดตั้งบนคอมพิวเตอร์</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4_-2kcxo5c_ZWjfzdCfPEQ.png" /><figcaption><a href="https://stoplight.io/studio/">https://stoplight.io/studio</a></figcaption></figure><p>หลังจากที่เราติดตั้งเสร็จเรียบร้อยแล้ว เราก็เปิดโปรแกรมขึ้นมาได้เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5fH5FF9NUmAHMMLfGQjwqg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/660/1*22OfSIyPDtJ2KpHSLw0kUw.png" /></figure><p>เราสามารถตั้งชื่อและสร้า Project ของเราได้เลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pFDGZbvtSoRhj6No15FCxg.png" /></figure><p>เมื่อเราสร้างโปรเจคใหม่เรียบร้อยแล้ว เรามาทำความรู้จัก กับหน้าตาของโปรแกรมเบื้องต้นกัน</p><ol><li>Project Name / Selector: เป็นส่วนของการแสดงชื่อโปรเจค เราสามารถค้นหาหรือเลือกโปรเจคอื่นๆ จากการคลิกไปยังชื่อโปรเจค</li><li>Project Actions: เป็นส่วนของการเพิ่มสิ่งต่างๆเข้าไปในยังโปรเจค สิ่งที่สามารถสร้างได้ตัวอย่างเช่น API, Endpoint, Model, Article, Image, File, Folder, New Project</li><li>User sharing: ส่วนของการจัดการ Publish &amp; Share โปรเจคของเราสามารถเข้าสู่ระบบได้ด้วย</li><li>Project Sidebar: เป็นการไฟล์ของโปรเจค ซึ่งเราสามารถเลือกการแสดงผลได้หลายมุมมอง <br>APIs แสดงเกี่ยวกับ APIs, endpoint, models<br>Docs แสดงเกี่ยวกับ เอกสารและไฟล์รูปต่างๆ<br>Files แสดงทุกไฟล์ในโปรเจค</li><li>Primary Panel: หน้าหลักในการ ออกแบบ API ซึ่งจะแสดงเป็นรูปแบบฟอร์ม หรือ โค้ด ได้</li><li>Secondary Panel: หน้าจอเพิ่มเติม จะใช้ได้เมื่อหน้าจอเรากว้างกว่า 1400px มีการทำงานคล้ายๆกับ หน้าต่างหลัก</li><li>Mock server: เราสามารถจำลองเซิฟเวอร์ เพื่อทดลอง API ที่เราออกแบบ</li><li>Validation and Linting: ส่วนของการแจ้งเตือนปัญหาต่างๆของโปรเจคเรา</li></ol><h3>2. ออกแบบ API</h3><p>ในวันนี้ เราจะสร้าง API สำหรับการที่สามารถดึงข้อมูลจำนวนผู้ติดเชื้อ COVID 19 กันนะครับ</p><p>*ในบทความนี้จะเป็นเหมือน จำลอง API มาเฉยๆนะครับ</p><p>API ที่เราต้องการสร้างในวันนี้คือ</p><p>ข้อมูลสรุปของ case ผู้ติดเชื้อ Covid 19 ในประเทศไทย ซึ่งก็จะมีข้อมูลคร่าวๆ จำนวนผู้ติดเชื้อ / จำนวนผู้ที่รักษาหายแล้ว / จำนวนผู้เสียชีวิต / ข้อมูลที่อัพเดทล่าสุด</p><h4>2.1 สร้าง API</h4><p>โดยคลิกไปที่ เพิ่ม API &gt; ตั้งชื่อ API ตามที่เราต้องการ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KGq8ZRwYlBQT911KWy1BoA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/988/1*PCbn5iWnZepXacN_cxDBSg.png" /></figure><p>หลังจากที่เราสร้างเสร็จเรียบร้อยแล้ว เราก็สามารถ เขียนอธิบาย API ไปใน API description และก็สามารถ ใส่ URL ของ servers เรา หรือ จะใส่รายละเอียดเกี่ยวกับข้อมูลติดต่อ เพื่อให้คนอื่นสามารถทำงานร่วมกันได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zZLtc22zvQxS1-pjxI5fhg.png" /></figure><h4>2.2 สร้าง Model</h4><p>คลิกไปที่ เพิ่ม Model &gt; ตั้งชื่อ Model ตามที่เราต้องการ</p><p>หลังจากที่สร้างเรียบร้อยแล้ว เราก็เพิ่มข้อมูลตามที่เราต้องการ ซึ่งเราก็สามารถเลือกประเภทของข้อมูลได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/986/1*m2WnM5zdkPncDqEPGTLkmw.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XCijJ_mcXT1H1Gnaq-34jA.png" /></figure><h4>2.3 สร้าง API End Point</h4><p>สร้าง API Endpoint ขึ้นมาใหม่ เราก็ต้องตั้งค่า Path และ เลือก Operations ที่ต้องการ ในที่นี้ ต้องการสร้างเพื่อดึงข้อมูล เราจึงเลือก GET Operations โดยที่เราสามารถเขียนคำอธิบายเพิ่มเติมได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/974/1*AU4z6HuDCscrj00wcDoSVg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*gPToCl3cPYH0i_cEkTQ12A.png" /></figure><p>หลังจากที่เราสร้างเรียบร้อยแล้ว เราจะต้องทำการเพิ่ม Response กันก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZgPnI-M4fLwP6C6-1Gj3Ig.png" /></figure><p>หลังจากที่เพิ่ม response เสร็จเรียบร้อยแล้ว ผมได้ทำการ เพิ่ม name เข้าไปใน body เพื่อส่งกลับไปให้ผู้เรียก API นี้</p><p>ซึ่งเราสามารถทดสอบได้โดยการ คลิกเข้าไปใน Mock Server เราจะเห็น Routes ที่เราสร้างขึ้นมา เราก็เปิด Mock URL ทางเซิฟเวอร์ก็จะส่งข้อมูลกลับมาให้ใน field ‘name’ ซึ่งข้อมูล ทางโปรแกรมจะสุ่มขึ้นมาให้นั้นเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tqDiPqgcH4X11CMEQYCLMQ.png" /></figure><p>หลังจากที่เราได้ลองทดสอบแล้ว เราก็มาเปลี่ยน ชนิดของข้อมูล โดยเราสามารถเลือก Model ที่เราสร้างไว้โดยการคลิกไปที่ $ref โดยเลือกชื่อที่เราต้องการ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/613/1*3x3FsdwiilYSLZ8U-jttHg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/611/1*S7WAZSsEoPuML0yoOsUwFA.png" /></figure><p>เราก็มาทดสอบกัน โดยที่เราสามารถคลิกไปที่ Preview โดยเลือกไปที่ Try it</p><p>โดยเราก็จะได้ข้อมูลตอบกลับออกมาตามโครงสร้างที่เราได้ออกแบบขึ้นมา แต่ข้อมูลที่แสดงผลจะเป็นการที่โปรแกรมทำการสุ่มขึ้นมา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TznmOdlFH6GgWgR5-o02Rw.png" /></figure><p>ก็จบเป็นที่เรียบร้อยสำหรับการใช้งาน Stoplight Studio เบื้องต้น</p><p>ผมคิดว่าถ้าเรานำมาใช้เป็นเครื่องมือที่ช่วยในการออกแบบ ทดสอบ และช่วยทำเอกสารให้เรา จะช่วยลดเวลาเราไปมากพอสมควรเลยหละ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c3e7d15e0bca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[แนวทางการออกแบบ Microservices]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B9%81%E0%B8%99%E0%B8%A7%E0%B8%97%E0%B8%B2%E0%B8%87%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%AD%E0%B8%AD%E0%B8%81%E0%B9%81%E0%B8%9A%E0%B8%9A-microservices-e35ad35fb22b?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/e35ad35fb22b</guid>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Sun, 09 Feb 2020 06:21:21 GMT</pubDate>
            <atom:updated>2020-02-09T06:21:21.088Z</atom:updated>
            <content:encoded><![CDATA[<h3>ทำไมเราต้องใช้ Microservices หละ?</h3><ul><li>แอปพลิเคชั่นต้องการความยืดหยุ่นที่สูง และ ต้องรองรับ User มหาศาล</li><li>แอปพลิเคชั่นใช้ Agile เพื่อให้สามารถแบ่งเป็นทีมย่อยๆเพื่อพัฒนาแอปพลิเคชั่นร่วมกัน</li><li>เมื่อเราต้องการพัฒนา Software ให้มีความรวดเร็ว และ สามารถเก็บ feedback จริงเพื่อนำมาแก้ไขได้อย่างรวดเร็ว</li></ul><h3>การออกแบบ microservice ให้ดี เป็นเรื่องที่ยาก</h3><p>เปรียบเทียบว่าเหมือนเราต้องการจะสร้างบ้าน เราก็ต้อง ออกแบบ เตรียมที่ดิน ตอกเสาเข็ม ขึ้นโครงสร้าง ตามด้วยงานตกแต่งภายในและภายนอก ค่อยๆเสร็จไปทีละส่วน ถ้ามีส่วนไหนที่มีปัญหา ที่จะต้องแก้ไข อาจจะมีปัญหา ไปถึงส่วนอื่นๆมากมาย</p><p>แต่ถ้าตัว microservice จะเป็นการ ออกแบบและแยกความสำคัญออกมาเป็นส่วนๆ โดยที่เราก็มาพูดตกลงกันว่า ในแต่ละส่วนจะมีความเชื่อมโยงกันอย่างไร หลังจากที่วางแผนกันเรียบร้อยแล้ว แต่ละส่วนก็ไปจัดการของตัวเอง และก็ และก็นำมารวมกันตามแผนงานที่วางไว้</p><p>ดังนั้นส่วนยากที่สุดของ Microservice Architecture คือ การออกแบบให้ดี</p><h3>รูปแบบในการออกแบบ Microservices</h3><p>การที่จะออกแบบ Microservices จะมีหลากหลายส่วนที่จะต้องคำนึงถึง ซึ่งก็จะแบ่งออกเป็น 3 ส่วนหลักๆตามรูปด้านล่าง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*jvZNbNHOZFWmj5QJ.jpg" /></figure><p>1. Application Patterns <br>เราก็มาดูว่า เราจะวางรูปแบบของ Microservice ของเราไปในทิศทางไหน ในขั้นแรกการจำแนกความต้องการต่างๆ ซึ่งก็จะมีวิธีการจำแนกได้หลากหลายรูปแบบตัวอย่างเช่น Business capability หรือ Domain-driven design ในลำดับถัดไปเราก็มาดูว่า จะเก็บข้อมูลในรูปแบบไหน และเราต้องทำให้ข้อมูลมีความไปในทิศทางเดียวกัน</p><p>2. Application infrastructure patterns<br>ในส่วนนี้ก็จะเป็นการออกแบบการติดต่อพูดคุย ออกแบบความปลอดภัยของระบบ เป็นเหมือนตัวกลางระหว่าง application และ infrastructure</p><p>3. Infrastructure patterns <br>งานหลักๆจะเกี่ยวเนื่องกับส่วนที่สอง ซึ่งจะเป็นการจัดการโครงสร้างพื้นฐานต่างๆ เช่นเราจะต้องการจัดการแต่ละ service อย่างไร? หรือจะเกี่ยวกับการ deployment</p><p>สำหรับใครที่สนใจเพิ่มเติมว่าแต่ละส่วนย่อยๆ ต้องทำอย่างไรอีกบ้าง แนะนำให้เข้าไปดูเพิ่มเติมใน <a href="https://microservices.io/patterns/index.html">https://microservices.io/patterns/index.html</a></p><h3>แนวทางการออกแบบ Microservice</h3><h4><strong>1. แยก application หลักให้เป็น service ย่อยๆก่อน</strong></h4><p>มีหลากหลายวิธีในการทำ จะมีสองวิธีที่ถูกพูดถึงบ่อยๆ ได้แก่</p><p><strong>Domain Driven Design </strong><br>Domain หมายถึง ขอบเขตสิ่งที่เรากำหนดไว้ เช่น ส่วนของ งานขาย และ งานบริการ ควรจะต้องแยกออกจากกันได้ ซึ่งมันก็จะเกิดขอบเขตระหว่าง Domain เราจะเรียกว่า Bounded Contexted</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/772/0*5TivvNUCrRNhShaa.png" /><figcaption>Domain Driven Design with Bounded Contexted</figcaption></figure><p>หลังจากที่เรามีการแบ่งเรียบร้อยแล้ว เราก็สามารถสร้าง Service ตาม Bounded context ก็จะมีขอบเขตที่ชัดเจน และ ไม่พึงพาอาศัยกับ service อื่นมากเกินไป</p><p><strong>Business Capability </strong><br>คือการที่เราสนใจเกี่ยวกับความโครงสร้างและความสามารถทางธุรกิจมาใช้ออกแบบ Service ต่างๆ เพื่อมาตอบความต้องการ ซึ่งก็จะตามกฎของ Conway’s Laws ที่กล่าวไว้ว่า</p><blockquote>organizations which design systems … are constrained to produce designs which are copies of the communication structures of these organizations.</blockquote><blockquote>— M. Conway<a href="https://en.wikipedia.org/wiki/Conway%27s_law#cite_note-Conway-2">[2]</a></blockquote><p>องค์กรที่ออกแบบระบบ ก็จะนำโครงสร้างองค์กรไปออกแบบระบบ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Yx2JV5MdHFHDqSYR.png" /><figcaption>Decompose application by Business capability</figcaption></figure><p>เราควรที่ทำ Document หรือใช้ Design Canvas ในการช่วยออกแบบ service ต่างๆ เป็นทางเลือกหนึ่งที่ช่วยในการออกแบบ และพัฒนาได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/647/0*J6UC7382_YRyJtGu.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/607/0*iLDQXHSA20zIRKhd.png" /><figcaption><em>Figure 3 — A sample microservice design canvas for “Payments Management Service” using the Capital One variant (information purely for demonstration purposes).</em></figcaption></figure><h4>2. ทำ Service ให้มีความเกี่ยวข้องกันน้อยๆ และ พยายามจัดกลุ่มให้มัน</h4><p>หรือจะเรียกสั้นๆว่า Low Coupling + High Cohesion หลายๆคนก็อาจจะยังไม่เข้าใจความหมายของสองคำนี้ ก่อนอื่นเรามาดูความหมายกันก่อน</p><p>Coupling คือ ระดับความเกี่ยวข้อง พึ่งพากันของ Service ต่างๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*pOmijLo0dMLNFAlg" /></figure><p>Cohesion คือ การบอกความสอดคล้องในการทำงานใน Service นั้นๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/300/0*ixvG6e6PBNtfr-SR" /></figure><p>ดังนั้นแต่ละ Service จะต้องมีความเป็นอิสระจากกันให้ได้มากที่สุด ( Low Coupling) และถ้า Service มีการทำงานในทิศทางเดียวกันเราก็จับมาอยู่ด้วยกัน ( High Cohesion ) หลักการนี้จะช่วยทำให้เวลาที่เราแก้ไข Service ต่างๆ ก็จะเกิดผลกระทบได้น้อยกว่า</p><h4><strong>3. แต่ละ Service ควรจะมีการเก็บข้อมูลเป็นของตัวเอง</strong></h4><p>ปัญหาที่ซ่อนอยู่คือ ปัญหาของข้อมูล เมื่อ services ที่ต้องการเรียกใช้ข้อมูลจากส่วนอื่นๆ ก็จะทำให้เกิด Coupling ขึ้นมาได้ service ที่ใช้ข้อมูลเยอะก็จะมีปัญหาเยอะ<br>ดังนั้นควรที่จะรู้ว่าแต่ละ service จะมีข้อมูลอะไรบ้าง และควรที่จะต้องมีฐานข้อมูลเป็นของตัวเอง ไม่ควรที่จะใช้ร่วมกับ service อื่นๆ เพื่อลดความเกี่ยวข้องไปได้อีกหนึ่งขั้นตอน</p><p>แต่เมื่อเราแยกข้อมูลเนี่ยออกจากกันแล้ว ปัญหาของความ consistency ของข้อมูลจะเกิดขึ้นมา ซึ่งก็จะ มีรูปแบบการจัดการหลายรูปแบบ เช่น <br>SAGA หรือ Command Query Responsibility Segregation (CQRS)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/0*zhyIIQ98E-LuqsZa.png" /></figure><h4>4. กำหนดวิธีการติดต่อระหว่าง service ให้เรียบร้อย</h4><p>เราจะต้องมาคำนึงถึงว่า Service จะติดต่อกับได้อย่างไร เช่นเราต้องกำหนด API ให้ชัดเจน และเลือกวิธีการพูดคุยกันให้เหมาะสม ให้ใช้งานได้ง่าย เช่นการใช้ HTTP/RESTful หรือ เป็น Asynchronous communication เช่น AMQP โดยทั้งหมดก็ควรที่จะเลือกเป็น protocol มากกว่า อยาก</p><h4>5. สิ่งอื่นๆที่ควรจะต้องคำนึงถึง</h4><p>การที่เราจะทำระบบขึ้นมาได้ services จะต้องมาอยู่รวมๆกัน เราจึงต้องคำถึงการจัดการระบบต่างๆ</p><ul><li><strong>Service replication </strong>การทำซ้ำของ service เพื่อให้ง่ายต่อการ scale</li><li><strong>Service registration and discovery </strong>เป็นกลไกที่จะค้นหา service ต่างๆในระบบว่ามีอะไรบ้าง แล้วยังสามารถติดต่อใช้งานได้รึเปล่า ซึ่งก็จะมีหลากหลายรูปแบบในตัวมันเองอีก เช่น Client-side discovery หรือ Server-side discovery</li><li><strong>Resiliency</strong> กลไกที่จะมาป้องกันความผิดพลาดของระบบเช่น Circuit Breaker หรือ Bulkheads</li></ul><p>Circuit Breaker จะทำหน้าที่เหมือนตัวกลางที่บอก ถ้า connection นั้นมีปัญหาไม่สามารถติดต่อได้ ก็จะเป็นตัวส่งกลับไปให้คนที่ request ทันที</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/638/0*xteNoBHp-v7Llc5d" /><figcaption>Circuit Breaker</figcaption></figure><p>ฺฺBulkheads เป็นการ connection pool ออกจากกันเพื่อให้เวลาเกิดปัญหาในการเชื่อมต่อ ส่งผลกระทบให้กับ microservice ในจำนวนน้อยที่สุด</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*iHBLis3fV5w58KRq.png" /><figcaption>ฺulkheads</figcaption></figure><ul><li><strong>Service monitoring and logging</strong> เป็นเหมือนตัวกลางที่จะมาช่วยเก็บข้อมูลต่างๆที่เกิดขึ้นในแต่ละ service</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*YZBCB2fD-2GAwwFx.png" /><figcaption><a href="https://www.ibm.com/cloud/blog/monitoring-java-microservices-with-microprofile-opentracing">https://www.ibm.com/cloud/blog/monitoring-java-microservices-with-microprofile-opentracing</a></figcaption></figure><ul><li><strong>API gateway</strong> เป็นกลไกที่อยู่ตรงการจัดการระหว่าง user และ service ต่างๆ</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/789/0*M0p3KrnSSrxFU2t4.png" /><figcaption><a href="https://www.express-gateway.io/eg-vs-amazon-aws-api-gateway/">https://www.express-gateway.io/eg-vs-amazon-aws-api-gateway/</a></figcaption></figure><h4>6. ขั้นตอนการพัฒนา</h4><p>ในแต่ละ service ตามที่เราออกแบบให้แยกออกจากกัน ซึ่งทำให้สามารถแบ่งทีมพัฒนาให้เล็กลง โดยสามารถ พัฒนา ทดสอบ และ นำไปใช้ได้ อย่างรวดเร็วมากขึ้น เพิ่มประสิทธิภาพจากการทำงานร่วมกันในทีมที่ขนาดไม่ใหญ่มาก</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/975/0*AEEOsafc66Nwtf8B.png" /></figure><p>ดังนั้นเราก็จะต้องมาดูว่าแต่ละ service จะต้องใช้ เทคโนโลยีอะไรมาพัฒนาดี แล้วนักพัฒนาที่เราจะจัดการทำอย่างไรดี</p><p>ในตัว microservice จะมีความซับซ้อนมากกว่าตัวแอปพลิเคชั่นธรรมดาอยู่มาก ดังนั้นจึงต้องมีทีมมาช่วยจัดการคือทีม Operation ซึ่งจะมาช่วยทีม Developer ซึ่งในการทำงานต่างๆ หรือเราเรียกว่า DevOps</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qwPWg3ZeqTpwVfTQ.png" /><figcaption>DevOPs</figcaption></figure><p>DevOps ก็คือ แนวทางการปฎิบัติการทำงานตั้งแต่เก็บ requirement ไปจนถึงการส่งมอบงานบน production ซึ่งจะเพิ่มประสิทธิภาพในการพัฒนา software ให้ดีมากขึ้นด้วยแนวทางการทำงานแบบใหม่ ที่รวดเร็ว และมีความ Lean</p><p>เมื่อมี DevOps สิ่งที่ตามมาก็คือ CI/CD หรือ Continuous Integration / Continuous Delivery เป็นขั้นตอนที่เราจะนำเครื่องมือต่างๆมาช่วยพัฒนา ทดสอบ ส่งมอบ application ของเราให้มีความรวดเร็ว และควรที่จะเป็นขั้นตอนอัตโนมัติ</p><p>โดยก็จะส่งให้ผู้ใช้งานได้ลองทดสอบใช้งาน และได้ติดตามแก้ไขปัญหา และ ถ้ามีข้อผิดพลาดเราก็สามารถย้อนกลับไปได้อย่างรวดเร็ว และก็จะเป็นตัวช่วย Automation Testing และ Deployment ซึ่งก็จะมีความเกี่ยวข้องไปกับ การทำงานของ Agile ด้วยหละ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/570/0*4vsC2uIoim5IEirQ.png" /><figcaption><a href="http://www.somkiat.cc/devops-in-practice/">http://www.somkiat.cc/devops-in-practice/</a></figcaption></figure><p>ซึ่งมันก็จะมี Tools ในการช่วยทำ CI/CD เยอะแยะมากมายตัวอย่างเช่น Jenkins หรือพวก public cloud อย่าง AWS, Azure, Google Clound platform</p><p><strong>การทดสอบ</strong></p><p>ในเรื่องของการ Automation Testing ก็จะมี Pyramid Testing ตามรูปด้านล่างก็จะทำการอธิบายการทดสอบที่มีหลากหลายรูปแบบ จะมีวิธีการทดสอบที่แตกต่างกันไปขึ้นอยู่กับความต้องการของเรา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*D5ezxZOE5pTSUmgk.png" /></figure><p><strong>การส่งมอบ</strong> <br>หลังจากที่เรามีการพัฒนา ทดสอบ แล้วการส่งมอบก็เป็นขั้นตอนที่สำคัญ ยิ่งถ้าระบบของเรามีจำนวนคนใช้ที่เยอะ แล้วถ้าเรา deploy อะไรขึ้น production แล้วเกิดปัญหาขึ้นจะทำอย่างไรกันดีหละ? ซึ่ง DevOps ก็มีวิธีที่จะช่วยเรา deploy ไม่ต้องเสี่ยงมากตามขั้นตอนของ Continuous Delivery</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/667/0*PdFloSvPPgFuP5cR.png" /></figure><p>ซึ่งในการส่งมอบก็จะมีอยู่หลากหลายแบบในที่นี้ก็ยกมาอยู่ 2 ประเภทใหญ่ๆคือ</p><p><strong>1. Blue-Green deployment</strong></p><p>หลักการก็คือ เราจะนำของใหม่เพิ่มจากของเดิม ตัวอย่างดังรูปเราจะมี Code Version 1 ซึ่งเป็นตัวเก่า และ Code Version 2 ซึ่งเป็นตัวใหม่ที่เราต้องการ update ซึ่งเมื่อเราทำเสร็จเรียบร้อยก็ให้ตัว Load Balancer นำ User Traffic ไปที่ยัง Code Version 2 ก็เป็นอันเรียบร้อย ซึ่งถ้าระบบใหม่เกิดปัญหาขึ้น เราก็จะสามารถย้อนกลับไปใช้ Code Version 1 ได้อย่างสะดวกรวดเร็ว</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/1*trCFJ9M8gz81BVeXp-oTJA.png" /><figcaption><a href="https://learningactors.com/intro-to-deployment-strategies-blue-green-canary-and-more/">https://learningactors.com/intro-to-deployment-strategies-blue-green-canary-and-more/</a></figcaption></figure><p><strong>2. Canary deployment</strong></p><p>ในการทำ Canary deploy จะพัฒนาเพิ่มมาจาก Blue-Green deployment แต่ต้องการลดปัญหาที่อาจจะเกิดขึ้นกับ User ทั้งหมดโดยการ เลือก User บางส่วนและลองให้ใช้กับ feature</p><p>ซึ่งการทำแบบนี้ก็จะดูเหมือน A/B Testing แต่จุดประสงค์จะมีความแตกต่างกันอยู่นะ Canary deploy ต้องการลดความเสี่ยง แต่ A/B Testing ต้องการทดสอบสิ่งใหม่และนำ feedback กลับไปพัฒนาต่อ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*Rt3MG2-MHArTJSu7.png" /></figure><p>สิ่งที่กล่าวมาก็เป็นการแนะนำเบื้องต้นในการออกแบบระบบ microservice ว่ามันเกี่ยวข้องอย่างไรบ้าง อย่างที่ผมกล่าวไปข้างต้น คิดว่า สิ่งที่ยากคือการออกแบบให้ดี ถ้าเราออกแบบไว้เรียบร้อยหมดแล้ว ขั้นตอนในการพัฒนา ทดสอบ และส่งมอบงานก็จะไม่ยากเกินความสามารถ</p><p>ถ้ามีข้อมูล มุมมอง ที่ผิดพลาดประการใด แนะนำ แลกเปลี่ยนความรู้ พูดคุยกันได้นะครับ ผมอาจจะไม่มีประสบการณ์ในเรื่องนี้มากเท่าไหร่ กำลังค่อยๆศึกษาไป ขอบคุณมากครับ</p><p>แหล่งอ้างอิง</p><ul><li><a href="https://siamchamnankit.co.th/%E0%B8%AA%E0%B8%A3%E0%B8%B8%E0%B8%9B-microservice-vs-monolith-architecture-%E0%B8%88%E0%B8%B2%E0%B8%81-alex-barashkov-08-12-2018-c84d996d062">สรุป Microservice vs. Monolith Architecture จาก Alex Barashkov–08/12/2018</a></li><li><a href="https://medium.com/platform-engineer/microservices-design-guide-eca0b799a7e8">Microservices Design Guide</a></li><li><a href="http://www.somkiat.cc/microservices-journey/">บันทึกการเดินทาง Microservices Journey</a></li><li><a href="https://dzone.com/articles/design-patterns-for-micro-service-architecture">Design Patterns for Microservice Architecture - DZone Microservices</a></li><li><a href="https://microservices.io/patterns/microservices.html">Microservices Pattern: Microservice Architecture pattern</a></li><li><a href="https://en.ppt-online.org/577559">Microservices - DDD = Micromonolith - online presentation</a></li></ul><p><a href="https://www.nginx.com/blog/building-microservices-inter-process-communication/">https://www.nginx.com/blog/building-microservices-inter-process-communication/</a></p><p><a href="https://www.xenonstack.com/blog/microservices-testing/">https://www.xenonstack.com/blog/microservices-testing/</a></p><p><a href="https://www.gocd.org/2018/05/08/continuous-delivery-microservices-test-strategy.html">https://www.gocd.org/2018/05/08/continuous-delivery-microservices-test-strategy.html</a></p><p><a href="https://medium.com/platform-engineer/microservices-design-guide-eca0b799a7e8">https://medium.com/platform-engineer/microservices-design-guide-eca0b799a7e8</a></p><p><a href="https://www.nginx.com/blog/introduction-to-microservices/">https://www.nginx.com/blog/introduction-to-microservices/</a></p><p><a href="https://dzone.com/articles/streamlined-microservice-design-in-practice">https://dzone.com/articles/streamlined-microservice-design-in-practice</a></p><p><a href="https://medium.com/@nathankpeck/microservice-principles-decentralized-data-management-4adaceea173f">https://medium.com/@nathankpeck/microservice-principles-decentralized-data-management-4adaceea173f</a></p><p><a href="https://www.martinfowler.com/tags/domain%20driven%20design.html">https://www.martinfowler.com/tags/domain%20driven%20design.html</a></p><p><a href="https://learningactors.com/intro-to-deployment-strategies-blue-green-canary-and-more/">https://learningactors.com/intro-to-deployment-strategies-blue-green-canary-and-more/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e35ad35fb22b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เฟซบุ๊ก เหมือนแอบฟังเราอยู่ใช่ไหม? เรามาจัดการกันดีกว่าด้วยการตั้งค่า Off-Facebook Activity]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B9%80%E0%B8%9F%E0%B8%8B%E0%B8%9A%E0%B8%B8%E0%B9%8A%E0%B8%81-%E0%B9%80%E0%B8%AB%E0%B8%A1%E0%B8%B7%E0%B8%AD%E0%B8%99%E0%B9%81%E0%B8%AD%E0%B8%9A%E0%B8%9F%E0%B8%B1%E0%B8%87%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%AD%E0%B8%A2%E0%B8%B9%E0%B9%88%E0%B9%83%E0%B8%8A%E0%B9%88%E0%B9%84%E0%B8%AB%E0%B8%A1-%E0%B9%80%E0%B8%A3%E0%B8%B2%E0%B8%A1%E0%B8%B2%E0%B8%88%E0%B8%B1%E0%B8%94%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%81%E0%B8%B1%E0%B8%99%E0%B8%94%E0%B8%B5%E0%B8%81%E0%B8%A7%E0%B9%88%E0%B8%B2%E0%B8%94%E0%B9%89%E0%B8%A7%E0%B8%A2%E0%B8%81%E0%B8%B2%E0%B8%A3%E0%B8%95%E0%B8%B1%E0%B9%89%E0%B8%87%E0%B8%84%E0%B9%88%E0%B8%B2-off-facebook-activity-ae0bf2a0d427?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/ae0bf2a0d427</guid>
            <category><![CDATA[off-facebook-activity]]></category>
            <category><![CDATA[data-privacy]]></category>
            <category><![CDATA[facebook]]></category>
            <category><![CDATA[เฟซบุ๊ก]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Sun, 02 Feb 2020 15:15:05 GMT</pubDate>
            <atom:updated>2020-02-02T15:16:43.933Z</atom:updated>
            <content:encoded><![CDATA[<p>เคยไหม? เวลาที่เราพูดอะไรกับเพื่อน หรือ แค่เราไปค้นหาสิ่งต่างๆ ในช่องทางอื่นๆ โฆษณา จะมาแสดงผลอยู่หน้า News Feed เราอยากรวดเร็ว อย่างเช่น ผมต้องการมอองหา คอมพิวเตอร์เครื่องใหม่ หลังจากนั้นไม่นาน ก็มีโฆษณาโผล่มายั่วยวน ให้เราสนใจและเสียตังกันอยู่เสมอๆเลย</p><p>จากวันที่ 28 มกราคมของทุกๆปี จะเป็นวันของ Data Privacy Day หรือ วันคุ้มครองข้อมูล เพื่อจะสร้างและส่งเสริมให้เรารักษาข้อมูลส่วนบุคคล</p><p>ในปีนี้ Facebook ก็ได้เปิดใช้งานฟีเจอร์ที่มีชื่อว่า Off-Facebook Activity เป็นที่เรียบร้อย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ef-P-zot3SYuGWdWwG5rTA.png" /></figure><h4>อะไรคือ Off-Facebook Activity?</h4><p>อยากที่ทุกคนทราบกันดีว่า เวลาเราไปค้นหาอะไรบางอย่างแล้วจะพบกับโฆษณามากมายมหาศาล บน feed ของเรา มันเกิดมาจากการที่เว็บไซต์ที่เราได้ไปทำการดู ทำการค้นหา จะส่งข้อมูลมาให้เฟซบุ๊ก ทำให้มันก็เอาข้อมูลที่ส่งมา มาประมวลผลแล้วก็ยิงโฆษณามาให้เราไงหละ</p><p>โดยที่เฟซบุ๊ก ก็บอกเอาไว้ว่า</p><p>เราสามารทราบได้นะว่า ข้อมูลที่รับมา รับมาจากที่ไหนบ้าง และมีในรูปแบบไหนบ้างหลังจากนั้น ก็สามารถทำสรุปข้อมูลต่างๆ มาก็ไว้ในรูปแบบไฟล์ HTML หรือ JSON ได้ และเราก็สามารถควบคุมลบข้อมูลเหล่านั้นออกไปได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*EC5dl09v5O0jrVTc8FPt4w.png" /><figcaption><a href="https://www.facebook.com/off-facebook-activity">https://www.facebook.com/off-facebook-activity</a></figcaption></figure><h3>วิธีการใช้งาน Off-Facebook Activity</h3><p>เราสามารถเข้าไปตั้งค่าได้จากหลายช่องทาง</p><ol><li>สามารถเข้าไปที่ <a href="https://www.facebook.com/off_facebook_activity">https://www.facebook.com/off_facebook_activity</a> <br>หรือ</li></ol><ul><li>สามารถคลิกได้ที่ ด้านบนขวา เลือกเข้าไปที่หน้า Settings</li><li>แท็ปด้านจะมีตัวเลือก Your Facebook Information</li><li>เลือก View ที่ Off-Facebook Activity</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*AxYMvwa0f_bSKM0yBF2F9Q.jpeg" /></figure><p>2. ผ่านทางแอปพลิเคชั่นโทรศัพท์มือถือ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eiBNiIm9vT2oFgw2dD6mCQ.jpeg" /></figure><p>หลังจากนั้นก็จะพบกับหน้าต่างที่อธิบายฟีเจอร์เราสามารถกดไปที่ Manage Your Off-Facebook Activity ซึ่งหลังจากที่ผมกดเข้าไปแล้ว โอโห!!!!! มีตั้ง 700 แอปที่ส่งข้อมูลเรามาให้เฟสบุคเลย เยอะสุดๆๆ เราก็สามารถกดเข้าไป แล้วมันก็จะแสดงข้อมูลต่างๆอย่างเช่น มีรับข้อมูลมาได้เท่าไหร่</p><p>สำหรับคนที่ไม่อยากเก็บข้อมูลสามารถกด Clear History ได้เลยครับ แต่หลังจากที่เราลบข้อมูลไป โฆษณาก็ยังคงมีอยู่นะ ไม่ใช่หายไปเลย แต่ว่าโฆษณาจะไม่ค่อยตรงมากในช่วงแรกๆ มันก็เหมือนยังไม่รู้จักเรามากแต่เมื่อเราใช้ไปได้สักพักหนึ่ง ผมคิดว่าน่าจะกลับมาเป็นเหมือนเดิม</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*NXJkaq0R3wkz-c0c7BUl1w.jpeg" /></figure><p>ผมเขียนบทความนี้ขึ้นมาอยากให้ทุกคนๆได้ลองเข้าไปจัดการ ส่วนตัวของเรามากขึ้นและหันมาให้ความสำคัญกับข้อมูลส่วนตัว</p><p>ซึ่งผมก็ยังไม่ได้ไปเครีย History หรอกนะครับ อยากให้มันแนะนำ ( ป้ายยา ) สิ่งของที่เราต้องการให้อยากได้ขึ้นไปอีก เอ้ะ นี่มันจะช่วยให้ดีขึ้นจริงๆรึเปล่าเนี่ย แต่ผมได้ลอง ขอ Activity Details มีขนาด 10GB+ ใหญ่พอสมควรเลยหละ ได้มาเป็นไฟล์สกุล HTML เดี๋ยวถ้าว่างๆจะกลับมาลองนั้งดูกันว่าจะมีอะไรในนั้นบ้าง</p><p>ขอบคุณสำหรับอ่านบทความนี้ของผมนะครับ :)</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ae0bf2a0d427" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Microservices]]></title>
            <link>https://medium.com/@takdanai.3473/microservices-369bd165728c?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/369bd165728c</guid>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[microservices]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Fri, 31 Jan 2020 01:40:44 GMT</pubDate>
            <atom:updated>2020-01-31T01:40:44.758Z</atom:updated>
            <content:encoded><![CDATA[<h3>What is Microservices</h3><p>Microservices or microservice architecture is an approach to develop an application. that developing a single application into services, each running in its process. These services organized around business capabilities and independently deployable.</p><p><strong>Components of microservices architecture:</strong><br> The services are independent, small, and loosely coupled<br> Organized around business capabilities<br>Services can use a different programming language.<br>Services can manage by a small team and independently deployable<br>Well-defined communication interface</p><p><strong>What is Monolithic Architecture?<br></strong>The monolithic application comes with a single application that can do everything. Inside Monolithic applications have many modules inside.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Z2mbJTZG2_TJPsah.jpg" /><figcaption>Monolithic architecture vs Microservices Architecture</figcaption></figure><p>Monolithic vs Microservices</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*LIkNg2uhPERzoVy60kWecg.png" /></figure><h4>Why a Microservice Architecture is important?</h4><ol><li><strong>Continuous delivery</strong><br>Microservices can provide continuous delivery. The company will get benefits from using DevOps operation to accelerates development and deployment.</li><li><strong>Independent services</strong><br>Microservices design and deploy in small pieces. Each application can be edited without affecting other services.</li><li><strong>Develop faster</strong><br>Microservice can break the barriers of technology tools by using different development tools for each component. A developer can select the programming language best for each function. When developing a new service you can pick a new technology stack. Similarly, when making major changes to an existing service you can rewrite it using a new technology stack.</li></ol><h3>Benefits of Microservices Architecture</h3><ol><li><strong>Delivery and Deployment</strong><br>Easy to manage by using continuous delivery and deployment.</li><li><strong>Technology Independent</strong> <br>A developer can use different technology</li><li><strong>Availability &amp; Reliability</strong><br>If one service failed another service still run. More reliability</li><li><strong>Scalability</strong><br>Easy to scale to support more user and it can scale small services</li><li><strong>Organize a small team</strong><br>Using small Team to develop</li><li><strong>Readable code</strong><br>Easier to understand</li></ol><h3>The drawback of Microservices Architecture</h3><ol><li><strong>A complex and distributed system</strong><br>Developers must deal with the additional complexity of creating a distributed system. Deployment complexity. In production, there is also the operational complexity of deploying and managing a system comprised of many different service types.</li><li><strong>Communication</strong><br>Developers must implement the inter-service communication mechanism.</li><li><strong>Infrastructure Automation</strong><br>Microservices need to using continuous deployment &amp; delivery. It is more difficult as compared to Monolith applications.</li><li><strong>Increased memory consumption</strong><br>The size of the application can slow down start-up time and When you increased to service the overhead of each service will occur.</li><li><strong>Data Consistency</strong><br>Data consistency is harder to maintain when integrated database.</li></ol><h3>A pattern language for microservices</h3><p>Microservices deal with a lot of things. The beginnings of a pattern language for microservices architectures.</p><p>We can design the microservices system according to the picture below. This picture represents an overview of microservices. It can separate into 3 main parts: Application Patterns, Application Infrastructure Patterns, and Infrastructure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rLsZu4sc44fuNgvJ.jpg" /><figcaption><a href="https://microservices.io/patterns/index.html">https://microservices.io/patterns/index.html</a></figcaption></figure><p>In Conclusion, both have many advantages and disadvantages. Both architectures are an approach to develop an application. We mush consider which one will have more benefit to solve your problem.</p><p><strong>Reference:</strong><br><a href="https://appinventiv.com/blog/microservices-vs-monolithic-architecture/">https://appinventiv.com/blog/microservices-vs-monolithic-architecture</a><br> <a href="http://martinfowler.com/microservices">http://martinfowler.com/microservices</a><br><a href="https://www.techtalkthai.com/introduction-to-microservices-architecture/">https://www.techtalkthai.com/introduction-to-microservices-architecture/</a><br><a href="https://shadow-soft.com/why-microservice-architecture/">https://shadow-soft.com/why-microservice-architecture/</a><br><a href="https://santhoshravirala.com/monolithic-vs-microservices/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=monolithic-vs-microservices">https://santhoshravirala.com/monolithic-vs-microservices/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=monolithic-vs-microservices</a><br><a href="https://microservices.io/patterns/index.html">https://microservices.io/patterns/index.html</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=369bd165728c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เขียนแอปพลิเคชั่น สำหรับ Register/Login โดยใช้ Ionic + NodeJS [Part3/3]]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%81%E0%B8%AD%E0%B8%9B%E0%B8%9E%E0%B8%A5%E0%B8%B4%E0%B9%80%E0%B8%84%E0%B8%8A%E0%B8%B1%E0%B9%88%E0%B8%99-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-register-login-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-ionic-nodejs-part3-3-84c074afc44?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/84c074afc44</guid>
            <category><![CDATA[cross-platform]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ionic]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Thu, 31 Oct 2019 16:16:08 GMT</pubDate>
            <atom:updated>2019-10-31T16:16:08.685Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 3 รวมร่าง</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/435/0*OP2_iIUSX-Jx9lmt.gif" /></figure><p>ในบทความนี้ก็จะเป็นการรวมในส่วนของ Front end + Back end เข้าด้วยกัน <br>ถ้าใครที่โผล่มาบทความนี้เลย ลองกลับไปอ่านบทความย้อนหลังก่อนได้นะ <br>ส่วนของ Front end อยู่ใน Part 1<br>Link: <a href="https://medium.com/@takdanai.3473/cbb6d1c94086">https://medium.com/@takdanai.3473/cbb6d1c94086</a><br>ส่วนของ Back end อยู่ใน Part 2<br>Link: <a href="https://medium.com/@takdanai.3473/e59cd3ccf8d7">https://medium.com/@takdanai.3473/e59cd3ccf8d7</a></p><p>หลังจากที่เราทำเรียบร้อยแล้วเรามาเช็คว่าเราได้ เปิด Service การทำงานเรียบร้อยแล้วหรือยัง สิ่งที่ต้องเปิดคือ service ของ ionic และ nodejs server ของเรานั้นเอง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nEQMBGvjGuxbnraDC6drRQ.png" /></figure><p>ต่อไปให้เราไปเช็คใน <strong>auth.service.ts ที่อยู่ใน folder src/app/services/auth.service.ts <br>เพื่อแก้ไข Authentication Server Address ให้ตรงกับ Ip เครื่องของเราหรือ เครื่องอื่นๆ ที่เราได้เปิด Service ไว้ ไม่งั้นเวลา login มันจะเชื่อมต่อไม่ได้ ซึ่งในการทำ ให้ลองดู log ใน developer tools กันนะ มันจะช่วยได้มากๆเลย</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1007/1*IttFsZh4F5eU0PtTkSG4iQ.png" /></figure><p>เมื่อเราเตรียมเสร็จแล้วก็มาลองสร้าง Account และ Login กันดีกว่า</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouPbSDnDhY8zEsq8hNkIGw.gif" /></figure><p>จากที่เห็น register user ใหม่เข้าไป ระบบทำการ login เข้าไป ฝั่ง server จะทำการ บันทึกข้อมูลเข้าไปยังฐานข้อมูล และออกสิทธิการใช้งานแอปพลิเคชั่นต่อไป หลังจากนั้นเราก็จะสามารถไปพัฒนาแอปพลิเคชั่นต่างๆ ต่อได้เลย</p><p>จากทั้งหมดที่ผมได้เขียนมาเพราะว่าผมต้องการที่จะทำแอปพลิเคชั่น แล้วผมก็ได้ไปค้นหาจากหลายๆที่ แล้วในแต่ละที่มันจะมีส่วนที่ตรงใจ ไม่ตรงใจ ก็เลยนำหลายๆส่วนนั้นมารวมเข้าด้วยกัน ก็คิดว่าน่าจะเป็นประโยชน์ไม่มากก็มากๆนะจ้าาาา</p><p>ขอบคุณผู้อ่านทุกๆท่าน สำหรับที่อ่านบทความของผมมาจนจบเลย</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=84c074afc44" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เขียนแอปพลิเคชั่น สำหรับ Register/Login โดยใช้ Ionic + NodeJS [Part2/3]]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%81%E0%B8%AD%E0%B8%9B%E0%B8%9E%E0%B8%A5%E0%B8%B4%E0%B9%80%E0%B8%84%E0%B8%8A%E0%B8%B1%E0%B9%88%E0%B8%99-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-register-login-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-ionic-nodejs-part2-3-e59cd3ccf8d7?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/e59cd3ccf8d7</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ionic]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cross-platform]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Wed, 30 Oct 2019 15:56:09 GMT</pubDate>
            <atom:updated>2019-10-30T15:56:09.583Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 2 ใช้ Express Node Js สำหรับติดต่อ แอปพลิเคชั่นกับฐานข้อมูล ( Back End )</h4><p>หลังจากเราได้เขียนแอปพลิเคชั่นผู้ใช้กันไปแล้ว เราก็จะต้องมาเขียนในส่วนของฝั่งเซิฟเวอร์กันบ้างแล้ว</p><p>โดยหลักๆ จะเป็นการใช้ web application framework ที่เป็น library ของตัว Nodejs ซึ่งก็เป็นแพลตฟอร์มที่เหมาะสำหรับการมาใช้ในส่วนของหลังบ้านอยู่แล้ว การเขียนอันนี้ก็ควรจะที่จะรู้ REST API สักนิดนึง ถ้าใครไม่เคยได้ยินลองไปหาข้อมูลกันก่อนได้เลยหละ</p><p>จากที่กล่าวไปข้างต้นว่าในบทความนี้จะเลือกใช้ SQLite เพราะว่ามันสะดวก มาก และเราก็สามารถนำไปใช้ต่อใน SQL Database ได้อีกด้วย ( ถ้าจะใช้กับ NoSQL ก็ต้องมาแก้กันนิดๆหน่อย ) ตัว SQLite เนี่ยมันจะได้ออกมาเป็นไฟล์ก้อนนึง เราสามารถใช้โปรแกรมเปิดไฟล์นั้นออกมาได้ ก็จะเหมือน SQL Database เลยหละ</p><h3>มาเริ่มต้นกันเลย Let’s Go!!!</h3><ol><li>เปิด Command line / Terminal เพื่อสร้าง Folder สำหรับ code ของ Server <br>โดยชื่อที่เราสร้างในวันนี้คือ express-auth-demo</li></ol><pre>mkdir express-auth-demo</pre><p>2. เข้าไปใน folder ที่เราได้สร้างไว้</p><pre>cd express-auth-demo</pre><p>3. สร้าง package.json file และเมื่อสร้างเสร็จแล้วเราก็เข้าไปแก้ไขไฟล์ package.json ไปเพิ่มในส่วนของ scripts เพิ่ม “start” : “node index.js” เข้าไป</p><pre>npm init -y</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/547/1*-zh0HfR5QhxAS23EWiMgag.png" /></figure><pre>&quot;scripts&quot;: {<br>    &quot;start&quot;: &quot;node index.js&quot;<br>},</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GCJ0-LtIrOWzYwM7PXtTcg.png" /><figcaption>package.json</figcaption></figure><p>4. ใช้คำสั่งรันใน Terminal เพื่อทำการติดตั้ง library ที่จำเป็นต้องใช้</p><pre>npm install --save express body-parser sqlite3 bcryptjs jsonwebtoken cors</pre><p>5. สร้างไฟล์ <strong>index.js</strong> และ copy code ที่ให้ไป</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a86fc54496d09c0a2646b0490c8b7f72/href">https://medium.com/media/a86fc54496d09c0a2646b0490c8b7f72/href</a></iframe><p>6. ใช้คำสั่ง เพื่อ เปิดใช้งาน server</p><pre>npm start</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/687/1*UybBElp0PcFA93ZBgZUvTg.png" /></figure><p>ถึงขั้นตอนนี้ส่วนของ Backend เราก็พร้อมแล้ว ไปต่อกันในบทต่อไปกันได้เลย</p><p><a href="https://medium.com/p/84c074afc44">https://medium.com/p/84c074afc44</a></p><h3>Reference:</h3><blockquote>This article follows <a href="https://www.techiediaries.com/ionic-jwt-authentication-httpclient/">https://www.techiediaries.com/ionic-jwt-authentication-httpclient/</a><br>Ionic 4 JWT Authentication Tutorial: Using Angular HttpClient with Node &amp; Express.js Server<br>Change file:<strong> index.js</strong> to work with my ionic application.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e59cd3ccf8d7" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[เขียนแอปพลิเคชั่น สำหรับ Register/Login โดยใช้ Ionic + NodeJS[Part1/3]]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B9%80%E0%B8%82%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%81%E0%B8%AD%E0%B8%9B%E0%B8%9E%E0%B8%A5%E0%B8%B4%E0%B9%80%E0%B8%84%E0%B8%8A%E0%B8%B1%E0%B9%88%E0%B8%99-%E0%B8%AA%E0%B8%B3%E0%B8%AB%E0%B8%A3%E0%B8%B1%E0%B8%9A-register-login-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B9%83%E0%B8%8A%E0%B9%89-ionic-nodejs-part1-3-cbb6d1c94086?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/cbb6d1c94086</guid>
            <category><![CDATA[cross-platform]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[ionic]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Wed, 30 Oct 2019 15:56:02 GMT</pubDate>
            <atom:updated>2019-10-30T15:56:02.833Z</atom:updated>
            <content:encoded><![CDATA[<h4>Part 1: เขียนแอปพลิเคชั่นโดยใช้ Ionic Framework ( Front End )</h4><p>Ionic CLI : <a href="https://ionicframework.com/docs/cli">https://ionicframework.com/docs/cli</a></p><p>เราจะใช้คำสั่ง Ionic CLI เพื่อทำการ สร้าง project ใหม่ขึ้นมา <br>ใน ionic เนี่ยก็จะมี template ให้เราเลือกได้หลากหลายเลย แต่ในบทความนี้จะเลือกใช้ tabs กันนะครับ</p><p>Step:</p><ol><li>สร้าง Project ใหม่และติดตั้ง library</li><li>สร้าง Page และ Service ต่างๆที่จำเป็นในการใช้งาน</li><li>แก้ไขไฟล์ พวก app component และ service ต่างๆ</li><li>จัดการในส่วนของ routing / tab module</li><li>จัดการหน้า Page ต่างๆ</li></ol><h3>1. สร้างProject ใหม่และติดตั้ง library</h3><p>คำสั่ง<br>- application จะหมายถึงชื่อ Project ของเรา<br>- tabs เป็น Application ตัวอย่างของทาง ionic framework</p><pre>ionic start application tabs --type=angular</pre><p>เราก็เข้าไปใน folder ที่เราสร้างขึ้นมา</p><pre>cd application/</pre><p>ติดตั้ง Library / <a href="https://ionicframework.com/docs/building/storage">ionic Storage</a></p><pre>ionic cordova plugin add cordova-sqlite-storage<br>npm install --save @ionic/storage</pre><pre>ionic cordova plugin add cordova-plugin-nativestorage<br>npm install @ionic-native/native-storage</pre><p>หลังจากที่เราเตรียมกันเสร็จเรียบร้อยแล้ว</p><h3>2. สร้าง Page และ Service ต่างๆ</h3><p>ก็มาสร้างหน้าเว็ปที่จะใช้งานกันก่อนโดยเราจะใช้คำสั่ง command line ในการสร้าง เพราะคำสั่งจะช่วยให้เราสร้างหน้าได้สะดวกขึ้นมากๆ<br>แบ่งออกเป็น <br>Landing Page<br>Authentication Page: Login / Register <br>App -&gt; Homepage, Dashboard, Profile Page</p><pre>ionic generate page pages/landing<br>ionic generate page pages/auth/login<br>ionic generate page pages/auth/register<br>ionic generate page pages/homepage<br>ionic generate page pages/dashboard<br>ionic generate page pages/profile</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/331/1*M_5F96u1KL2TsEHrYVIJ8Q.png" /><figcaption>Pages</figcaption></figure><p>ตามด้วยการสร้าง service ที่เราจะเรียกใช้กันนะครับ</p><pre>ionic generate service services/auth<br>ionic generate service services/alert<br>ionic generate service services/env<br>ionic generate guard guard/auth</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/320/1*BPqebbZmBxTBbM_EXwssAg.png" /><figcaption>Services</figcaption></figure><p>ซึ่งในของ Ionic ( Angular ) ก็จะแบ่งเป็น 3 ไฟล์หลัก ใน 1 หน้าคือ HTML + TypeScipt + CSS นะครับ สำหรับใครที่ยังไม่เข้าใจในส่วนนี้ต้องลองไปศึกษาเพิ่มเติมกันดูก่อนนะ เดี๋ยวมันงงๆๆ</p><h3>3. แก้ไขไฟล์ พวก app component และ service ต่างๆ</h3><h4>App Component</h4><h4>3.1 ไฟล์ app.module.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/49d45092b2145c747f35d1a77a9c813f/href">https://medium.com/media/49d45092b2145c747f35d1a77a9c813f/href</a></iframe><h4>3.2 ไฟล์ src/app/app.component.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8d5d9c68804c1172b7616406bd696a89/href">https://medium.com/media/8d5d9c68804c1172b7616406bd696a89/href</a></iframe><h4>3.3 ให้เราสร้าง folder ใน src/app/models<br>และสร้างไฟล์ user.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ef0d345cc005e9baebe906cd65b829b/href">https://medium.com/media/3ef0d345cc005e9baebe906cd65b829b/href</a></iframe><h4><strong>Updating Service<br></strong>3.4 ไฟล์ auth.service.ts</h4><p>โดยในตัว authentication service เราจะต้องใส่ authentication server address ลงไป</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/43cb3a825c63edab4dc2ab24541abbc5/href">https://medium.com/media/43cb3a825c63edab4dc2ab24541abbc5/href</a></iframe><h4>3.5 ไฟล์ auth.guard.ts</h4><p>ตัวนี้จะทำหน้าที่ในการจัดการ การเข้าถึงหน้า ของแอปพลิเคชั่น</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2c7895d97658af7121ce1a5935ed90b6/href">https://medium.com/media/2c7895d97658af7121ce1a5935ed90b6/href</a></iframe><h4><strong>Alert Service <br></strong>3.6 ไฟล์ alert.service.ts</h4><p>มาทำตัว alert แจ้งเตือนกัน</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/905f05bd6dd108640d0a35cc37caa08a/href">https://medium.com/media/905f05bd6dd108640d0a35cc37caa08a/href</a></iframe><h4>3.7 ไฟล์ env.service.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/abdb88a86d75abaf7c9686b7206fa845/href">https://medium.com/media/abdb88a86d75abaf7c9686b7206fa845/href</a></iframe><h3>4. จัดการในส่วนของ Routing / Tab module</h3><p>ส่วนแรกเลย เราจะต้องไปปรับแก้ตัว app-routing.module.ts เพื่อมันสามารถ redirect ไปยังหน้า landing เป็นหน้าแรก และ ใส่ AuthGuard เข้าไปในหน้าที่เราต้องการบังคับให้ผู้ใช้งาน เข้าสู่ระบบก่อนที่จะใช้งาน และในกรณีนี้เราใช้ตัว Tabs bar ซึ่งเราก็ต้องเข้าไปแก้ไขในที่นั้นด้วย</p><h4>4.1 app-routing.module.ts</h4><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/323ed5bc842eefb89b7fc9b0baa17f59/href">https://medium.com/media/323ed5bc842eefb89b7fc9b0baa17f59/href</a></iframe><p>ตัว app-routing.module.ts จะเป็นตัวจัดการ นำทางไปยังหน้าต่างๆ ซึ่งจากที่เราได้สร้างตัว auth service มาเพื่อจำกัดสิทธิในการเข้าถึงหน้าต่างๆ <br>ในตัวอย่าง เราต้องการที่จะต้องให้มีการ login เข้าสู่ระบบก่อนที่จะเข้าไปใช้งานในส่วนของ app ดังนั้นเราจึงต้องใส่ service AuthGuard ที่เราสร้างขึ้นมา</p><p>อันนี้คือตัวอย่างก่อนที่เราจะใส่ AuthGuard</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*m8BjfKQ2hmHkUlcPd-5Wnw.gif" /><figcaption>ตัวอย่างของการไม่ใส่ Auth Guard</figcaption></figure><p>เราก็ต้องใส่ ตัว Authguard เข้าไปใน path ที่เราต้องการจำกัดสิทธิ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1001/1*P9FxGPz8ktz7M3urs7RVGw.png" /></figure><p>จากการที่ลองพยายามเข้าโดยที่ยังไม่ได้ทำการ login ก็จะโดน redirect เด้งกลับไปยังหน้าไปยังหน้า landing page</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*atdZ6MT4B-A4dox06Z3L4w.gif" /><figcaption>ตัวอย่างของการใส่ Auth Guard</figcaption></figure><h4>4.2 tabs-routing.module.ts</h4><p>ใน Tabs เราเนี่ยจะมีอยู่ 3 หน้าหลักก็คือ homepage, dashboard, profile ซึ่งเราในที่นี้มันก็จะเป็น route ตัวอย่างเช่น<br>localhost:8100/app/tabs/homepages<br>app มาจาก app-routing-module ที่เราตั้งค่าไว้<br>tabs มาจาก tab-routing-module โดยที่จะมี homepage เป็น category ย่อยๆลงไปอีก</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4d15f8d4e8cbc4c791ce7d11c92c036a/href">https://medium.com/media/4d15f8d4e8cbc4c791ce7d11c92c036a/href</a></iframe><h4>4.3 tabs.pages.html</h4><p>ปรับแต่งหน้าตา Tabs เล็กน้อย โดยเราจะต้องเปลี่ยน tab-button ให้เป็น path ที่เราจะต้องการไป</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ccf8283b3a52a6599dbedc9fee547c30/href">https://medium.com/media/ccf8283b3a52a6599dbedc9fee547c30/href</a></iframe><h3>5. จัดการหน้า Page ต่างๆ</h3><p>หลังจากที่เราได้ทำ เกี่ยวกับ service เรียบร้อยแล้ว เราจะมาทำตัวเกี่ยวกับ หน้าตาของแอปพลิเตชั่นกันต่อ<br>ในส่วนหลักๆของเราก็จะต้องแก้ไข ไฟล์ HTML และ ไฟล์ TypeScript เพื่อเป็นการที่เชื่อมหน้าตาแอปพลิเคชั่นของเรากับตัวฟังก์ชั่นต่างๆ ก็เหมือนของคู่กันนั้นแหละนะ ฝั่ง CSS ผมขอยังไม่ไปพูดถึงมันมากเดี๋ยวกลัวจะวุ่นวายมากกว่านี้ ฮ่าๆ</p><h4>5.1 Landing Page</h4><p>ไฟล์ landing.page.html<strong><br></strong>หน้านี้จะเป็นหน้าแรกของแอปพลิเคชั่นของเรา ซึ่งเราจะมีปุ่ม login/register อยู่บริเวณ footer ของเรา</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e709e83ce787baf2ef1e1bf5e6d1342b/href">https://medium.com/media/e709e83ce787baf2ef1e1bf5e6d1342b/href</a></iframe><p>ไฟล์ landing.page.ts<strong><br></strong>ในส่วนนี้ก็จะมีฟังก์ชั่นต่างๆ <br>ionViewWillEnter() ตัวนี้ทำหน้าที่เช็คเกี่ยวกับระบบ authentication ถ้าเราได้ทำการเข้าสู่ระบบเรียบร้อยแล้ว มันจะไปยังหน้า application ของเราได้เลย<br>login() และ register() จะเป็น Function เมื่อมีการกดปุ่ม login/logout ให้แสดง modal นั้นๆขึ้นมา</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9662eb0297e957b08fb53099e4cba6fe/href">https://medium.com/media/9662eb0297e957b08fb53099e4cba6fe/href</a></iframe><p>ไฟล์ landing.module.ts<br>เป็นการเพิ่ม module LoginPage และ Register Page</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/774c069b6464a2216c08ecaa8ea23d1e/href">https://medium.com/media/774c069b6464a2216c08ecaa8ea23d1e/href</a></iframe><h4>5.2 Login Page</h4><p>ไฟล์ login.page.html<br>มาสร้างหน้า login กัน ซึ่งในหน้านี้เราจะทำ form มารับ username &amp; password จากผู้ใช้ที่ใส่เข้ามา</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4e91a049fe5c6e94e34e0600e3e11c43/href">https://medium.com/media/4e91a049fe5c6e94e34e0600e3e11c43/href</a></iframe><p>ไฟล์ login.page.ts<br>ในตัวนี้ก็จะมีการส่งข้อมูลไปยัง AuthService เพื่อทำการ login</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d5b4c2597d02a07aa74c5a83f0ae404b/href">https://medium.com/media/d5b4c2597d02a07aa74c5a83f0ae404b/href</a></iframe><h4>5.3 Register Page</h4><p>ไฟล์ register.page.html<br>มาสร้างหน้า Register กัน ซึ่งในหน้านี้เราจะทำ form มารับ username, password, firstname, and lastname จากผู้ใช้ที่ใส่เข้ามา</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9608142a60df1ad1aa66b9b75baf1dcd/href">https://medium.com/media/9608142a60df1ad1aa66b9b75baf1dcd/href</a></iframe><p>ไฟล์ register.page.ts<br>ในตัวนี้ก็จะมีการส่งข้อมูลไปยัง AuthService เพื่อทำการ register</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8be35cc00e520fa9355aa87655b00d5e/href">https://medium.com/media/8be35cc00e520fa9355aa87655b00d5e/href</a></iframe><h3>ก่อนจะไปกันต่อเรามาลองทดสอบกันก่อน</h3><h4>Running the app</h4><p>เมื่อเราทำเสร็จแล้วมาลองดูกัน โดยเราเปิด terminal แล้ว ไปยัง directory ของ project หลังจากนั้นใช้คำสั่ง ionic serve เพื่อทำการสร้าง service ขึ้นมา</p><pre>ionic serve</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/1*9VZLKmUFiHJQaG9z-vUCgA.png" /></figure><p>เมื่อทำการ run เสร็จเรียบร้อยแล้ว เราก็สามารถเปิด web browser เพื่อเข้าไปยัง URL ของ service ที่สร้างขึ้นมาได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/858/1*e2N11lo0Zsvjfh2SXJCyZA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*6GgLs67qU-yHVPafoBbznA.gif" /></figure><p>หลังจากที่เรา login เข้าไปแล้ว ใน application นี้ จะมีอยู่สามหน้า หลัก คือ<br>homepage<br>dashboard<br>profile</p><h4>5.4 Profile Page</h4><p>ซึ่งในที่นี้ผมจะลองทำให้ หน้า profile ของเรา แสดงชื่อผู้ใช้ และสร้างปุ่ม logout</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/491/1*CkysDeTXXXi1Hy-RB3Xm_Q.png" /></figure><p>ไฟล์ profile.page.html</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2e85e15caeb73eed0888475a0da9471b/href">https://medium.com/media/2e85e15caeb73eed0888475a0da9471b/href</a></iframe><p>ไฟล์ profile.page.ts</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6c09c0995043c54f08c0a999aad41784/href">https://medium.com/media/6c09c0995043c54f08c0a999aad41784/href</a></iframe><p>ในตอนนี้แอปพลิเคชั่นของเราก็ยังจะ login ไม่ได้ เราจะต้องสร้าง authentication server ขึ้นมาก่อน ตัว authentication server จะอยู่ใน part ต่อไป ไปดูกันต่อได้เลย<br><a href="https://medium.com/p/e59cd3ccf8d7">https://medium.com/p/e59cd3ccf8d7</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hXPk_fpfjb5kDRcfgn_c2A.png" /></figure><p>Reference: <br><a href="https://www.techiediaries.com/ionic-ui-forms-theming/">https://www.techiediaries.com/ionic-ui-forms-theming/</a><br><a href="https://blog.flicher.net/ionic-4-user-registration-login-tutorial/">https://blog.flicher.net/ionic-4-user-registration-login-tutorial/</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cbb6d1c94086" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[บทความนี้ผมจะมาสร้างระบบลงทะเบียนและเข้าใช้ระบบ ผ่าน Ionic 4 Framework โดยบทความนี้ จะมีในส่วนของ…]]></title>
            <link>https://medium.com/@takdanai.3473/%E0%B8%9A%E0%B8%97%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%99%E0%B8%B5%E0%B9%89%E0%B8%9C%E0%B8%A1%E0%B8%88%E0%B8%B0%E0%B8%A1%E0%B8%B2%E0%B8%AA%E0%B8%A3%E0%B9%89%E0%B8%B2%E0%B8%87%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A%E0%B8%A5%E0%B8%87%E0%B8%97%E0%B8%B0%E0%B9%80%E0%B8%9A%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B9%81%E0%B8%A5%E0%B8%B0%E0%B9%80%E0%B8%82%E0%B9%89%E0%B8%B2%E0%B9%83%E0%B8%8A%E0%B9%89%E0%B8%A3%E0%B8%B0%E0%B8%9A%E0%B8%9A-%E0%B8%9C%E0%B9%88%E0%B8%B2%E0%B8%99-ionic-4-framework-%E0%B9%82%E0%B8%94%E0%B8%A2%E0%B8%9A%E0%B8%97%E0%B8%84%E0%B8%A7%E0%B8%B2%E0%B8%A1%E0%B8%99%E0%B8%B5%E0%B9%89-%E0%B8%88%E0%B8%B0%E0%B8%A1%E0%B8%B5%E0%B9%83%E0%B8%99%E0%B8%AA%E0%B9%88%E0%B8%A7%E0%B8%99%E0%B8%82%E0%B8%AD%E0%B8%87-d5d769aeb6c6?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/d5d769aeb6c6</guid>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[cross-platform]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[ionic]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Wed, 30 Oct 2019 15:55:29 GMT</pubDate>
            <atom:updated>2019-10-30T15:55:29.559Z</atom:updated>
            <content:encoded><![CDATA[<h3>เขียนแอปทำระบบ Login ใช้ Ionic + NodeJS Server [Introduction]</h3><p>สวัสดีครับ ในบทความนี้ผมจะมาเขียนแอปพลิเคชั่น Crossplatform ในการทำระบบ Login / Register อย่างง่ายๆกัน ผ่าน Ionic Framework</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/352/1*wPZEXrSRd0jXqmcSLLCYLQ.gif" /><figcaption>Application Example</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouPbSDnDhY8zEsq8hNkIGw.gif" /></figure><h3>แอปพลิเคชั่นทำอะไรได้บ้าง</h3><p>1. สร้างผู้ใช้งาน<br>2. เข้าสู่ระบบ<br>3. จำกัดสิทธิการเข้าถึงหน้าต่างๆ <br>4.แสดงชื่อผู้ใช้งานในแอปพลิเคชั่น</p><h3>โดยผมขอแบ่งบทความนี้ออกเป็น 3 ส่วนหลัก</h3><h4>Part 1: เขียนแอปพลิเคชั่นกันเถอะ ( Front End )</h4><p>ในบทความนี้จะเป็นการเขียน application ผ่านการใช้ Ionic framework โดยที่มันจะใช้ตัว Apache Cordova แปลงภาษาที่ใช้ในการเขียนเว็ป ให้กลายเป็นแอปพลิเคชั่นโทรศัพท์ได้เลย ไม่ใช่ web-app เน้อ <br>โดยส่วนนี้ก็จะเยอะที่สุดแล้วหละ ถ้าทำตรงนี้ได้ ส่วนอื่นก็สบายๆแล้ว<br>Link: <a href="https://medium.com/@takdanai.3473/cbb6d1c94086">https://medium.com/@takdanai.3473/cbb6d1c94086</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/880/0*qrcDLgkquZsr7UB3.jpg" /></figure><h4>Part 2: ใช้ Express Node Js สำหรับติดต่อ แอปพลิเคชั่นกับฐานข้อมูล ( Back End )</h4><p>ในบทความนี้จะเป็นการ ทำส่วนของหลังบ้าน โดยใช้ Library ของ Nodejs ที่ชื่อว่า ExpressJS ติดต่อกับส่วน FrontEnd-Application โดยใช้ RESP API<br>ฐานข้อมูลเลือกใช้ SQLite เพราะเราจะได้ไม่ต้องติดตั้งโปรแกรมอะไรมากให้วุ่นวาย ใช้งานได้สะดวก <br>Link: <a href="https://medium.com/@takdanai.3473/e59cd3ccf8d7">https://medium.com/@takdanai.3473/e59cd3ccf8d7</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/0*mc5Hpsx_Nnt_idmt.png" /></figure><h4>Part 3: มารวมแอปพลิเคชั่นกัน เถอะ ( Frond End + Back End )</h4><p>ในส่วนนี้จะเป็นการ นำทั้งสองส่วนที่ได้พัฒนาในก่อนหน้านี้ นำมาลองใช้ดูกัน <br>Link: <a href="https://medium.com/@takdanai.3473/84c074afc44">https://medium.com/@takdanai.3473/84c074afc44</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouPbSDnDhY8zEsq8hNkIGw.gif" /></figure><h3>Prerequisites</h3><h4>Skill:</h4><p>1. พอที่จะเข้าใจโครงสร้าง หรือ เขียน Angular / Ionic มาบ้างแล้ว ถ้าใครมีพื้นฐาน ก็จะเข้าใจได้มากขึ้น</p><h4>Software:</h4><blockquote><strong>NodeJS</strong><br>Install Node.js® is a JavaScript runtime<br><a href="https://nodejs.org/en/">https://nodejs.org/en/</a><br><strong>Ionic Framework </strong><br>Install Ionic Framework<br><a href="https://ionicframework.com/docs/installation/cli">https://ionicframework.com/docs/installation/cli</a></blockquote><blockquote><strong>Optional <br>TablePlus</strong> ( GUI for open SQLite )<br><a href="https://tableplus.com/">https://tableplus.com/</a><br><strong>Visual Studio Code </strong>( Text Editor )<br><a href="https://code.visualstudio.com/">https://code.visualstudio.com/</a></blockquote><p>บทความนี้ผมหวังว่าผู้อ่านจะเข้าใจ และนำไปประยุกต์ใช้ได้นะ ถ้ามีอะไรไม่เข้าใจ หรือแลกเปลี่ยนความรู้มาคุยกันได้ พอดีเพิ่งหัดเขียนเว็ป มาได้ไม่นานเองครับ และอันนี้อยากจะเก็บไว้ เวลาผมลืมว่ามันทำอย่างไรจะได้กลับมาดูและทำตามได้ ฮ่าๆๆ</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d5d769aeb6c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make an iOS Device into an iBeacon Device, Swift Programming]]></title>
            <link>https://medium.com/@takdanai.3473/how-to-make-an-ios-device-into-an-ibeacon-device-swift-programming-342dae4268?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/342dae4268</guid>
            <category><![CDATA[swift]]></category>
            <category><![CDATA[ibeacon]]></category>
            <category><![CDATA[ibeacon-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Tue, 23 Jul 2019 06:04:22 GMT</pubDate>
            <atom:updated>2019-07-23T06:04:22.650Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello, Today We will make an iOS device into an iBeacon Device ( Broadcast Signal) by using Swift Language</p><p>What is iBeacon?<br>It is a technology developed by Apple. It helps to identify the location of various devices. Using Bluetooth 4.0 technology.</p><p>In this article. I do not have many details on the iBeacon. I want to implement the example from this <a href="https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon">Hackingwithswift</a> with a user interface to use it.</p><p>The value of iBeacon that we need to know first.<br>- UUID is a set of numbers that are created for Beacon<br>- Major is a set of numbers indicating that beacon is in which group can be referenced from the same UUID<br>- Minor is a set of numbers indicating that beacon is in which sub-group that divided from major.</p><p>Requirement:<br>1. XCode Program<br>2. iOS Device</p><p>Source Code:<br><a href="https://github.com/rookiehome7/ibecon_Broadcast_IOS">https://github.com/rookiehome7/ibecon_Broadcast_IOS</a></p><p>Let’s start.<br>1. Create a project first <br>Xcode: File &gt; New &gt; Project by choosing to be a Single View App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*cUAgkFLcVw9y3chsrigfnQ.png" /></figure><p>2. Go to the Main Storyboard page <br>This page will manage the user interface of our application. Now we will make the very simple UI by showing the value ex. UUID, Major, Minor, Identity, Beacon Status, and two-button</p><p>First I using Vertical Stack View.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*gLhLOpgu_n0oGyA4RaiLGA.png" /><figcaption>Press Command + Shift + L to open Library or click at that button</figcaption></figure><p>After we drag the Vertical Stack View into our view page.</p><p>2.1 We started to set Constraints together. I want it to be in the middle of the screen. I went to set Horizontally and Vertically in Container. I wanted it to be aligned from the left corner. And the right corner of both screens. Add Constraints</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*GyI8w4bnDcMgEMurgQywiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*rm0fC4yKS2-jyXJODuBV1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*H9IURb6O1iSyWu3gbDujQQ.png" /></figure><p>2.2 Add the label to each row.<br>By using Horizontal Stack View. Then put the label inside it.<br>Vertical Stack View<br>-&gt;Horizontal Stack View<br> → Label<br> → Label<br>We can open the library and drag it into the bar.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebumFpZKKlATURhu_bpAPA.gif" /></figure><p>After inserting 2 labels, you will notice that It’s not equal We have to set the Constraints on the left label to have width 100.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*unEMBrfJB1FznknL4SpV5A.png" /></figure><p>2.3 It will use about 5 rows. Then make it duplicate.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxSgA3k7wTIJdZ4kxP_96g.gif" /></figure><p>Click on the Stack View. And Set the Spacing value to make it easy to read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*vBPmVmiNpxEzvO8ggU6BBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*YpYiUqcu9R4pWTzNt5K52g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*yXp93ruCncrei12IXYLI1A.png" /></figure><p>2.3 Set the label name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*J6RJD3BggIi0qPrlib80oA.gif" /></figure><p>2.4 Create two additional buttons. Name the button that says Start and Stop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wDw8eN9ScohbgiRwsYmSQ.gif" /></figure><p>3. We will start writing in the Controller section. In this step, it will be Connect UI to the Code section.</p><p>In Swift language, we are our Assistant Editor on the right. Will open ViewController.swift And then we select the things that we want by pressing Ctrl and dragging into our Code section.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHr0T4t2cWNS68TKPFbXJQ.gif" /></figure><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> uuidValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> majorValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> minorValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> identityValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> beaconStatus: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> startButton: UIButton!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> stopButton: UIButton!</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*mV2P_13GW_YynAmLJ4aZNg.png" /></figure><p>After that, we have already connected the User Interface and Code.</p><p>4. First of all, we have to prepare the UUID value to use in our application. <br>Open Terminal in macOS and type uuidgen. We then store the values ​​that we created first.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tkb_dkRUtHi3dTH-VuhJdw.png" /></figure><p>5. First of all, we have to import the library that will be used in our project. And we have to add</p><p>CBPeripheralManagerDelegate goes after UIViewController As in the picture</p><pre><strong>import</strong> CoreBluetooth<br><strong>import</strong> CoreLocation</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*8jzBOwW4THqTM4Wc5nO0Kg.png" /></figure><p>6. Create variables <br>For the localBeaconUUID, We can use the value created from step 5.</p><pre><strong>var</strong> localBeacon: CLBeaconRegion!<br><strong>var</strong> beaconPeripheralData: NSDictionary!<br><strong>var</strong> peripheralManager: CBPeripheralManager!<br><strong>let</strong> localBeaconUUID = “F651C4C7-B4BC-4656-B246-AF8B709EF297”<br><strong>let</strong> localBeaconMajor: CLBeaconMajorValue = 123<br><strong>let</strong> localBeaconMinor: CLBeaconMinorValue = 456<br><strong>let</strong> identifier = “Put your identifier here”</pre><p>7. Create a management function. iBecon is used to start and stop services and peripheralManagerDidUpdateState from adding CBPeripheralManagerDelegate.</p><pre><strong>func</strong> initLocalBeacon() {<br><strong>if</strong> localBeacon != <strong>nil</strong> {<br>stopLocalBeacon()<br>}<br><strong>let</strong> uuid = UUID(uuidString: localBeaconUUID)!<br>localBeacon = CLBeaconRegion(proximityUUID: uuid, major: localBeaconMajor, minor: localBeaconMinor, identifier: identifier)<br>beaconPeripheralData = localBeacon.peripheralData(withMeasuredPower: <strong>nil</strong>)<br>peripheralManager = CBPeripheralManager(delegate: <strong>self</strong>, queue: <strong>nil</strong>, options: <strong>nil</strong>)<br>}</pre><pre><strong>func</strong> stopLocalBeacon() {<br>peripheralManager.stopAdvertising()<br>peripheralManager = <strong>nil<br></strong>beaconPeripheralData = <strong>nil<br></strong>localBeacon = <strong>nil<br></strong>}</pre><pre><strong>func</strong> peripheralManagerDidUpdateState(<strong>_</strong> peripheral: CBPeripheralManager) {<br><strong>if</strong> peripheral.state == .poweredOn {<br>peripheralManager.startAdvertising(beaconPeripheralData <strong>as</strong>? [String: <strong>Any</strong>])<br>}</pre><pre><strong>else</strong> <strong>if</strong> peripheral.state == .poweredOff {<br>peripheralManager.stopAdvertising()<br>}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUVChb7zZJhooVAAlChmnw.png" /></figure><p>8. Add commands when we press the Start and Stop buttons</p><pre><em>// MARK: Action<br></em><strong>@IBAction</strong> <strong>func</strong> startButton(<strong>_</strong> sender: <strong>Any</strong>) {<br>initLocalBeacon()<br>startButton.isHidden = <strong>true<br></strong>stopButton.isHidden = <strong>false<br></strong>beaconStatus.text = “ON”<br>}</pre><pre><strong>@IBAction</strong> <strong>func</strong> stopButton(<strong>_</strong> sender: <strong>Any</strong>) {<br>stopLocalBeacon()<br>startButton.isHidden = <strong>false<br></strong>stopButton.isHidden = <strong>true<br></strong>beaconStatus.text = “OFF”<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*vBUVY089FhpEd38WNyMQMQ.png" /></figure><p>9. Create commands in the function viewDidLoad() to set the UI to show the values ​​we need</p><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {<br><strong>super</strong>.viewDidLoad()<br>stopButton.isHidden = <strong>true</strong><em><br></em>uuidValue.text = localBeaconUUID<br>majorValue.text = String(localBeaconMajor)<br>minorValue.text = String(localBeaconMinor)<br>identityValue.text = identifier<br>beaconStatus.text = “OFF”<br>}</pre><p>10. We try to build a Build Project to see if there are any errors and fix them.<br>After loading finish, Start it and finding another device to searching this device ( I try from the application in Android Phone).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*FEkKh5taqJU3Us_q-Z4BSw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dLRE1uagQUeR1KjCnmyNDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GSeYURABwU4bLOWZ1Jrucg.png" /></figure><p>Distance in the application may not accurate with the actual distance.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ksDo32OEvzI3rb9b" /></figure><p>Hope that this article should be understood. And the reader can use in reader’s application.</p><p>Thank you for reading my article. I just learned Swift programming. Maybe not very skilled. I just learned to write a few weeks. Too, and if there is anything else you can commend me.</p><p>Source Code<br><a href="https://github.com/rookiehome7/ibecon_Broadcast_IOS">https://github.com/rookiehome7/ibecon_Broadcast_IOS</a></p><p>Reference<br><a href="https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon">https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon</a><br><a href="https://medium.com/@kittipatdienprapai/beacon-technology-e885a71e14ac">https://medium.com/@kittipatdienprapai/beacon-technology-e885a71e14ac</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=342dae4268" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to make an iOS Device into an iBeacon Device, Swift Programming 2]]></title>
            <link>https://medium.com/@takdanai.3473/how-to-make-an-ios-device-into-an-ibeacon-device-swift-programming-2-420628f6ad20?source=rss-da4e73901a95------2</link>
            <guid isPermaLink="false">https://medium.com/p/420628f6ad20</guid>
            <category><![CDATA[ibeacon]]></category>
            <category><![CDATA[ibeacon-app-development]]></category>
            <category><![CDATA[swift-programming]]></category>
            <category><![CDATA[ios-app-development]]></category>
            <category><![CDATA[swift]]></category>
            <dc:creator><![CDATA[Takdanai jirawanichkul]]></dc:creator>
            <pubDate>Sat, 20 Jul 2019 16:07:12 GMT</pubDate>
            <atom:updated>2020-01-28T04:32:45.304Z</atom:updated>
            <content:encoded><![CDATA[<h3>ทำอุปกรณ์ iOS Device ให้ปล่อยสัญญาน iBecon โดยใช้ภาษา Swift Programming</h3><p><a href="https://medium.com/@takdanai.3473?source=post_page---------------------------">takdanai jirawanichkul</a></p><p><a href="https://medium.com/@takdanai.3473/how-to-make-an-ios-device-into-an-ibeacon-device-swift-programming-2-420628f6ad20?source=post_page---------------------------">Jul 21</a> · 6 min read</p><p>สวัสดีครับวันนี้ เราจะมาลองเขียนโปรแกรมภาษา Swift Language กัน<br>โดยจะให้อุปกรณ์ IOS สามารถปล่อยสัญญาน beacon signal ออกมา</p><p>iBeacon คืออะไร?<br>มันคือเทคโนโลยีที่พัฒนาโดยบริษัท Apple โดยจะช่วยระบุตำแหน่งของอุปกรณ์ต่างๆ โดยอาศัยเทคโนโลยี Bluetooth 4.0 เป็นพื้นฐานการค้นหาตำแหน่งต่างๆ</p><p>โดยในบทความอันนี้ ผมจะไม่ได้ลงรายละเอียดกับในตัว iBeacon มากนักเท่าไหร่ จุดประสงค์ของผมอันนี้คืออยากจะลองเขียนบทความ และนำมาอธิบายเป็นส่วนๆซึ่งผมก็อ้างอิงทำตาม มาจากเว็ป <a href="https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon?source=post_page---------------------------">Hackingwithswift</a> นี้ครับ ผมอยากจะเพิ่มเติมจากตัวอย่างขึ้นมานิดหน่อย</p><p>iBecon มีค่าอะไรบ้างที่ตั้งค่าแบบเบื้องต้นสุดๆ <br>- <strong>UUID </strong>คือ ชุดตัวเลขที่ถูกสร้างขึ้นมาให้กับ Beacon แต่ละตัว<br>- <strong>Major </strong>คือ ชุดตัวเลขที่ระบุว่า Beacon อยู่ในกลุ่มใดจะอ้างอิงได้จาก UUID เดียวกัน<br>- <strong>Minor </strong>คือ ชุดตัวเลขที่ระบุว่า Beacon อยู่ในกลุ่มใดที่ย่อยลงมาจาก Major อีกที<br>- <strong>TxPower </strong>คือ ค่าความแรงของสัญญาณ</p><p>อุปกรณ์ที่จะต้องมีก่อนทำ <br>1. โปรแกรม XCode<br>2. อุปกรณ์ IOS Device</p><p>Source Code<br><a href="https://github.com/rookiehome7/ibecon_Broadcast_IOS?source=post_page---------------------------">https://github.com/rookiehome7/ibecon_Broadcast_IOS</a></p><p>เรามาเริ่มกันดีกว่านะ<br>1.สร้างโปรเจคกันก่อนเลย<br>Xcode : File &gt; New &gt; Project โดยเลือกเป็น App IOS ประเภท Single View App</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*cUAgkFLcVw9y3chsrigfnQ.png" /></figure><p>2. เข้าไปยังหน้า Main Storyboard <br>ซึ่งในหน้าอันนี้จะเป็นการจัดการหน้าตาของแอปพลิเคชั่นของเรา อันที่ผมทำก็ไม่ได้ใช้เทคนิคอะไรมากมายเลยนะครับแฮะๆ ซึ่งค่าของเราก็จะเอาค่าหลักๆมาใช้ก็จะมี เป็น UUID, Major, Minor, Identity, Beacon Status กับ ปุ่มอีกสองปุ่มนะ</p><p>การจัดหน้า UI ผมก็จะใช้ Stack View ในการช่วยเรียงลำดับแถวของตัวอักษร</p><p>กด Command + Shift + L เพื่อเปิด Library ขึ้นมา หรือไปที่ปุ่มที่อยู่บริเวณมุมบนขวา</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*gLhLOpgu_n0oGyA4RaiLGA.png" /><figcaption>Press Command + Shift + L to open Library or click at that button</figcaption></figure><p>หลังจากที่เราลากตัว Vertical Stack View เข้าไปใน หน้าหลักของเราแล้ว</p><p>2.1 เราก็มาเริ่มตั้งค่า Constraints กันก่อนเลยผมอยากให้มันอยู่ตรงบริเวณกลางของหน้าจอผมก็ไปตั้งค่า Horizontally และ Vertically in Container แล้วผมก็อยากให้มันชิดจากมุมซ้าย และมุมขวาของจอ ทั้งสองอัน Add Constraints</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/349/1*GyI8w4bnDcMgEMurgQywiQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/296/1*rm0fC4yKS2-jyXJODuBV1A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/379/1*H9IURb6O1iSyWu3gbDujQQ.png" /></figure><p>2.2 เรามาเพิ่มตัว label ในแต่ละแถวกัน<br>เราจะต้องใช้ Horizontal Stack View แล้วเราก็ใส่ label เข้าไปข้างในนั้น สองอัน <br>Vertical Stack View<br>-&gt;Horizontal Stack View<br>→ Label<br>→ Label<br>โดยเราสามารถเปิด Library แล้วลากเข้าไปในแถบด้านซ้าย สังเกตุดีๆด้วยหละ เวลา<br>จะวาง มันจะอยู่ในระดับที่แตกต่างกันได้</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ebumFpZKKlATURhu_bpAPA.gif" /></figure><p>หลังจากที่ใส่ label เข้าไป 2 อันแล้วจะสังเกตุได้ว่า มันไม่เท่ากัน เราก็ไปตั้งค่า Constraints ของ label ด้านซ้ายให้มีค่า Width สัก 100</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/280/1*unEMBrfJB1FznknL4SpV5A.png" /></figure><p>2.3 เราจะใช้ประมาณ 5 แถว เราก็ Copy Stack View ที่สร้างไว้แล้วกันเลย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QxSgA3k7wTIJdZ4kxP_96g.gif" /></figure><p>กดไปที่ Stack View อันที่อยู่นอกสุด แล้วไปตั้งค่า Spacing จัดความห่างให้มันสวยงามขึ้นอีกนิดนึง</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/290/1*vBPmVmiNpxEzvO8ggU6BBg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/519/1*YpYiUqcu9R4pWTzNt5K52g.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*yXp93ruCncrei12IXYLI1A.png" /></figure><p>2.3 ตั้งชื่อกันให้เรียบร้อย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*J6RJD3BggIi0qPrlib80oA.gif" /></figure><p>2.4 สร้างปุ่มเพิ่มอีกสักสองปุ่ม ตั้งชื่อปุ่มว่า Start และ Stop</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1wDw8eN9ScohbgiRwsYmSQ.gif" /></figure><p>3. เราจะเริ่มมาเขียนในส่วนของตัว Controller กันแล้วนะ ในขั้นตอนนี้ก็จะเป็นการ เชื่อมต่อหน้าตา UI กับส่วนของ Code</p><p>ในภาษา Swift เราก็ Assistant Editor ด้านขวาของเรา จะเป็นการเปิด ViewController.swift แล้วเราก็เลือกสิ่งต่างๆที่เราต้องการ โดยการ กด Ctrl ค้างแล้วลากเข้าไปในส่วนของ Code ของเราเลย ตั้งชื่อตัวแปรให้เรียบร้อย</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hHr0T4t2cWNS68TKPFbXJQ.gif" /></figure><pre><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> uuidValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> majorValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> minorValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> identityValue: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> beaconStatus: UILabel!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> startButton: UIButton!<br><strong>@IBOutlet</strong> <strong>weak</strong> <strong>var</strong> stopButton: UIButton!</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/605/1*mV2P_13GW_YynAmLJ4aZNg.png" /></figure><p>หลังจากนั้นเราก็เชื่อมส่วนของ User Interface กับ Code เรียบร้อยแล้ว</p><p>4. ก่อนอื่นเลย เราจะต้องมา เตรียมค่า UUID เพื่อใช้ ในแอปพลิเคชั่นของเรา<br>เปิด Terminal ใน MacOS แล้วพิมพ์คำสั่ง ​uuidgen แล้วเราก็เก็บค่าที่เราสร้างขึ้นมาไว้ก่อน</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Tkb_dkRUtHi3dTH-VuhJdw.png" /></figure><p>5. ก่อนอื่นเราก็ต้อง import library ที่จะใช้ในโปรเจคของเรา และเราจะต้องเพิ่ม</p><p>CBPeripheralManagerDelegate ไปไว้หลัง UIViewController ตามในรูปได้เลย</p><pre><strong>import</strong> CoreBluetooth<br><strong>import</strong> CoreLocation</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*8jzBOwW4THqTM4Wc5nO0Kg.png" /></figure><p>6. สร้างตัวแปรที่สำคัญกันก่อนเลย<br>ในตัว localBeaconUUID เราก็เอาค่าที่เราสร้างขึ้นมาจากในขั้นตอนที่ 5 มาใช้ได้เลย</p><pre><strong>var</strong> localBeacon: CLBeaconRegion!<br><strong>var</strong> beaconPeripheralData: NSDictionary!<br><strong>var</strong> peripheralManager: CBPeripheralManager!<br><strong>let</strong> localBeaconUUID = “F651C4C7-B4BC-4656-B246-AF8B709EF297”<br><strong>let</strong> localBeaconMajor: CLBeaconMajorValue = 123<br><strong>let</strong> localBeaconMinor: CLBeaconMinorValue = 456<br><strong>let</strong> identifier = “Put your identifier here”</pre><p>7. สร้างฟังก์ชั่นจัดการ iBecon ใช้ในการ Start และ Stop Service และ peripheralManagerDidUpdateState จากการเพิ่ม CBPeripheralManagerDelegate</p><pre><strong>func</strong> initLocalBeacon() {<br><strong>if</strong> localBeacon != <strong>nil</strong> {<br>stopLocalBeacon()<br>}<br><strong>let</strong> uuid = UUID(uuidString: localBeaconUUID)!<br>localBeacon = CLBeaconRegion(proximityUUID: uuid, major: localBeaconMajor, minor: localBeaconMinor, identifier: identifier)<br>beaconPeripheralData = localBeacon.peripheralData(withMeasuredPower: <strong>nil</strong>)<br>peripheralManager = CBPeripheralManager(delegate: <strong>self</strong>, queue: <strong>nil</strong>, options: <strong>nil</strong>)<br>}<strong>func</strong> stopLocalBeacon() {<br>peripheralManager.stopAdvertising()<br>peripheralManager = <strong>nil<br></strong>beaconPeripheralData = <strong>nil<br></strong>localBeacon = <strong>nil<br></strong>}<strong>func</strong> peripheralManagerDidUpdateState(<strong>_</strong> peripheral: CBPeripheralManager) {<br><strong>if</strong> peripheral.state == .poweredOn {<br>peripheralManager.startAdvertising(beaconPeripheralData <strong>as</strong>? [String: <strong>Any</strong>])<br>}<strong>else</strong> <strong>if</strong> peripheral.state == .poweredOff {<br>peripheralManager.stopAdvertising()<br>}<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JUVChb7zZJhooVAAlChmnw.png" /></figure><p>8. เพิ่มคำสั่งเมื่อเรากดปุ่ม Start และ Stop</p><pre><em>// MARK: Action<br></em><strong>@IBAction</strong> <strong>func</strong> startButton(<strong>_</strong> sender: <strong>Any</strong>) {<br>initLocalBeacon()<br>startButton.isHidden = <strong>true<br></strong>stopButton.isHidden = <strong>false<br></strong>beaconStatus.text = “ON”<br>}<strong>@IBAction</strong> <strong>func</strong> stopButton(<strong>_</strong> sender: <strong>Any</strong>) {<br>stopLocalBeacon()<br>startButton.isHidden = <strong>false<br></strong>stopButton.isHidden = <strong>true<br></strong>beaconStatus.text = “OFF”<br>}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/578/1*vBUVY089FhpEd38WNyMQMQ.png" /></figure><p>9. สร้างคำสั่งในฟังก์ชั่น viewDidLoad() เพื่อเป็นการ ตั้งค่าให้ UI แสดงค่าต่างๆที่เราต้องการ</p><pre><strong>override</strong> <strong>func</strong> viewDidLoad() {<br><strong>super</strong>.viewDidLoad()<br>stopButton.isHidden = <strong>true</strong><em><br></em>uuidValue.text = localBeaconUUID<br>majorValue.text = String(localBeaconMajor)<br>minorValue.text = String(localBeaconMinor)<br>identityValue.text = identifier<br>beaconStatus.text = “OFF”<br>}</pre><p>10. หลังจากนั้นก็ลองโหลดแอปพลิเคชั่นเข้าไปในอุปกรณ์และก็ หาอุปกรณ์ที่มี แอปที่ค้นหาสัญญาน Beacon ได้มาลองดู</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*FEkKh5taqJU3Us_q-Z4BSw.jpeg" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*dLRE1uagQUeR1KjCnmyNDg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/640/1*GSeYURABwU4bLOWZ1Jrucg.png" /></figure><p>ระยะทางที่แสดงก็อาจจะไม่ค่อยตรงกับระยะจริงสักเท่าไหร่นะ ฮ่าๆ</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*ksDo32OEvzI3rb9b" /></figure><p>หวังว่าบทความนี้น่าจะตอบโจทย์ผู้อ่านได้ และนำไปใช้ประโยชน์ได้นะ</p><p>Thank you for reading my article. I just learned Swift programming. Maybe not very skilled. I just learned to write a few weeks. Too, and if there is anything else you can commend me.</p><p>Source Code<br><a href="https://github.com/rookiehome7/ibecon_Broadcast_IOS">https://github.com/rookiehome7/ibecon_Broadcast_IOS</a></p><p>Reference<br><a href="https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon">https://www.hackingwithswift.com/example-code/location/how-to-make-an-iphone-transmit-an-ibeacon</a><br><a href="https://medium.com/@kittipatdienprapai/beacon-technology-e885a71e14ac">https://medium.com/@kittipatdienprapai/beacon-technology-e885a71e14ac</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=420628f6ad20" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>