Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,025

HOME > Windows Azure > Windows Azure (Storage) and Java Application > ตอนที่ 12 : รู้จักกับ Queue Storage และการเขียนร่วมกับภาษา Java Application



Clound SSD Virtual Server

ตอนที่ 12 : รู้จักกับ Queue Storage และการเขียนร่วมกับภาษา Java Application

ตอนที่ 12 : รู้จักกับ Queue Storage และการเขียนร่วมกับภาษา Java Application สำหรับ Queue Service บน Storage ของ Windows Azure เป็นบริการภายใต้ Storage ใช้สำหรับการสร้าง Queue หรือกลุ่มของลำดับข้อมูล แบบ First-In Last-Out เรียงลำดับก่อนหลัง เช่นในระบบการส่ง Message ไปยังสมาชิก ประมาณ 100,000 คน เราก็อาจจะสร้าง Queue Services จัดเก็บลำดับของสมาชิกทั้ง 100,000 คนด้วยการนำข้อมูลทั้งหมดบันทึกลงใน Queue และเมื่อได้ Queue แล้ว เราจะอาศัยการทำงานร่วมกับโปรแกรมอื่น ๆ ที่จะสามารถมาอ่าน Queue เพื่อไปยังตำแหน่งของถัดไป และเมื่อ Queue นั้น ๆ ทำงานเสร็จสิ้นแล้ว เราก็สามารถลบ Queue นั้น ๆ ออกจากระบบ และ Queue ถัดไปก็จะขึ้นมาแทนทีลำดับเพื่อรอการทำงานอื่น ๆ ถัดไป เหตุผลหนึ่งที่ใน Windows Azure มีบริการ Queue ขึ้นมาก็คือ ในความเป็นจริงแล้วเราสร้าง Queue ขึ้นมาใช้เองนั้นจะมีความยุ่งยากในการออกแบบและการเขียนมาก และเพื่อที่จะให้ Queue ทำงานได้อย่างมีประสิทธิภาพก็ยุ่งยากเช่นเดียวกัน ทั้งยังต้องเตรียม Application ทั้ง Server และ Database แต่ถ้าเราใช้ Queue Storage ของ Windows Azure เราไม่จำเป็นจะต้องกังวลกับการออกแบบเลย จะสร้าง Queue ขึ้นมาเป็นแสน ล้าน หรือหลายสร้าง Queue ก็ไม่มีปัญหา สามารถแบ่งกลุ่มของ Queue สามารถทำงานอ่าน-เขียน ได้รวดเร็ว และในอนาคต Queue ยังสามารถใช้งานร่วมกับ Application บน Mobile เช่น iOS , Android และ Windows Phone ซึ่งจะเป็นประโยชน์แน่นอน เมื่อนำมาประยุกต์ใช้กับ App บน Mobile แต่ในบทความนี้ ใช้รูปแบบการเขียน Java แบบ JSP Web Application และก่อนการเขียนจะต้องติดตั้ง Java SDK กับโปรแกรม Eclipse / Apache Tomcat ให้เรียบร้อยก่อน โดยสามารถอ่านได้จากบทความก่อนหน้านี้

Queue Storage Java Application

Azure Queue Storage Service


ตอนที่ 2 : Config Eclipse กับ Apache Tomcat ไว้เขียน JSP กับ Windows Azure


ข้อมูลที่จัดเก็บใน Queue Service จะนิยมจัดเก็บพวก Queue ของ Message และ Application ไม่จำเป็นว่าจะต้องเป็น Java เท่านั้น เพราะใน Windows Azure เองก็ได้ก็ได้ออกแบบ SDK ที่รองรับหลาย ๆ ภาษา เช่น .Net , PHP และอื่น ๆ รวมทั้งในอนาคตเร็ว ๆ นี้จะมี SDK ที่รองรับการเขียนบน Mobile อาทิพวก Android , iOS และ Windows Phone อย่างแน่นอน

กลับมายังหน้า Storage บน Portal Management ของ Windows Azure

Queue Storage Java Application

ให้คลิกที่ Manage Access Key เพื่อจะเอา Key ไปใช้งาน

Queue Storage Java Application

เราจะได้ Key นี้ไว้ใช้งานและเชื่อมต่อกับ Storage หลังจากนั้นเราจะเขียน Java (JSP) เพื่อติดต่อกับ Queue








กลับมายัง Project บน Eclipse

Queue Storage Java Application

Windows Azure Libraries for Java

ให้ Download ไฟล์ Jar Library สำหรับ Windows Azure มาใช้

Queue Storage Java Application

ให้นำไฟล์ไปไว้ใน Project ของ JSP โดยจัดเก็บไว้ที่ WEB-INF/lib

Queue Storage Java Application

จากนั้นให้คลิกควาที่ Project -> Properties

Queue Storage Java Application

เลือก Java Build Path -> Add JARs

Queue Storage Java Application

