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_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); } }
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); } }