private void Route(object source, ReceiveCompletedEventArgs result)
        {
            try
            {
                MessageQueue queue = (MessageQueue) source;
                Message message = queue.EndReceive(result.AsyncResult);

                TraceMessage(message);

                // read topic from the message Extension
                byte[] bytes = message.Extension;
                string topic = Encoding.Unicode.GetString(bytes);

                // Look up the target queue for the topic
                MessageQueue topicQueue;

                if (routingTable.TryGetValue(topic, out topicQueue))
                {
                    // Send to the target queue
                    topicQueue.Send(message);
                }
            }
            catch (MessageQueueException mqe)
            {
                Console.WriteLine("{0} {1}", mqe.Message, mqe.MessageQueueErrorCode);
            }

            Receive();
        }
Example #2
0
 static void q_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
     lock (_lock) {
         SendMail((Email)e.Message.Body);
     }
     _q.BeginReceive();
 }
Example #3
0
 /// <summary>
 /// ReceiveCompleted
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 public void ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
     try
     {
         lock (_obj)
         {
             var messageQueue = (MessageQueue)sender;
             var message = messageQueue.EndReceive(e.AsyncResult);
             var messageObj = (LogMessage)message.Body;
             _dbContext.LogMessages.Add(messageObj);
             _dbContext.SaveChanges();
         }
     }
     catch (Exception ex)
     {
         _dbContext.LogMessages.Add(new LogMessage()
         {
             CreatTime = DateTime.Now,
             Status = Status.Error,
             JobName = "MqReceiveError",
             ErrorMsg = ex.Message + ex.StackTrace,
             RequestTime = DateTime.Now
         });
     }
 }
        /// <summary>
        /// Event fires when a message arrives on the queue.  Pulls the message and hands
        /// the information off to the AssignmentManager.ServerAction class to process
        /// </summary>
        public void OnReceiveCompleted(Object source, System.Messaging.ReceiveCompletedEventArgs e)
        {
            ServerAction sa = new ServerAction();

            // grab the queue information
            MessageQueue mq = (MessageQueue)source;

            // grab the message
            System.Messaging.Message m = mq.EndReceive(e.AsyncResult);
            m.Formatter = new System.Messaging.XmlMessageFormatter(new String[] { "System.String" });

            // process the message
            string msgBody = (string)m.Body;

            try
            {
                bool result = sa.ProcessMessage(msgBody, m.Label);
            }
            catch (System.Exception ex)
            {
                System.Diagnostics.EventLog.WriteEntry(this.ServiceName.ToString(), ex.ToString());
            }
            finally
            {
                // continue listening on the queue
                mq.BeginReceive();
            }
        }
        private static void QueueMessageReceived(object sender, ReceiveCompletedEventArgs e)
        {
            try
            {
                MessageQueue msQueue = (MessageQueue)sender;

                //once a message is received, stop receiving
                Message msMessage = msQueue.EndReceive(e.AsyncResult);

                //do something with the message
                Trace.WriteLine("Received message body in MSMQService: " + msMessage.Body + " at " + DateTime.Now);
                Functions.ProcessQueueMessage(msMessage.Body.ToString());
                //set the signal
                count += 1;
                if (count == 10)
                {
                    signal.Set();
                }
                //Restart the receive operation
                // Console.ReadLine();
                //begin receiving again
                msQueue.BeginReceive();
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc.Message);
            }
        }
