1
0
mirror of synced 2024-11-15 01:33:51 +00:00
PettingZoo/Model/RabbitMQClientConnection.cs

51 lines
1.5 KiB
C#
Raw Normal View History

2016-06-20 10:30:03 +00:00
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace PettingZoo.Model
2016-06-18 14:50:32 +00:00
{
public class RabbitMQClientConnection : IConnection
{
2016-06-20 10:30:03 +00:00
private readonly CancellationTokenSource timer;
2016-06-18 14:50:32 +00:00
public RabbitMQClientConnection(ConnectionInfo connectionInfo)
{
2016-06-20 10:30:03 +00:00
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);
2016-06-18 14:50:32 +00:00
}
2016-06-18 18:30:12 +00:00
public void Dispose()
{
2016-06-20 10:30:03 +00:00
timer.Cancel();
2016-06-18 18:30:12 +00:00
}
2016-06-20 10:30:03 +00:00
public event EventHandler<MessageReceivedEventArgs> MessageReceived;
2016-06-18 14:50:32 +00:00
}
}