static uint GetMessageCount(MessageQueue q) { uint count = 0; var cursor = q.CreateCursor(); var m = PeekWithoutTimeout(q, cursor, PeekAction.Current); if (m != null) { count = 1; while ((PeekWithoutTimeout(q, cursor, PeekAction.Next)) != null) { count++; } } return count; }
static void Main(string[] args) { string serverName; if (args.Length == 0) { Console.WriteLine("Assuming trasa1000 as the server name"); serverName = "trasa1000"; } else { serverName = args[0]; } string queueName = "FormatName:DIRECT=OS:" + serverName + @"\private$\TwitterRequest"; using (connection = ConnectionFactory.Create()) { connection.Open(); cmd = new SqlCommand("FirstFriend", connection) { CommandType = CommandType.StoredProcedure }; cmd.Parameters.Add("@name", SqlDbType.NVarChar, 255); using (var q = new MessageQueue(queueName) { MessageReadPropertyFilter = { AppSpecific = true }, Formatter = new BinaryMessageFormatter() }) { var cursor = q.CreateCursor(); // first one: var m = PeekWithoutTimeout(q, cursor, PeekAction.Current); VerifyMessage(q, m); // loop the rest: while ((m = PeekWithoutTimeout(q, cursor, PeekAction.Next)) != null) { VerifyMessage(q, m); } } } }
// // GET: /Payment/ public ActionResult Index() { IDictionary<PaymentModel, string> model = new Dictionary<PaymentModel, string>(); if (MessageQueue.Exists(".\\Private$\\easyTravelPaymentQueue")) { using (MessageQueue mq = new MessageQueue(".\\Private$\\easyTravelPaymentQueue")) { //mq.Formatter = new XmlMessageFormatter(); ((XmlMessageFormatter)mq.Formatter).TargetTypes = new Type[] { typeof(PaymentModel) }; Cursor c = mq.CreateCursor(); Message[] msgs = mq.GetAllMessages(); if (msgs != null) { foreach (Message m in msgs) { model.Add((PaymentModel)m.Body, m.Label); } } } } else { log.Warn("Queue \".\\Private$\\easyTravelPaymentQueue\" does not exist"); } return View(model); }
/// <summary> /// Reads a message from target queue as a String /// </summary> /// <param name="mq">Message Queue Name</param> public void ReadMessageAsString(System.Messaging.MessageQueue mq) { System.Messaging.Cursor cursor = mq.CreateCursor(); System.Messaging.Message m = PeekWithoutTimeout(mq, cursor, PeekAction.Current); m.Formatter = new XmlMessageFormatter(new String[] { "System.String, mscorlib", }); string body = (string)m.Body; Console.Write(body); Console.Write(Environment.NewLine); { while ((m = PeekWithoutTimeout(mq, cursor, PeekAction.Next)) != null) { // Construct an XMLMessageFormatter m.Formatter = new XmlMessageFormatter(new String[] { "System.String, mscorlib", }); body = (string)m.Body; Console.Write(body); Console.Write(Environment.NewLine); } } }
public MessageInfo PeekAllMessage(StructuredQueue oQueueTemp, int myID, int MaxQuery) { //Message messages = null; MessageInfo MyInfo = new MessageInfo(); try { MessageQueue MessageInQueue = new System.Messaging.MessageQueue(oQueueTemp.sPath, QueueAccessMode.SendAndReceive); System.Messaging.Cursor cursor = MessageInQueue.CreateCursor(); Message m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current); Application.DoEvents(); ArrayList MyMessage = new ArrayList(); MessageInQueue.MessageReadPropertyFilter.Id = true; MessageInQueue.MessageReadPropertyFilter.Priority = true; MessageInQueue.MessageReadPropertyFilter.SentTime = true; MessageInQueue.MessageReadPropertyFilter.MessageType = true; MessageInQueue.MessageReadPropertyFilter.Label = true; MessageInQueue.MessageReadPropertyFilter.Body = true; MessageInQueue.BeginPeek(new TimeSpan(0, 0, 10, 0)); //MessageEnumerator msgQenum = MessageInQueue.GetMessageEnumerator2(); int index = 0; // MyInfo.ID = MessageInQueue.GetAllMessages().Length; if (m != null) { while ((m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current)) != null) //while (msgQenum.MoveNext()) { Application.DoEvents(); if (!(index > MaxQuery)) { // messages = msgQenum.Current; QueueInfos QueueInfo = new QueueInfos(); //QueueInfo.ID = messages.Id; //QueueInfo.SentTime = messages.SentTime.ToString(); //QueueInfo.Body = ReadMessageStream(messages.BodyStream); //QueueInfo.Label = messages.Label; //QueueInfo.Priority = messages.Priority.ToString(); //QueueInfo.MessageID = index.ToString(); //QueueInfo.Transact = oQueueTemp.bTransactional; //QueueInfo.Queue = oQueueTemp.sQueueName; QueueInfo.ID = m.Id; QueueInfo.SentTime = m.SentTime.ToString(); QueueInfo.Body = ReadMessageStream(m.BodyStream); QueueInfo.Label = m.Label; QueueInfo.Priority = m.Priority.ToString(); QueueInfo.MessageID = index.ToString(); QueueInfo.Transact = oQueueTemp.bTransactional; QueueInfo.Queue = oQueueTemp.sQueueName; MyMessage.Add(QueueInfo); } index++; PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Next); } } MyInfo.ID = index; MyInfo.Message = MyMessage; } catch {} return MyInfo; }
public FilteredReceiver(MSMQ.MessageQueue queue, bool isTransactional, string subject) : base(queue, isTransactional) { _subject = subject; _cursor = queue.CreateCursor(); _stopWatch = new Stopwatch(); }
public MessageInfo PeekAllMessage(StructuredQueue oQueueTemp, int myID, int MaxQuery) { //Message messages = null; MessageInfo MyInfo = new MessageInfo(); try { MessageQueue MessageInQueue = new System.Messaging.MessageQueue(oQueueTemp.sPath, QueueAccessMode.SendAndReceive); System.Messaging.Cursor cursor = MessageInQueue.CreateCursor(); Message m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current); Application.DoEvents(); ArrayList MyMessage = new ArrayList(); MessageInQueue.MessageReadPropertyFilter.Id = true; MessageInQueue.MessageReadPropertyFilter.Priority = true; MessageInQueue.MessageReadPropertyFilter.SentTime = true; MessageInQueue.MessageReadPropertyFilter.MessageType = true; MessageInQueue.MessageReadPropertyFilter.Label = true; MessageInQueue.MessageReadPropertyFilter.Body = true; MessageInQueue.BeginPeek(new TimeSpan(0, 0, 10, 0)); //MessageEnumerator msgQenum = MessageInQueue.GetMessageEnumerator2(); int index = 0; // MyInfo.ID = MessageInQueue.GetAllMessages().Length; if (m != null) { while ((m = PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Current)) != null) //while (msgQenum.MoveNext()) { Application.DoEvents(); if (!(index > MaxQuery)) { // messages = msgQenum.Current; QueueInfos QueueInfo = new QueueInfos(); //QueueInfo.ID = messages.Id; //QueueInfo.SentTime = messages.SentTime.ToString(); //QueueInfo.Body = ReadMessageStream(messages.BodyStream); //QueueInfo.Label = messages.Label; //QueueInfo.Priority = messages.Priority.ToString(); //QueueInfo.MessageID = index.ToString(); //QueueInfo.Transact = oQueueTemp.bTransactional; //QueueInfo.Queue = oQueueTemp.sQueueName; QueueInfo.ID = m.Id; QueueInfo.SentTime = m.SentTime.ToString(); QueueInfo.Body = ReadMessageStream(m.BodyStream); QueueInfo.Label = m.Label; QueueInfo.Priority = m.Priority.ToString(); QueueInfo.MessageID = index.ToString(); QueueInfo.Transact = oQueueTemp.bTransactional; QueueInfo.Queue = oQueueTemp.sQueueName; MyMessage.Add(QueueInfo); } index++; PeekWithoutTimeout(MessageInQueue, cursor, PeekAction.Next); } } MyInfo.ID = index; MyInfo.Message = MyMessage; } catch {} return(MyInfo); }