public void Should_use_string_empty_label_when_no_convention_configured() { var queueName = "emptyLabelTest"; var path = $@".\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(new MsmqSettings(), pairs => string.Empty); var bytes = new byte[] { 1 }; var headers = new Dictionary <string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default); messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()); var messageLabel = ReadMessageLabel(path); Assert.IsEmpty(messageLabel); } finally { MsmqHelpers.DeleteQueue(path); } }
public void Should_use_string_empty_label_when_no_convention_configured() { var queueName = "emptyLabelTest"; var path = $@".\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(new MsmqSettings(), pairs => string.Empty); var bytes = new byte[] { 1 }; var headers = new Dictionary<string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default); messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()); var messageLabel = ReadMessageLabel(path); Assert.IsEmpty(messageLabel); } finally { MsmqHelpers.DeleteQueue(path); } }
public void Should_set_label_when_convention_configured() { var queueName = "labelTest"; var path = $@"{RuntimeEnvironment.MachineName}\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(new MsmqSettings(), _ => "mylabel"); var bytes = new byte[] { 1 }; var headers = new Dictionary <string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default); messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()); var messageLabel = ReadMessageLabel(path); Assert.AreEqual("mylabel", messageLabel); } finally { MsmqHelpers.DeleteQueue(path); } }
public void Should_set_label_when_convention_configured() { var queueName = "labelTest"; var path = $@"{RuntimeEnvironment.MachineName}\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(new MsmqSettings(), _ => "mylabel"); var bytes = new byte[] { 1 }; var headers = new Dictionary<string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default); messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()); var messageLabel = ReadMessageLabel(path); Assert.AreEqual("mylabel", messageLabel); } finally { MsmqHelpers.DeleteQueue(path); } }
public DueDelayedMessagePoller(MsmqMessageDispatcher dispatcher, IDelayedMessageStore delayedMessageStore, int numberOfRetries, Action <string, Exception, CancellationToken> criticalErrorAction, string timeoutsErrorQueue, Dictionary <string, string> faultMetadata, TransportTransactionMode transportTransactionMode, TimeSpan timeToTriggerFetchCircuitBreaker, TimeSpan timeToTriggerDispatchCircuitBreaker, int maximumRecoveryFailuresPerSecond, string timeoutsQueueTransportAddress) { txOption = transportTransactionMode == TransportTransactionMode.TransactionScope ? TransactionScopeOption.Required : TransactionScopeOption.RequiresNew; this.delayedMessageStore = delayedMessageStore; errorQueue = timeoutsErrorQueue; this.faultMetadata = faultMetadata; this.timeoutsQueueTransportAddress = timeoutsQueueTransportAddress; this.numberOfRetries = numberOfRetries; this.dispatcher = dispatcher; fetchCircuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("MsmqDelayedMessageFetch", timeToTriggerFetchCircuitBreaker, ex => criticalErrorAction("Failed to fetch due delayed messages from the storage", ex, tokenSource?.Token ?? CancellationToken.None)); dispatchCircuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("MsmqDelayedMessageDispatch", timeToTriggerDispatchCircuitBreaker, ex => criticalErrorAction("Failed to dispatch delayed messages to destination", ex, tokenSource?.Token ?? CancellationToken.None)); failureHandlingCircuitBreaker = new FailureRateCircuitBreaker("MsmqDelayedMessageFailureHandling", maximumRecoveryFailuresPerSecond, ex => criticalErrorAction("Failed to execute error handling for delayed message forwarding", ex, tokenSource?.Token ?? CancellationToken.None)); signalQueue = Channel.CreateBounded <bool>(1); taskQueue = Channel.CreateBounded <Task>(2); }
public DelayedDeliveryPump(MsmqMessageDispatcher dispatcher, DueDelayedMessagePoller poller, IDelayedMessageStore storage, MessagePump messagePump, string errorQueue, int numberOfRetries, Action <string, Exception, CancellationToken> criticalErrorAction, TimeSpan timeToWaitForStoreCircuitBreaker, Dictionary <string, string> faultMetadata, TransportTransactionMode transportTransactionMode) { this.dispatcher = dispatcher; this.poller = poller; this.storage = storage; this.numberOfRetries = numberOfRetries; this.faultMetadata = faultMetadata; pump = messagePump; this.errorQueue = errorQueue; txOption = transportTransactionMode == TransportTransactionMode.TransactionScope ? TransactionScopeOption.Required : TransactionScopeOption.RequiresNew; storeCircuitBreaker = new RepeatedFailuresOverTimeCircuitBreaker("DelayedDeliveryStore", timeToWaitForStoreCircuitBreaker, ex => criticalErrorAction("Failed to store delayed message", ex, CancellationToken.None)); }
static Message DispatchMessage(string queueName, MsmqSettings settings = null, DeliveryConstraint deliveryConstraint = null, Func <IReadOnlyDictionary <string, string>, string> messageLabelGenerator = null) { if (settings == null) { settings = new MsmqSettings(null); } if (messageLabelGenerator == null) { messageLabelGenerator = _ => string.Empty; } settings.LabelGenerator = messageLabelGenerator; var path = $@".\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(settings); var bytes = new byte[] { 1 }; var headers = new Dictionary <string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); var deliveryConstraints = new List <DeliveryConstraint>(); if (deliveryConstraint != null) { deliveryConstraints.Add(deliveryConstraint); } var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), DispatchConsistency.Default, deliveryConstraints); messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), new ContextBag()); using (var queue = new MessageQueue(path)) using (var message = queue.Receive(TimeSpan.FromSeconds(5))) { return(message); } } finally { MsmqHelpers.DeleteQueue(path); } }
static async Task <Message> DispatchMessage(string queueName, MsmqTransport settings = null, DispatchProperties dispatchProperties = null, CancellationToken cancellationToken = default) { if (settings == null) { settings = new MsmqTransport(); } var path = $@".\private$\{queueName}"; try { MsmqHelpers.DeleteQueue(path); MsmqHelpers.CreateQueue(path); var messageSender = new MsmqMessageDispatcher(settings, "timeouts"); var bytes = new byte[] { 1 }; var headers = new Dictionary <string, string>(); var outgoingMessage = new OutgoingMessage("1", headers, bytes); dispatchProperties = dispatchProperties ?? new DispatchProperties(); var transportOperation = new TransportOperation(outgoingMessage, new UnicastAddressTag(queueName), dispatchProperties); await messageSender.Dispatch(new TransportOperations(transportOperation), new TransportTransaction(), cancellationToken); using (var queue = new MessageQueue(path)) using (var message = queue.Receive(TimeSpan.FromSeconds(5))) { return(message); } } finally { MsmqHelpers.DeleteQueue(path); } }