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,027

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



Clound SSD Virtual Server

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

ตอนที่ 12 : รู้จักกับ Azure Queue Storage และการเขียนร่วมกับ .Net 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 แต่ในบทความนี้ ใช้รูปแบบการเขียน .NET Application แบบ ASP.Net Web Application และก่อนการเขียนจะต้องติดตั้ง Visual Studio ให้เรียบร้อยก่อน โดยสามารถอ่านได้จากบทความก่อนหน้านี้

Queue Storage .NET Application

Azure Queue Storage Service


ตอนที่ 2 : ปรับแต่ง Visual Studio เรียกใช้งาน Library เพื่อติดต่อกับ Azure Storage


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

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

Queue Storage .NET Application

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

Queue Storage .NET Application

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

กลับมายัง Project บน Visual Studio

Queue Storage .NET Application








การเชื่อมต่อ .NET กับ Table Storage บน Windows Azure

Import Library
using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Queue;


สร้าง Connection String ใส่ Account และ Key ให้ถูกต้อง
String StorageConnectionString = "DefaultEndpointsProtocol=https;AccountName=[yourAccount];AccountKey=[yourKey]";

CloudStorageAccount storageAccount = CloudStorageAccount.Parse(StorageConnectionString);

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

Default.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Microsoft.WindowsAzure.Storage;
using Microsoft.WindowsAzure.Storage.Auth;
using Microsoft.WindowsAzure.Storage.Queue;

namespace myWebApp
{
    public partial class Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            // Create the connectionstring
            String StorageConnectionString = "DefaultEndpointsProtocol=https;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.CreateIfNotExists();

            this.lblResult.Text = "Queue 'myqueue' has been created.";

        }
    }
}

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="myWebApp.Default" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>ThaiCreate.Com Azure Storage Tutorial</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>

        <asp:Label ID="lblResult" runat="server"></asp:Label>
    
    </div>
    </form>
</body>
</html>

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

Queue Storage .NET Application

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

Queue Storage .NET Application

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

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








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

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


   
Share


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


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


   


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

 
ตอนที่ 1 : รู้จักกับ Windows Azure และเบื้องต้นกับ Storage สำหรับ .Net Application
Rating :

 
ตอนที่ 2 : ปรับแต่ง Visual Studio เรียกใช้งาน Library เพื่อติดต่อกับ Azure Storage
Rating :

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

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

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

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

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

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

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

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

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

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

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

 
ตอนที่ 15 : How to use .Net (Asp.net) 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 อัตราราคา คลิกที่นี่