public CancellationTokenSource StartService() { IList <IMQConnection> messageConnectors = null; var tokenSource = new CancellationTokenSource(); string Queues = Configuration.Create().GetSection("Filas").Value; var t = Task.Run(() => { try { messageConnectors = new List <IMQConnection>(); foreach (string queueName in Queues.Replace(",", ";").Split(';')) { IMQConnection messageConnector; messageConnector = MessageConnectionFactory.CriarConexaoMQ(); messageConnector.MessageArrived += MessageConnector_MessageArrived; messageConnector.ListenTo(queueName); messageConnectors.Add(messageConnector); } ServiceStatus = ServiceStatus.Running; do { if (tokenSource.Token.IsCancellationRequested) { ServiceStatus = ServiceStatus.Cancelling; } Thread.Sleep(300); } while (ServiceStatus == ServiceStatus.Running); } catch (Exception ex) { throw; } finally { foreach (IMQConnection messageConnector in messageConnectors) { messageConnector.Dispose(); } ServiceStatus = ServiceStatus.Stopped; } }, tokenSource.Token); return(tokenSource); }
public void GetConnection_Returns_Expected_IConnection(MessageConnectionType type, string username, IPAddress ip, int port, ConnectionOptions options) { var f = new MessageConnectionFactory(); var c = f.GetMessageConnection(type, username, ip, port, options); Assert.Equal(type, c.Type); Assert.Equal(username, c.Username); Assert.Equal(ip, c.IPAddress); Assert.Equal(port, c.Port); Assert.Equal(options, c.Options); }
public Base() { messageConnector = MessageConnectionFactory.CriarConexaoMQ(); }