public void WorksWhenMovingToErrorQueue() { using (var messageQueue = new MsmqMessageQueue("error")) { // make sure error queue is empty messageQueue.PurgeInputQueue(); adapter.Handle<Request>(req => { throw new ApplicationException("oh crap"); }); var request = new Request(); bus.AttachHeader(request, Headers.UserName, "super-unique!!!!111"); bus.SendLocal(request); // let it fail Thread.Sleep(2.Seconds()); var receivedTransportMessage = messageQueue.ReceiveMessage(new NoTransaction()); receivedTransportMessage.ShouldNotBe(null); var serializer = new JsonMessageSerializer(); var message = serializer.Deserialize(receivedTransportMessage); message.Headers.ShouldContainKeyAndValue(Headers.UserName, "super-unique!!!!111"); } }
static List<ReceivedTransportMessage> GetAllTheMessages(MsmqMessageQueue msmqMessageQueue, ITransactionContext transactionContext) { var messages = new List<ReceivedTransportMessage>(); ReceivedTransportMessage transportMessage; while ((transportMessage = msmqMessageQueue.ReceiveMessage(transactionContext)) != null) { messages.Add(transportMessage); } return messages; }
public void CanSendAndReceiveMessageToQueueOnLocalhost() { // arrange var queue = new MsmqMessageQueue("test.msmq.loca.input").PurgeInputQueue(); disposables.Add(queue); const string localHostQualifiedQueueName = "test.msmq.loca.input@localhost"; // act queue.Send(localHostQualifiedQueueName, new TransportMessageToSend { Body = Encoding.UTF8.GetBytes("yo dawg!") }, new NoTransaction()); Thread.Sleep(200); // assert var receivedTransportMessage = queue.ReceiveMessage(new NoTransaction()); receivedTransportMessage.ShouldNotBe(null); Encoding.UTF8.GetString(receivedTransportMessage.Body).ShouldBe("yo dawg!"); }
public void CanSendAndReceiveMessageToQueueOnMachineSpecifiedByIp() { var ipAddress = GuessOwnIpAddress(); // arrange var queue = new MsmqMessageQueue("test.msmq.ip.input").PurgeInputQueue(); disposables.Add(queue); var ipQualifiedName = "test.msmq.ip.input@" + ipAddress; // act queue.Send(ipQualifiedName, new TransportMessageToSend { Body = Encoding.UTF8.GetBytes("yo dawg!") }, new NoTransaction()); Thread.Sleep(1.Seconds()); // assert var receivedTransportMessage = queue.ReceiveMessage(new NoTransaction()); receivedTransportMessage.ShouldNotBe(null); Encoding.UTF8.GetString(receivedTransportMessage.Body).ShouldBe("yo dawg!"); }
public void CanSendAndReceiveMessageToQueueOnSpecificMachine() { // arrange var queue = new MsmqMessageQueue("test.msmq.mach.input").PurgeInputQueue(); disposables.Add(queue); var machineQualifiedQueueName = "test.msmq.mach.input@" + Environment.MachineName; // act queue.Send(machineQualifiedQueueName, new TransportMessageToSend { Body = Encoding.UTF8.GetBytes("yo dawg!") }, new NoTransaction()); Thread.Sleep(200); // assert var receivedTransportMessage = queue.ReceiveMessage(new NoTransaction()); receivedTransportMessage.ShouldNotBe(null); Encoding.UTF8.GetString(receivedTransportMessage.Body).ShouldBe("yo dawg!"); }