Example #6
0
        private void ServerQueueOnReceiveCompleted(object sender, ReceiveCompletedEventArgs receiveCompletedEventArgs)
        {
            var queue = (MessageQueue) sender;

            using (Message clientRequest = queue.EndReceive(receiveCompletedEventArgs.AsyncResult))
            {
                var request = clientRequest.Body as BasicMessage;

                if (request != null)
                {
                    Console.WriteLine("Message Received from client:");
                    Console.WriteLine(" - " + request.Content);
                    Console.WriteLine("Sending response in one moment...");
                    Thread.Sleep(1000); // Simulate some long process...

                    using (MessageQueue responseQueue = clientRequest.ResponseQueue) // Note we don't need to know the address.
                    {
                        var response = new BasicMessage
                        {
                            Content = "Server response on " + DateTime.Now.ToShortTimeString()
                        };
                        responseQueue.Send(response);
                    }
                }
            }

            queue.BeginReceive();
        }
 protected virtual void MessageReceived(object sender, ReceiveCompletedEventArgs e)
 {
     lock(messageLock)
     {
         OnResponseReceived(new ResponseReceivedEventArgs((TwitterResponse)e.Message.Body));
     }
 }
        /// <summary>
        /// Finishes the asynchronous receive.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.Messaging.ReceiveCompletedEventArgs"/> instance containing the event data.</param>
        private void FinishReceive(object sender, ReceiveCompletedEventArgs e)
        {
            if (_messageQueue == null) {
                return;
            }

            try
            {
                _messageQueue.EndReceive(e.AsyncResult);
                // receive the current message
                var message = e.Message;
                var messageBody = message.Body as string;
                if (messageBody == null)
                {
                    Log.Warn("msmq message body was invalid");
                    return;
                }

                // convert to an XML wrapper
                var messageInXml = XElement.Parse(messageBody);

                DecodeAndRouteEvent(messageInXml);
            } catch(MessageQueueException) {
            } catch(NullReferenceException) {
            } finally {
                // begin receiving the next message
                _messageQueue.BeginReceive();
            }
        }
 private void Consume(object source, ReceiveCompletedEventArgs result)
 {
     var message = channel.EndReceive(result.AsyncResult);
     message.TraceMessage();
     if (isRunning)
         channel.BeginReceive();
 }
Example #10
0
 static void ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
     Log<Program>.Debug("Receiving message...");
     var message = messageQueue.EndReceive(e.AsyncResult);
     Log<Program>.Info(message.Body.ToString());
     messageQueue.BeginReceive();
 }
        /// <summary>
        /// Evenement declenché à la reception d'un message.
        /// </summary>
        /// <param name="source">Queue</param>
        /// <param name="asyncResult">Message</param>
        private void MyPeekCompleted(Object source, 
            ReceiveCompletedEventArgs asyncResult)
        {
            // Récupère la queue.
            MessageQueue mq = (MessageQueue)source;
            System.Diagnostics.Debug.WriteLine("(Info) Reception d'une demande de reservation");
            try
            {
                // Récupération du message.
                ProjetNet.Modele.ModeleReservation.ReservationHotelVol reservation = (ProjetNet.Modele.ModeleReservation.ReservationHotelVol) mq.EndPeek(asyncResult.AsyncResult).Body;

                WebServiceReservationSoap serviceReservationSOAP = new WebServiceReservationSoapClient();
                ReserverRequestBody requestBody = new ReserverRequestBody(new WebServiceReservation.ReservationHotelVol()
                    {
                        Client = new WebServiceReservation.Client() {
                            FirstName = reservation.Client.FirstName,
                            LastName = reservation.Client.LastName,
                            Mail = reservation.Client.Mail,
                            Phone = reservation.Client.Phone,
                            Address = reservation.Client.Address,
                            City = reservation.Client.City,
                            PostalCode = reservation.Client.PostalCode,
                            Country = reservation.Client.Country
                        },
                        Hotel = new WebServiceReservation.Hotel() {
                            Name = reservation.Hotel.Name,
                            Stars = reservation.Hotel.Stars,
                            Price = reservation.Hotel.Price,
                            City = reservation.Hotel.City,
                            Country = reservation.Hotel.Country
                        },
                        Vol = new WebServiceReservation.Vol() {
                            Name = reservation.Vol.Name,
                            From = reservation.Vol.From,
                            To = reservation.Vol.To,
                            Price = reservation.Vol.Price,
                            Category = reservation.Vol.Category
                        },
                        DateEnd = reservation.DateEnd,
                        DateStart = reservation.DateStart
                    });
                ReserverRequest reserverRequest = new ReserverRequest(requestBody);

                // appel du WS
                serviceReservationSOAP.Reserver(reserverRequest);

                System.Diagnostics.Debug.Write("(Info) Reservation reussie.");
            }
            catch(Exception e)
            {
                System.Diagnostics.Debug.WriteLine("(Erreur) Reservation echouée : ");
                System.Diagnostics.Debug.WriteLine(e.Message);
            }
            finally
            {
                // Relance l'attente d'un message.
                mq.BeginReceive();
            }
        }
Example #12
0
 static void ReceiveQueueMessage(object sender, ReceiveCompletedEventArgs e)
 {
     Log<Program>.Debug("Receiving queue message...");
     var message = messageQueue.EndReceive(e.AsyncResult);
     var queueMessage = message.Body as QueueMessage;
     queueMessage.DoSomeWork();
     messageQueue.BeginReceive();
 }
