public void Send(Object message) { // Open the queue. using (var queue = new MessageQueue(_queueName.GetQueueFormatName())) { // Set the formatter to JSON. queue.Formatter = new MsmqMessageFormatter(); // Since we're using a transactional queue, make a transaction. using (MessageQueueTransaction mqt = new MessageQueueTransaction()) { mqt.Begin(); // Create a simple text message. Message myMessage = new Message(message, new MsmqMessageFormatter()); myMessage.Label = message.GetType().FullName; myMessage.ResponseQueue = new MessageQueue(_queueName.GetQueueFormatName()); // Send the message. queue.Send(myMessage, mqt); mqt.Commit(); } } }
public void Send(object message, QueueName queueName) { // Open the queue. using (var queue = new MessageQueue(queueName.GetQueueFormatName())) { SendIternal(message, queue); } }
public void Listen() { try { using (var queue = new MessageQueue(_inputQueue.GetQueueFormatName())) { queue.MessageReadPropertyFilter.ResponseQueue = true; queue.MessageReadPropertyFilter.SourceMachine = true; queue.Formatter = new MsmqMessageFormatter(); while (_continue) { var transaction = new MessageQueueTransaction(); try { transaction.Begin(); Message message = null; try { message = queue.Receive(transaction); var obj = ReadMessageBody(message); if (obj != null && obj is ShutdownBusMessage) { transaction.Commit(); continue; } _logger.Info("Received message {0} from sender {1}@{2}", obj.GetType().FullName, message.ResponseQueue.MachineName, message.ResponseQueue.QueueName); var arrived = NewMessageArrived; if (arrived != null) { arrived(obj); } } catch (HandlerException handlerException) { SendToErrorQueue(message, transaction, handlerException); } catch (DesearilazationException desearilazationException) { SendToErrorQueue(message, transaction, desearilazationException); } transaction.Commit(); } catch (MessageQueueException mqe) { if (mqe.MessageQueueErrorCode == MessageQueueErrorCode.IOTimeout) { continue; } transaction.Abort(); throw; } catch (Exception exception) { transaction.Abort(); throw; } } } } catch (System.Threading.ThreadAbortException abortException) { var wrapper = new Exception(String.Format("Thread listener was aborted in Service Bus [{0}]", _serviceBusName), abortException); _logger.FatalException("", wrapper); } catch (Exception ex) { var wrapper = new Exception(String.Format("Fatal exception in Service Bus [{0}]", _serviceBusName), ex); _logger.FatalException("", wrapper); throw wrapper; } }