static void Main(string[] args)
        {
            //create a new MSMQ implementation object
            IMessageQueue msmq = new MSMQ("QueueA");
            //bind the implementation to the MessageQueueManager
            IMessageQueueManager mqm = new MessageQueueManager(msmq);

            //create a new message object
            Message m = new Message();

            m.Label   = "test";
            m.Content = "this is test";
            try
            {
                mqm.OpenConnection();
                mqm.SendMessage(m);
                Message retrievedMessage = mqm.RetrieveMessage();
                //send two more method the queue for MessageArrival event test later
                mqm.SendMessage(m);
                mqm.SendMessage(m);
            }
            finally
            {
                mqm.CloseConnection();
            }

            //register the client with the message arrive
            mqm.RegisterMessageArrivalHanlder(new MessageArrivalHandler(RecieveMessage));

            //create a new MQSeries implementation
            IMessageQueue mqseries = new MQSeries("QueueB");

            //bind implementation object to the MessageQueueManager
            mqm = new MessageQueueManager(mqseries);
            try
            {
                mqm.OpenConnection();
                mqm.SendMessage(m);
                Message retrievedMessage = mqm.RetrieveMessage();
            }
            finally
            {
                mqm.CloseConnection();
            }


            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            //Expression<Func<int, int, int>> expression = (a,b) => a + b;

            //BinaryExpression body = (BinaryExpression)expression.Body;
            //ParameterExpression left = (ParameterExpression)body.Left;
            //ParameterExpression right = (ParameterExpression)body.Right;

            //var fun=expression.Compile();



            //int c = fun(2, 3);
            //Console.WriteLine(TimeSpan.MinValue);
            //var key = Console.ReadKey().Key;
            //if (key == ConsoleKey.A)
            //{
            //    Console.WriteLine("A");
            //    while (true)
            //    {
            //        Thread.Sleep(1000);
            //        var msg = Consumer.Receive();
            //            if(string.IsNullOrEmpty(msg))
            //                msg="^_^";
            //        Console.WriteLine(msg);
            //    }

            //}
            //Console.WriteLine("发送!");
            //while (true)
            //{
            //    var msg = Console.ReadLine();
            //    Producer.Send(msg);
            //}

            MSMQ.Createqueue(@"FormatName:DIRECT=tcp:192.168.1.103\private$\Email");
            Console.WriteLine(MSMQ.Msg);
            Thread.Sleep(2000);
            MSMQ.SendMessage("just send");
            Console.WriteLine("send!");
            Thread.Sleep(2000);
            var msg = MSMQ.ReceiveMessage();

            Console.WriteLine(msg);


            Console.ReadKey();
        }