Example #13
0
		private void HandleMessage (object source, ReceiveCompletedEventArgs args) {
			try {
				MessageQueue q = (MessageQueue) source;
				m = q.EndReceive (args.AsyncResult);
				state = (string) args.AsyncResult.AsyncState;
			} catch (Exception e) {
				failureMessage = e.Message;
			}
		}
Example #14
0
 private void OnReceive(object sender, ReceiveCompletedEventArgs e)
 {
     Message message = _messageQueue.EndReceive(e.AsyncResult);
     foreach (var subscriber in _subscribers)
     {
         subscriber.Invoke(message.Body);
     }
     ReceiveAsyncLoop();
 }
Example #15
0
        private void OnReceived(object sender, ReceiveCompletedEventArgs e)
        {
            if (_shuttingDown)
                return;

            var msg = e.Message;
            _receiver.ReceivedLogEntry((LogEntryDTO) msg.Body);

            _queue.BeginReceive();
        }
Example #16
0
        private void OnMessage(Object source, ReceiveCompletedEventArgs asyncResult)
        {
            var mq = (MessageQueue)source;
            Message message = mq.EndReceive(asyncResult.AsyncResult);

            if (IsConditionFulfilled())
                outQueue1.Send(message);
            else
                outQueue2.Send(message);
            mq.BeginReceive();
        }
Example #17
0
 void q_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
    //处理文件
   var  mq = (MessageQueue)sender;
    Message m = mq.EndReceive(e.AsyncResult);        
    string fileId = m.Label;
    logger.Debug(fileId);
     
     //再次接收
    mq.BeginReceive(MessageQueue.InfiniteTimeout);
 }
Example #18
0
 private static void Queue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
     MessageQueue mq = (MessageQueue)sender;
     var message = mq.EndReceive(e.AsyncResult);
     System.Messaging.XmlMessageFormatter stringFormatter;
     stringFormatter = new System.Messaging.XmlMessageFormatter(
        new string[] { "System.String" });
     message.Formatter = stringFormatter;
     Console.WriteLine(" e.Message:" + message.Body);
     mq.BeginReceive();
 }
Example #19
0
        void requestQueue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            MessageQueue requestQueue = (MessageQueue)sender;
            Message requestMessage = requestQueue.EndReceive(e.AsyncResult);

            try
            {
                Console.WriteLine("Received request");
                Console.WriteLine("\tTime:          {0}", DateTime.Now.ToString("HH:mm:ss.ffffff"));
                Console.WriteLine("\tMessage ID:    {0}", requestMessage.Id);
                Console.WriteLine("\tCorrel:        {0}", requestMessage.CorrelationId);
                Console.WriteLine("\tReply To   :   {0}", "<n/a>");
                Console.WriteLine("\tContents:       {0}", requestMessage.Body.ToString());

                string contents = requestMessage.Body.ToString();
                MessageQueue replyQueue = requestMessage.ResponseQueue;
                Message replyMessage = new Message();
                replyMessage.Body = contents;
                replyMessage.CorrelationId = requestMessage.Id;
                replyQueue.Send(replyMessage);

                Console.WriteLine("Sent reply");
                Console.WriteLine("\tTime:          {0}", DateTime.Now.ToString("HH:mm:ss.ffffff"));
                Console.WriteLine("\tMessage ID:    {0}", replyMessage.Id);
                Console.WriteLine("\tCorrel:        {0}", replyMessage.CorrelationId);
                Console.WriteLine("\tReply To   :   {0}", "<n/a>");
                Console.WriteLine("\tContents:       {0}", replyMessage.Body.ToString());

            }
            catch (Exception)
            {

                Console.WriteLine("Invalid message detected!");
                Console.WriteLine("\tType:          {0}", requestMessage.BodyType);
                Console.WriteLine("\tTime:          {0}", DateTime.Now.ToString("HH:mm:ss.ffffff"));
                Console.WriteLine("\tMessage ID:    {0}", requestMessage.Id);
                Console.WriteLine("\tCorrel:        {0}", "<n/a>");
                Console.WriteLine("\tReply To   :   {0}", "<n/a>");

                requestMessage.CorrelationId = requestMessage.Id;

                controlQueue.Send(requestMessage);

                Console.WriteLine("Send to invalid message queue!");
                Console.WriteLine("\tType:          {0}", requestMessage.BodyType);
                Console.WriteLine("\tTime:          {0}", DateTime.Now.ToString("HH:mm:ss.ffffff"));
                Console.WriteLine("\tMessage ID:    {0}", requestMessage.Id);
                Console.WriteLine("\tCorrel:        {0}", requestMessage.CorrelationId);
                Console.WriteLine("\tReply To   :   {0}", requestMessage.ResponseQueue.Path);
            }

            requestQueue.BeginReceive();
        }
