static void PurgeInputQueue(string inputQueueName) { using (var queue = new MsmqMessageQueue(inputQueueName)) { queue.PurgeInputQueue(); } }
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.CorrelationId, "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.CorrelationId, "super-unique!!!!111"); } }
MsmqMessageQueue GetQueue(string queueName) { var queue = new MsmqMessageQueue(queueName).PurgeInputQueue(); disposables.Add(queue); return queue; }
public static void UseMsmqInOneWayClientMode(this TransportConfigurer configurer) { var msmqMessageQueue = MsmqMessageQueue.Sender(); configurer.UseSender(msmqMessageQueue); var gag = new OneWayClientGag(); configurer.UseReceiver(gag); configurer.UseErrorTracker(gag); }
void StartWorker() { using (var messageQueue = new MsmqMessageQueue(listenQueue)) { while (keepRunning) { DoWork(messageQueue); } } }
protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers) { var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue(); serializer = new JsonMessageSerializer(); var bus = new RebusBus(activateHandlers, messageQueue, messageQueue, new InMemorySubscriptionStorage(), this, serializer, new SagaDataPersisterForTesting(), new TrivialPipelineInspector()); buses.Add(bus); return bus; }
static void DoIt(TransportConfigurer configurer, string inputQueueName, string errorQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName, errorQueueName); configurer.UseSender(msmqMessageQueue); configurer.UseReceiver(msmqMessageQueue); }
protected override void DoSetUp() { serializer = new JsonMessageSerializer(); senderQueue = new MsmqMessageQueue(SenderQueueName); destinationQueue = NewRawMsmqQueue(DestinationQueueName); senderQueue.PurgeInputQueue(); destinationQueue.Purge(); TrackDisposable(senderQueue); }
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; }
static void DoItEncrypted(TransportConfigurer configurer, string inputQueueName, string iv, string key, string errorQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName, errorQueueName); var encryptionFilter = new RijndaelEncryptionTransportDecorator(msmqMessageQueue, msmqMessageQueue, iv, key); configurer.UseSender(encryptionFilter); configurer.UseReceiver(encryptionFilter); }
public LoadBalancerService Start() { if (!destinationQueueNames.Any()) { throw new InvalidOperationException("Cannot start load balancer without adding at least one worker input queue!"); } log.Info("Starting load balancer"); queue = new MsmqMessageQueue(inputQueueName); workers.AddRange(Enumerable.Range(1, numberOfWorkers) .Select(i => new LoadBalancerWorker(queue, i, GetNextDestination))); return this; }
public void CheckSendPerformance(int count) { var queue = new MsmqMessageQueue("test.msmq.performance", "error").PurgeInputQueue(); var transportMessageToSend = new TransportMessageToSend { Headers = new Dictionary<string, string>(), Body = new byte[1024], Label = "this is just a label" }; var stopwatch = Stopwatch.StartNew(); count.Times(() => queue.Send("test.msmq.performance", transportMessageToSend)); var totalSeconds = stopwatch.Elapsed.TotalSeconds; Console.WriteLine("Sending {0} messages took {1:0} s - that's {2:0} msg/s", count, totalSeconds, count/totalSeconds); }
protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, string errorQueueName) { var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue(); MsmqUtil.PurgeQueue(errorQueueName); serializer = new JsonMessageSerializer(); var bus = new RebusBus(activateHandlers, messageQueue, messageQueue, storeSubscriptions, storeSagaData, this, serializer, pipelineInspector, new ErrorTracker(errorQueueName), null, new ConfigureAdditionalBehavior()); EnsureProperDisposal(bus); EnsureProperDisposal(messageQueue); return bus; }
public void SetUp() { serializer = new JsonMessageSerializer(); senderQueue = new MsmqMessageQueue(MsmqMessageQueue.PrivateQueue("test.msmq.tx.sender")); destinationQueuePath = MsmqMessageQueue.PrivateQueue("test.msmq.tx.destination"); if (!MessageQueue.Exists(destinationQueuePath)) MessageQueue.Create(destinationQueuePath, transactional: true); destinationQueue = new MessageQueue(destinationQueuePath) { Formatter = new RebusTransportMessageFormatter() }; senderQueue.PurgeInputQueue(); destinationQueue.Purge(); }
public void SubscriptionWorks() { var inputQueueName = "test.subscriber"; var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue(); serializer = new JsonMessageSerializer(); var subscriptionStorage = new InMemorySubscriptionStorage(); var bus = new RebusBus(new HandlerActivatorForTesting(), messageQueue, messageQueue, subscriptionStorage, new SagaDataPersisterForTesting(), this, serializer, new TrivialPipelineInspector()); bus.Start(); bus.Subscribe<TheMessage>("test.subscriber"); Thread.Sleep(500); Assert.AreEqual("test.subscriber", subscriptionStorage.GetSubscribers(typeof(TheMessage))[0]); }
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!"); }
static void DoIt(TransportConfigurer configurer, string inputQueueName, string errorQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName); var errorQueuePath = MsmqUtil.GetPath(errorQueueName); MsmqUtil.EnsureMessageQueueExists(errorQueuePath); MsmqUtil.EnsureMessageQueueIsTransactional(errorQueuePath); configurer.UseSender(msmqMessageQueue); configurer.UseReceiver(msmqMessageQueue); configurer.UseErrorTracker(new ErrorTracker(errorQueueName)); }
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!"); }
static void DoIt(RebusTransportConfigurer configurer, string inputQueueName, string errorQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName); // since these operations only make sense to perform on a local queue, we'll skip it if the error queue is remote // (read http://blogs.msdn.com/b/johnbreakwell/archive/2008/07/31/checking-if-msmq-queues-exist-is-hard-work-so-should-you-bother.aspx // for more info...) if (MsmqUtil.IsLocal(errorQueueName)) { var errorQueuePath = MsmqUtil.GetPath(errorQueueName); MsmqUtil.EnsureMessageQueueExists(errorQueuePath); MsmqUtil.EnsureMessageQueueIsTransactional(errorQueuePath); } configurer.UseSender(msmqMessageQueue); configurer.UseReceiver(msmqMessageQueue); configurer.UseErrorTracker(new ErrorTracker(errorQueueName)); }
static void DoIt(RebusTransportConfigurer configurer, string inputQueueName, string errorQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName); var errorQueuePath = MsmqUtil.GetPath(errorQueueName); MsmqUtil.EnsureMessageQueueExists(errorQueuePath); MsmqUtil.EnsureMessageQueueIsTransactional(errorQueuePath); configurer.UseSender(msmqMessageQueue); configurer.UseReceiver(msmqMessageQueue); configurer.UseErrorTracker(new ErrorTracker(errorQueueName)); }
protected RebusBus CreateBus(string inputQueueName, IActivateHandlers activateHandlers, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData, string errorQueueName) { var messageQueue = new MsmqMessageQueue(inputQueueName, errorQueueName).PurgeInputQueue(); MsmqUtil.PurgeQueue(errorQueueName); serializer = new JsonMessageSerializer(); var bus = new RebusBus(activateHandlers, messageQueue, messageQueue, storeSubscriptions, storeSagaData, this, serializer, pipelineInspector); toDispose.Add(bus); toDispose.Add(messageQueue); return bus; }
static void DoIt(TransportConfigurer configurer, string inputQueueName) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName); configurer.UseSender(msmqMessageQueue); configurer.UseReceiver(msmqMessageQueue); }
public LoadBalancerWorker(MsmqMessageQueue queue, int workerNumber, Func<string> getNextDestination) { this.queue = queue; this.workerNumber = workerNumber; this.getNextDestination = getNextDestination; workerThread = new Thread(DoWork); log.Info("Starting load balancer worker {0}", workerNumber); workerThread.Start(); }
static void DoItEncrypted(TransportConfigurer configurer, string inputQueueName, string iv, string key) { if (string.IsNullOrEmpty(inputQueueName)) { throw new ConfigurationErrorsException("You need to specify an input queue."); } var msmqMessageQueue = new MsmqMessageQueue(inputQueueName); var encryptionFilter = new EncryptionFilter(msmqMessageQueue, msmqMessageQueue, iv, key); configurer.UseSender(encryptionFilter); configurer.UseReceiver(encryptionFilter); }
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!"); }
public void SetUp() { disposables = new List<IDisposable>(); serializer = new JsonMessageSerializer(); senderQueue = new MsmqMessageQueue("test.msmq.tx.sender"); destinationQueueName = "test.msmq.tx.destination"; destinationQueue = NewRawMsmqQueue(destinationQueueName); senderQueue.PurgeInputQueue(); destinationQueue.Purge(); disposables.Add(senderQueue); disposables.Add(destinationQueue); }
Tuple<ISendMessages, IReceiveMessages> MsmqTransports() { var sender = new MsmqMessageQueue(@"test.contracts.sender").PurgeInputQueue(); var receiver = new MsmqMessageQueue(@"test.contracts.receiver").PurgeInputQueue(); return new Tuple<ISendMessages, IReceiveMessages>(sender, receiver); }
public Tuple<ISendMessages, IReceiveMessages> GetQueue(string inputQueueName) { var messageQueue = new MsmqMessageQueue(inputQueueName).PurgeInputQueue(); disposables.Add(messageQueue); return new Tuple<ISendMessages, IReceiveMessages>(messageQueue, messageQueue); }
static void Run(Parameters parameters) { if (string.IsNullOrWhiteSpace(parameters.ErrorQueueName)) { throw new NiceException("Please specify the name of an error queue"); } using (var tx = new TransactionScope()) { var transactionContext = new AmbientTransactionContext(); if (!MessageQueue.Exists(MsmqUtil.GetPath(parameters.ErrorQueueName))) { throw new NiceException("The MSMQ queue '{0}' does not exist!", parameters.ErrorQueueName); } var msmqMessageQueue = new MsmqMessageQueue(parameters.ErrorQueueName, allowRemoteQueue: true); var allTheMessages = GetAllTheMessages(msmqMessageQueue, transactionContext); foreach (var message in allTheMessages) { var transportMessageToSend = message.ToForwardableMessage(); try { if (!transportMessageToSend.Headers.ContainsKey(Headers.SourceQueue)) { throw new NiceException( "Message {0} does not have a source queue header - it will be moved back to the input queue", message.Id); } var sourceQueue = (string)transportMessageToSend.Headers[Headers.SourceQueue]; if (parameters.AutoMoveAllMessages.GetValueOrDefault()) { msmqMessageQueue.Send(sourceQueue, transportMessageToSend, transactionContext); Print("Moved {0} to {1}", message.Id, sourceQueue); } else { var answer = PromptChar(new[] { 'y', 'n' }, "Would you like to move {0} to {1}? (y/n)", message.Id, sourceQueue); if (answer == 'y') { msmqMessageQueue.Send(sourceQueue, transportMessageToSend, transactionContext); Print("Moved {0} to {1}", message.Id, sourceQueue); } else { msmqMessageQueue.Send(msmqMessageQueue.InputQueueAddress, transportMessageToSend, transactionContext); Print("Moved {0} to {1}", message.Id, msmqMessageQueue.InputQueueAddress); } } } catch (NiceException e) { Print(e.Message); msmqMessageQueue.Send(msmqMessageQueue.InputQueueAddress, transportMessageToSend, transactionContext); } } if (parameters.DryRun.GetValueOrDefault()) { Print("Aborting queue transaction"); return; } if (!parameters.Interactive) { tx.Complete(); return; } var commitAnswer = PromptChar(new[] {'y', 'n'}, "Would you like to commit the queue transaction?"); if (commitAnswer == 'y') { Print("Committing queue transaction"); tx.Complete(); return; } Print("Queue transaction aborted"); } }
public void SetUp() { serializer = new JsonMessageSerializer(); senderQueue = new MsmqMessageQueue("test.msmq.tx.sender", "error"); destinationQueueName = "test.msmq.tx.destination"; destinationQueuePath = MsmqMessageQueue.PrivateQueue(destinationQueueName); if (!MessageQueue.Exists(destinationQueuePath)) { var messageQueue = MessageQueue.Create(destinationQueuePath, transactional: true); messageQueue.SetPermissions(Thread.CurrentPrincipal.Identity.Name, MessageQueueAccessRights.FullControl); } destinationQueue = new MessageQueue(destinationQueuePath) { Formatter = new RebusTransportMessageFormatter(), MessageReadPropertyFilter = RebusTransportMessageFormatter.PropertyFilter, }; senderQueue.PurgeInputQueue(); destinationQueue.Purge(); }