public virtual void Publish(TEvnt eventToBePublished) { if (string.IsNullOrEmpty(this.QueuePath)) { return; } Utilities.CreateIfNotExist(new MessageQueueRequest { IsTransactional = this.IsTransactional, QueuePath = this.QueuePath }); using (var mq = new System.Messaging.MessageQueue(this.QueuePath)) { mq.Formatter = _formatter; if (this.Logger != null) { this.Logger.Debug(string.Format("Sending Event '{1}' to Message Queue '{0}' with publisher '{2}'", this.QueuePath, typeof(TEvnt).Name, this.GetType().Name)); } mq.Send(eventToBePublished); if (this.Logger != null) { this.Logger.Debug(string.Format("Sent Event '{1}' to Message Queue '{0}' with publisher '{2}'", this.QueuePath, typeof(TEvnt).Name, this.GetType().Name)); } mq.Close(); } }
protected virtual void Dispose(bool disposing) { if (System.Threading.Interlocked.Exchange(ref _disposed, 1) == 0) { if (disposing) { if (!_cts.IsCancellationRequested) { _cts.Cancel(); } _mq.ReceiveCompleted -= OnMQReceiveCompleted; _mq.Close(); _mq.Dispose(); } } }