เลือก Library ที่ได้ Copy ไว้ก่อนหน้านี้ เลือก OK และ ตอนนี้ Library ได้ถูกเพิ่มเข้ามาใน Project เรียบร้อยแล้ว จากนั้นเราจะทดสอบการเขียน JSP แบบง่าย ๆ ซึ่งจะเป็นตัวอย่างการสร้าง Queue

การเชื่อมต่อ Java กับ Queue Storage บน Windows Azure

Import Library
import com.microsoft.windowsazure.services.core.storage.*;
import com.microsoft.windowsazure.services.queue.client.*;


สร้าง Connection String ใส่ Account และ Key ให้ถูกต้อง
public static final String storageConnectionString =
"DefaultEndpointsProtocol=http;" +
"AccountName=[yourAccount];" +
"AccountKey=[yourKey]";

String storageConnectionString =
RoleEnvironment.getConfigurationSettings().get("StorageConnectionString");

โดยขั้นแรกเราจะต้องทำการสร้างชื่อ Queue (เปรียบเสมือนกลุ่มลอง Queue หรือจะสร้างเป็น User ก็ได้) ให้สำหรับการจัดเก็บลำดับข้อความซะก่อน

<%@ page import="com.microsoft.windowsazure.services.core.storage.*" %>
<%@ page import="com.microsoft.windowsazure.services.queue.client.*" %>

<html>
<head>
	<title>ThaiCreate.Com Azure Tutorial</title>
</head>
<body>
	<%
	
	String storageConnectionString = 
    "DefaultEndpointsProtocol=http;" + 
    "AccountName=[yourAccount];" + 
    "AccountKey=[yourKey]";
    
 	// Retrieve storage account from connection-string
    CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);

 	// Create the queue client
    CloudQueueClient queueClient = storageAccount.createCloudQueueClient();
 	
 	// Retrieve a reference to a queue
    CloudQueue queue = queueClient.getQueueReference("myqueue");

    // Create the queue if it doesn't already exist
    queue.createIfNotExist();	
	
    out.print("Queue 'myqueue' has been created.");
    
	%>
</body>
</html>

ใน Code นี้จะสร้าง Queue ชื่อว่า myqueue (จาก Code อย่าลืมแก้ไข Account และ Key ให้ถูกด้วย)

Queue Storage Java Application

ทดสอบ Run โปรแกรม

Queue Storage Java Application

เมื่อใช้ Azure Storage Explorer เราจะพบกับ Queue ที่เราสร้างขึ้น

หลังจากที่ได้ Queue แล้ว ต่อไปเราก็จะใช้ Java (JSP) ทำการสร้าง Queue อ่าน Queue หรือไปยัง Queue ถัดไป โดยสามารถอ่านได้จากบทความถัดไป

บทความที่เกี่ยวข้อง









บทความถัดไปที่แนะนำให้อ่าน


   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2013-11-30 08:29:02 / 2017-03-24 14:31:40
  Download : No files
 Sponsored Links / Related

 
ตอนที่ 1 : รู้จักกับ Windows Azure และ Azure Java SDK สำหรับภาษา Java
Rating :

 
ตอนที่ 2 : Config Eclipse กับ Apache Tomcat ไว้เขียน JSP กับ Windows Azure
Rating :

 
ตอนที่ 3 : รู้จักกับ Blob Storage และการเขียนร่วมกับภาษา Azure for Java Application
Rating :

 
ตอนที่ 4 : How to use Java (JSP) Upload file to Blob การอัพโหลดไฟล์ลงใน Blob
Rating :

 
ตอนที่ 5 : How to use Java (JSP) List the Blobs การแสดงรายการไฟล์จาก Blob
Rating :

 
ตอนที่ 6 : How to use Java (JSP) Delete Blob การลบรายการไฟล์บน Blob
Rating :

 
ตอนที่ 7 : รู้จักกับ Table Storage Service และการเขียนร่วมกับภาษา Java Application
Rating :

 
ตอนที่ 8 : How to use Java (JSP) Add Entity to a Table Storage - บันทึกข้อมูลลงตาราง
Rating :

 
ตอนที่ 9 : How to use Java (JSP) Retrieve Entity from Table Storage - อ่านข้อมูลในตาราง
Rating :

 
ตอนที่ 10 : How to use Java (JSP) Update Entity in Table Storage - แก้ไขข้อมูลในตาราง
Rating :

 
ตอนที่ 11 : How to use Java (JSP) Delete Entity in Table Storage - ลบข้อมูลในตาราง
Rating :

 
ตอนที่ 13 : How to use Java (JSP) Create a message Queue - สร้างคิวใหม่
Rating :

 
ตอนที่ 14 : How to use Java (JSP) Peek at the next message - อ่านคิวถัดไป
Rating :

 
ตอนที่ 15 : How to use Java (JSP) De-queue the next messag - ขยับไปยังคิวถัดไป
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 02
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่