/// <inheritdoc /> public override async Task Init(CancellationToken cancellationToken = default(CancellationToken)) { if (Interlocked.Exchange(ref _initialized, 1) == 0) { _directory.Refresh(); var directoryAlreadyExisted = _directory.Exists; if (!directoryAlreadyExisted) { _directory.Create(); _directory.Refresh(); } _deadLetterDirectory.Refresh(); if (!_deadLetterDirectory.Exists) { _deadLetterDirectory.Create(); _deadLetterDirectory.Refresh(); } cancellationToken.ThrowIfCancellationRequested(); await DiagnosticService.EmitAsync( new FilesystemEventBuilder(this, DiagnosticEventType.ComponentInitialization) { Detail = "Filesystem queue initialized", Queue = QueueName, Path = _directory.FullName }.Build(), cancellationToken); } await base.Init(cancellationToken); }
private async void MoveToDeadLetterDirectory(FileInfo file) { try { var deadLetter = new FileInfo(Path.Combine(_deadLetterDirectory.FullName, file.Name)); file.MoveTo(deadLetter.FullName); await DiagnosticService.EmitAsync( new FilesystemEventBuilder(this, DiagnosticEventType.DeadLetter) { Detail = "Message file moved to dead letter directory", Queue = QueueName, Path = deadLetter.FullName }.Build()); } catch (Exception ex) { DiagnosticService.Emit( new FilesystemEventBuilder(this, DiagnosticEventType.DeadLetterError) { Detail = "Error moving message file to dead letter directory", Queue = QueueName, Path = file.FullName, Exception = ex }.Build()); } }
private async Task OnMaximumAttemptsExceeded(object source, MessageQueueEventArgs args) { await UpdateQueuedMessage(args.QueuedMessage, DateTime.UtcNow); await DiagnosticService.EmitAsync( new SQLEventBuilder(this, DiagnosticEventType.DeadLetter) { Detail = "Message abandoned", Message = args.QueuedMessage.Message, Queue = QueueName }.Build()); }
private async Task DeleteMessageFile(QueuedMessage queuedMessage) { var message = queuedMessage.Message; var headers = message.Headers; var pattern = headers.MessageId + "*.pmsg"; var matchingFiles = _directory.EnumerateFiles(pattern); foreach (var matchingFile in matchingFiles) { matchingFile.Delete(); await DiagnosticService.EmitAsync( new FilesystemEventBuilder(this, FilesystemEventType.MessageFileDeleted) { Detail = "Message file deleted", Message = message, Queue = QueueName, Path = matchingFile.FullName }.Build()); } }
private async Task MoveToDeadLetterDirectory(QueuedMessage queuedMessage) { var message = queuedMessage.Message; var headers = message.Headers; var pattern = headers.MessageId + "*.pmsg"; var matchingFiles = _directory.EnumerateFiles(pattern); foreach (var matchingFile in matchingFiles) { var messageFile = new MessageFile(matchingFile); var deadLetter = await messageFile.MoveTo(_deadLetterDirectory); await DiagnosticService.EmitAsync( new FilesystemEventBuilder(this, DiagnosticEventType.DeadLetter) { Detail = "Message file deleted", Message = message, Queue = QueueName, Path = deadLetter.File.FullName }.Build()); } }
private async Task CreateMessageFile(QueuedMessage queuedMessage) { var message = queuedMessage.Message; var principal = queuedMessage.Principal; var securityToken = await _securityTokenService.NullSafeIssue(principal, message.Headers.Expires); var storedMessage = message.WithSecurityToken(securityToken); if (_messageEncryptionService != null) { storedMessage = await _messageEncryptionService.Encrypt(storedMessage); } var messageFile = await MessageFile.Create(_directory, storedMessage); await DiagnosticService.EmitAsync( new FilesystemEventBuilder(this, FilesystemEventType.MessageFileCreated) { Detail = "Message file created", Message = message, Queue = QueueName, Path = messageFile.File.FullName }.Build()); }