public void Subscribe(bool machineSpecific, string queueName, bool durable, bool temporary, string routingKey, MessageArrivedEventHandler handler) { CheckRabbitMQ(); if (machineSpecific) { queueName = string.Concat(Environment.MachineName, ".", queueName); } if (temporary) { queueName = string.Concat(queueName, ".", Guid.NewGuid().ToString()); } _DALRabbitMQ.Subscribe(queueName, durable, temporary, routingKey, handler); lock (_Subscriptions) { _Subscriptions.Add(new Subscription() { Durable = durable, Handler = handler, QueueName = queueName, RoutingKey = routingKey, Temporary = temporary }); } }
protected virtual void CheckRabbitMQ() { if (_DALRabbitMQ == null) { lock (this) { if (_DALRabbitMQ == null) { _DALRabbitMQ = new DALRabbitMQ(ServiceConfiguration.RabbitMQConnections); if (_Subscriptions.Count > 0) { lock (_Subscriptions) { foreach (Subscription item in _Subscriptions) { _DALRabbitMQ.Subscribe(item.QueueName, item.Durable, item.Temporary, item.RoutingKey, item.Handler); } } } } } } }