Example #20
0
        private void OnReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult)
        {
            var mq = (MessageQueue)source;

            Message inputMessage = mq.EndReceive(asyncResult.AsyncResult);

            inputMessage.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });

            Message outputMessage = ProcessMessage(inputMessage);
            outputQueue.Send(outputMessage);

            mq.BeginReceive();
        }
Example #21
0
        void replyQueue_ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            replyQueue = (MessageQueue)sender;
            Message replyMessage = replyQueue.EndReceive(e.AsyncResult);

             Console.WriteLine("Received reply");
            Console.WriteLine("\tTime:          {0}", DateTime.Now.ToString("HH:mm:ss.ffffff"));
            Console.WriteLine("\tMessage ID:    {0}", replyMessage.Id);
            Console.WriteLine("\tCorrel:        {0}", replyMessage.CorrelationId);
            Console.WriteLine("\tReply To   :   {0}", "<n/a>");
            Console.WriteLine("\tContents:       {0}", replyMessage.Body.ToString());
            replyQueue.BeginReceive();
        }
        private void Consume(object source, ReceiveCompletedEventArgs result)
        {
            // The Consume method is called on completion of a message being received
            // We need to obtain the message from the result by calling EndRecieve
            Message message = channel.EndReceive(result.AsyncResult);
            message.TraceReceivedMessage();

            // We also want to begin receiving again, unless we have stopped running
            if (isRunning)
            {
                channel.BeginReceive();
            }
        }
        void MessageQueueReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            var messageQueue = (MessageQueue) sender;
            try
            {
                Message message = messageQueue.EndReceive(e.AsyncResult);

                _messageHandler.Handle((IMessage) message.Body);
            }
            finally
            {
                messageQueue.BeginReceive();
            }
        }
Example #24
0
 void Recover(object sender, ReceiveCompletedEventArgs e) {
     var queue = sender as MessageQueue;
     try {
         Message msg = queue.EndReceive(e.AsyncResult);
         SecsMessage secsMsg = msg.Body as SecsMessage;
         if (secsMsg != null)
             _subscription.Handle(secsMsg);
         queue.BeginReceive(TimeSpan.FromSeconds(QUEUE_RECEIVE_TIMEOUT));
     } catch (MessageQueueException) {
         _serverDisposable.RecoverComplete();
         queue.Close();
         MessageQueue.Delete(_queuePath);
     }
 }
Example #25
0
        static void msgQ_RecieveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            lock (lockObject) //mutex
            {
                MailMessageWrapper mailMessageWrapper = (MailMessageWrapper)e.Message.Body;
                MailMessage msg = mailMessageWrapper.BuildMail();
                smtpClient.Send(msg);

                Debug.WriteLine("HASAN JEBENI SAKIC PIZDA MU MATERINA");
                Console.WriteLine("Message recieved: " + mailMessageWrapper.Body);
            }

            msgQ.BeginReceive();
        }
Example #26
0
 /// <summary>
 /// Callback function that is called when a message is picked up
 /// </summary>
 /// <param name="sender">Object that calls the callback</param>
 /// <param name="e">Event arguments</param>
 private void ReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
 {
     try
     {
         Message m = this.MQ.EndReceive(e.AsyncResult);
         this.RaiseMessageReceived(m.Body);
     }
     catch (Exception ex)
     {
     }
     finally
     {
         this.MQ.BeginReceive();
     }
 }
Example #27
0
 public static void mq_ReceiveCompletedReply(object sender, ReceiveCompletedEventArgs e)
 {
     MessageQueue cmq = (MessageQueue)sender;
     try
     {
         System.Messaging.Message msg = cmq.EndReceive(e.AsyncResult);
         var messageLabel = msg.Label;
         var procID = UInt32.Parse(messageLabel);
         GetProcess(procID);
     }
     catch
     {
     }
     cmq.Refresh();
     cmq.BeginReceive();
 }
        //
        // Message receiving handler
        //
        private void qMe_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
        {
            Util.line    lineToDraw = new Util.line();
            MessageQueue mq         = (MessageQueue)sender;

            System.Messaging.Message m = mq.EndReceive(e.AsyncResult);
            if (m.Body.ToString().Length == 1)
            {             // Draw a char
                DrawChar(m.Body.ToString());
            }
            else
            {             // Draw a line
                HP.StringToLine(m.Body.ToString(), ref lineToDraw);
                AddLine(lineToDraw, picture1Graphics);
            }
            mq.BeginReceive();
        }
