-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (53 loc) · 2.13 KB
/
Program.cs
File metadata and controls
59 lines (53 loc) · 2.13 KB
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
49
50
51
52
53
54
55
56
57
58
59
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Services.Queue;
using Pet360.Service.Email;
namespace BHWorker
{
public class Program
{
private static Consumer _consumer;
private static string _queueName = ConfigurationManager.AppSettings.Get("BHQueueName");
private static string _endpoint = ConfigurationManager.AppSettings.Get("BHEndpoint");
private delegate void _consumeDelegate();
private static EmailService _sendEmail;
private static int _counter;
static void Main(string[] args)
{
StartConsuming();
}
private static void StartConsuming()
{
try
{
_counter = 0;
Console.WriteLine("NOW READING FROM QUEUE" + Environment.NewLine);
_consumer = new Consumer(_queueName + ".queue");
var _consumeDelegate = new _consumeDelegate(_consumer.Consume);
_consumeDelegate.BeginInvoke(null, null);
_consumer.onMessageReceived += HandleMessage;
}
catch (Exception ex)
{
throw new Exception("An error occcurred with running the BH worker application: " + ex);
}
}
private static void HandleMessage(byte[] body)
{
_counter++;
var _body = Encoding.UTF8.GetString(body);
_sendEmail = new EmailService();
var response = _sendEmail.AsyncSendEmail(_endpoint, _body);
//_sendEmail.SyncSendEmail(_endpoint, _body);
Console.WriteLine("***********************************************");
Console.WriteLine("MESSAGE #" + _counter + " FROM QUEUE:" + Environment.NewLine);
Console.WriteLine(_body + Environment.NewLine);
Console.WriteLine("SENT EMAIL RESPONSE CODE : " + response.Result + Environment.NewLine);
Console.WriteLine("***********************************************");
}
}
}