-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathProgram.cs
48 lines (43 loc) · 1.47 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
using Microsoft.Azure.ServiceBus;
using System;
using System.Text;
using System.Threading.Tasks;
namespace ServiceBusSender
{
class Program
{
//TODO - Move connection strings to secured file in project
const string ServiceBusConnectionString = "Your connecting string for service bus here";
const string QueueName = "devjonahtestqueue1";
static IQueueClient queueClient;
static void Main(string[] args)
{
MainAsync().GetAwaiter().GetResult();
}
static async Task MainAsync()
{
const int noOfMsgs = 50;
queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
await SendMessagesAsync(noOfMsgs);
await queueClient.CloseAsync();
}
static async Task SendMessagesAsync(int noOfMsgToSend)
{
try
{
for (int i = 0; i < noOfMsgToSend; i++)
{
//Create and send async msg to the queue
string msgBody = $"Message {i}";
var msg = new Message(Encoding.UTF8.GetBytes(msgBody));
Console.WriteLine($"Sending message: {msgBody}");
await queueClient.SendAsync(msg);
}
}
catch (Exception ex)
{
Console.WriteLine($"{DateTime.Now}:: Exception: {ex.Message}");
}
}
}
}