1
0
mirror of synced 2024-11-14 17:33:49 +00:00
PettingZoo/Model/RabbitMQClientConnection.cs
2016-06-20 12:30:03 +02:00

51 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace PettingZoo.Model
{
public class RabbitMQClientConnection : IConnection
{
private readonly CancellationTokenSource timer;
public RabbitMQClientConnection(ConnectionInfo connectionInfo)
{
timer = new CancellationTokenSource();
var token = timer.Token;
Task.Run(() =>
{
while (true)
{
if (token.IsCancellationRequested)
break;
if (MessageReceived != null)
MessageReceived(null, new MessageReceivedEventArgs(new MessageInfo()
{
RoutingKey = "test",
Body = Encoding.UTF8.GetBytes("{ \"hello\": \"world\" }"),
Properties = new Dictionary<string, string>
{
{ "content-type", "application/json" },
{ "classType", "LEF.Messaging.Internal.ActieNewMessage" }
}
}));
Thread.Sleep(1000);
}
}, token);
}
public void Dispose()
{
timer.Cancel();
}
public event EventHandler<MessageReceivedEventArgs> MessageReceived;
}
}