Example #29
0
        static void MessageQueueReceiveCompleted(object sender, ReceiveCompletedEventArgs e)
        {
            logQueue.EndReceive(e.AsyncResult);
            var message = (string)e.Message.Body;
            Console.WriteLine(message);

            //deserialize to dynamic object, so we can dump whatever properties we want to the database,
            //without needing to change any of this code
            var logEntry = JsonConvert.DeserializeObject<ExpandoObject>(message);
            //Console.WriteLine(logEntry);

            //now that we have this object, we can dump it to mongoDB, right?
            var dict = logEntry.ToDictionary(en => en.Key, en => en.Value);
            mongoDBWriter.WriteEntry(dict);

            DoReceive();
        }
Example #30
0
        private void Consume(object source, ReceiveCompletedEventArgs result)
        {
            try
            {
                var queue = (MessageQueue) source;
                var message = queue.EndReceive(result.AsyncResult);
                if (message != null)
                {
                    message.TraceMessage();
                }
            }
            catch (MessageQueueException mqe)
            {
                Console.WriteLine("{0} {1}", mqe.Message, mqe.MessageQueueErrorCode);
            }

            Receive();
        }
Example #31
0
    private void qOrders_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
    {
        // This event fires when a message is received.

        try
        {
            // Get the message

            Message m;

            m = qOrders.EndReceive(e.AsyncResult);

            // Cast the message body to an object instance
            Server.MSMQOrders o;
            o = (Server.MSMQOrders)m.Body;


            // if we did the following line of code:
            // o.Process()
            // our listening thread would be blocked until
            // it finished. Instead will use the built-in
            // CLR Thread Pool.
            // Note that our MSMQOrders.Process method has to match
            // expected signature defined by the QueueUserWorkItem method.
            // See the documenation for more information.

            ThreadPool.QueueUserWorkItem(new WaitCallback(o.Process));

            // Now continue listening for messages

            this.qOrders.BeginReceive();
        }

        catch (MessageQueueException exp)
        {
            this.EventLog.WriteEntry(exp.Message);
        }

        catch (Exception exp)
        {
            this.EventLog.WriteEntry(exp.Message);
        }
    }
Example #32
0
		public static void ProcessOrder(Object source,ReceiveCompletedEventArgs asyncResult)
		{
			try
			{
				// Connect to the queue.
				MessageQueue Queue = (MessageQueue)source;
				// End the asynchronous receive operation.
				System.Messaging.Message msg = Queue.EndReceive(asyncResult.AsyncResult);
				msg.Formatter = new System.Messaging.XmlMessageFormatter(new Type[] { typeof(PurchaseOrder) });
				PurchaseOrder po = (PurchaseOrder) msg.Body;
                Random statusIndexer = new Random();
                po.Status = (OrderStates)statusIndexer.Next(3);
                Console.WriteLine("Processing {0} ", po);
				Queue.BeginReceive();
			}
			catch (System.Exception ex)
			{
				Console.WriteLine(ex.Message);
			}
		}
        private void Route(object source, ReceiveCompletedEventArgs result)
        {
            try
            {
                var queue = (MessageQueue) source;
                var message = queue.EndReceive(result.AsyncResult);

                TraceMessage(message);

                var topic = Encoding.ASCII.GetString(Convert.FromBase64String(Encoding.ASCII.GetString(message.Extension)));
                Console.WriteLine("Topic is {0}.", topic);
                var topicQueue = routingTable[topic];
                topicQueue.Send(message);
            }
            catch (MessageQueueException mqe)
            {
                Console.WriteLine("{0} {1}", mqe.Message, mqe.MessageQueueErrorCode);
            }

            Receive();
        }
Example #34
0
        private void drawingMQ_ReceiveCompleted(object sender, System.Messaging.ReceiveCompletedEventArgs e)
        {
            System.Messaging.Message m;
            MSMQGraphics.Drawing     d;

            try
            {
                if (e.Message != null)
                {
                    m           = e.Message;
                    m.Formatter = new XmlMessageFormatter(new Type[] { typeof(MSMQGraphics.Drawing), typeof(MSMQGraphics.Line) });
                    d           = (MSMQGraphics.Drawing)m.Body;
                    thisDrawing = d;
                    pictureBox1.Invalidate();
                }
            }
            catch
            {
            }

            drawingMQ.BeginReceive(new TimeSpan(0, 0, 3));
        }