-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueueHelper.cs
34 lines (32 loc) · 1.09 KB
/
QueueHelper.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
using NLog;
using System;
using System.Globalization;
using System.Messaging;
using System.Runtime.CompilerServices;
namespace msmq_to_sqs
{
public class QueueHelper
{
private static Logger logger = LogManager.GetCurrentClassLogger();
[MethodImpl(MethodImplOptions.Synchronized)]
public static void Send(string m, string queue)
{
MessageQueue sQueue = new MessageQueue(queue);
sQueue.Formatter = new ActiveXMessageFormatter();
MessageQueueTransaction transaction = new MessageQueueTransaction();
transaction.Begin();
Message message = new Message();
message.Body = m;
message.Formatter = new ActiveXMessageFormatter();
sQueue.Send(message, DateTime.Now.ToString(CultureInfo.InvariantCulture), transaction);
transaction.Commit();
}
public static Message Receive(string queue)
{
MessageQueue rQueue = new MessageQueue(queue);
rQueue.Formatter = new ActiveXMessageFormatter();
logger.Info("checking {0}", queue);
return rQueue.Receive();
}
}
}