示例#1
0
        void client_MessageReceived(object sender, MDS.Client.MessageReceivedEventArgs e)
        {
            var      instance  = GeneralHelper.DeserializeObject(e.Message.MessageData);
            IMessage message   = new DotNetMQ(e.Message);
            var      eventArgs = new MessageReceivedEventArgs(this, message);

            OnReceived(this, eventArgs);
        }
示例#2
0
        static void mdsClient_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            string messageText = Encoding.UTF8.GetString(e.Message.MessageData);

            Console.WriteLine();
            Console.WriteLine("收到消息 : " + messageText);
            Console.WriteLine("消息源    : " + e.Message.SourceApplicationName);
            Console.WriteLine("接收时间    : " + DateTime.Now.ToString());

            e.Message.Acknowledge();
        }
示例#3
0
        /// <summary>
        /// This method handles received messages from other applications via DotNetMQ.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e">Message parameters</param>
        static void MDSClient_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            //Get message
            var messageText = Encoding.UTF8.GetString(e.Message.MessageData);

            //Process message
            Console.WriteLine();
            Console.WriteLine("Text message received : " + messageText);
            Console.WriteLine("Source application    : " + e.Message.SourceApplicationName);

            //Acknowledge that message is properly handled and processed. So, it will be deleted from queue.
            e.Message.Acknowledge();
        }
示例#4
0
        static void MDSClient_MessageReceived(object sender, MessageReceivedEventArgs e)
        {
            //Get message
            var stockQueryMessage = GeneralHelper.DeserializeObject(e.Message.MessageData) as StockQueryMessage;
            if (stockQueryMessage == null)
            {
                return;
            }

            //Write message content
            Console.WriteLine("Stock Query Message for: " + stockQueryMessage.StockCode);

            //Get stock counts from a database...
            int reservedStockCount;
            int totalStockCount;
            switch (stockQueryMessage.StockCode)
            {
                case "S01":
                    reservedStockCount = 14;
                    totalStockCount = 80;
                    break;
                case "S02":
                    reservedStockCount = 0;
                    totalStockCount = 25;
                    break;
                default:
                    reservedStockCount = -1;
                    totalStockCount = -1;
                    break;
            }

            //Create a reply message for stock query
            var stockQueryResult = new StockQueryResultMessage
                                       {
                                           StockCode = stockQueryMessage.StockCode,
                                           ReservedStockCount = reservedStockCount,
                                           TotalStockCount = totalStockCount
                                       };
            
            //Create a MDS response message to send to client
            var responseMessage = e.Message.CreateResponseMessage();
            responseMessage.MessageData = GeneralHelper.SerializeObject(stockQueryResult);

            //Send message
            responseMessage.Send();

            //Acknowledge the original request message. So, it will be deleted from queue.
            e.Message.Acknowledge();
        }
示例#5
0
 static void mdsClient_MessageReceived(object sender, MessageReceivedEventArgs e)
 {
     //Simply acknowledge other received messages
     e.Message.Acknowledge();
 }