Last active
August 17, 2022 10:48
-
-
Save savaged/be9bdfc15d0e5515ccdfa30027b1a224 to your computer and use it in GitHub Desktop.
Azure Storage Queues Hello World
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.Azure.Storage; | |
using Microsoft.Azure.Storage.Queue; | |
using Newtonsoft.Json; | |
using System; | |
using System.Threading; | |
namespace MyCo_Workflow | |
{ | |
class Program | |
{ | |
private const string _conn = "your string here"; | |
static void Main(string[] args) | |
{ | |
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(_conn); | |
CloudQueueClient queueClient = storageAccount.CreateCloudQueueClient(); | |
CloudQueue queue = queueClient.GetQueueReference("savagedqueue"); | |
queue.CreateIfNotExists(); | |
CloudQueueMessage message = new CloudQueueMessage(new ExampleModel().ToJson()); | |
queue.AddMessage(message); | |
Thread.Sleep(10000); | |
message = queue.GetMessage(); | |
Console.WriteLine(message.AsString); | |
queue.DeleteMessage(message); | |
} | |
} | |
public class ExampleModel | |
{ | |
public ExampleModel() | |
{ | |
Id = 1; | |
ExampleField = "My example field data"; | |
} | |
public int Id { get; set; } | |
public string ExampleField { get; set; } | |
public string ToJson() | |
{ | |
var value = JsonConvert.SerializeObject(this); | |
return value; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment