当前位置: 首页>>代码示例>>C#>>正文


C# MessageQueue.Send方法代码示例

本文整理汇总了C#中System.Messaging.MessageQueue.Send方法的典型用法代码示例。如果您正苦于以下问题:C# MessageQueue.Send方法的具体用法?C# MessageQueue.Send怎么用?C# MessageQueue.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Messaging.MessageQueue的用法示例。


在下文中一共展示了MessageQueue.Send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnAdd_Click

        private void btnAdd_Click(object sender, RoutedEventArgs e)
        {
            string queueName = ConfigurationManager.AppSettings["MSMQLocation"];

            MessageQueue rmTxnQ = new MessageQueue(queueName);

            rmTxnQ.Formatter = new XmlMessageFormatter(new Type[] { typeof(ProcessMessage) });

            foreach (ListBoxItem itm in files.Items)
            {
                MessageQueueTransaction msgTx = new MessageQueueTransaction();
                msgTx.Begin();
                try
                {
                    string argument = "-i \"{0}\" -o \"{1}\" --preset \"" + ConfigurationManager.AppSettings["HandbrakePreset"] + "\"";

                    string destination = txtDestination.Text + "\\" + System.IO.Path.GetFileNameWithoutExtension(itm.ToolTip.ToString()) + ".m4v";

                    ProcessMessage p = new ProcessMessage() { CommandLine = argument, DestinationURL = destination, OrignalFileURL = itm.ToolTip.ToString() };

                    rmTxnQ.Send(p, msgTx);
                    results.Items.Insert(0, string.Format("{0} added to queue", p.OrignalFileURL));

                    msgTx.Commit();
                }
                catch (Exception ex)
                {
                    results.Items.Insert(0, ex.Message);
                    msgTx.Abort();
                }
            }
        }
开发者ID:tiernano,项目名称:HandbrakeCluster,代码行数:32,代码来源:MainWindow.xaml.cs

示例2: ByMSMQ

 static void ByMSMQ()
 {
     Console.WriteLine("Opening MSMQ...");
     //messageQueue = !MessageQueue.Exists(QueueName) ? MessageQueue.Create(QueueName) : new MessageQueue(QueueName);4
     messageQueue = new MessageQueue(QueueName);
     Console.WriteLine("Server is ready");
     Console.WriteLine("Launch client app");
     RSA_public_key_receive();
     Console.WriteLine("Receiving open RSA-key...");
     Console.WriteLine("Making DES-key...");
     des_provider = new DESCryptoServiceProvider();
     des_provider.GenerateKey();
     des_provider.GenerateIV();
     Console.WriteLine("Crypt DES-key with open RSA-key...");
     DES_key = Encrypt_RSA(des_provider.Key);
     Console.WriteLine("Sending encrypted DES-key and initialization vector(IV)...");
     messageQueue.Send(DES_key);
     messageQueue.Send(des_provider.IV);
     Console.WriteLine("Getting data from Access...");
     GetData();
     Console.WriteLine("Crypt data...");
     var myMemoryStream = new MemoryStream();
     EncryptAndSerialize(myMemoryStream, data_to_recieve.ToArray());
     Console.WriteLine("Transfering data...");
     //Console.WriteLine("length = " + myMemoryStream.Length);
     messageQueue.Send(myMemoryStream.ToArray());
     Console.WriteLine("Successfull");
     Console.ReadKey();
 }
开发者ID:DashaSerdyuk,项目名称:main,代码行数:29,代码来源:Program.cs

示例3: Main

        static void Main(string[] args)
        {
            Console.WriteLine("Simple Text");
            Console.WriteLine("Input for MSMQ Message:");
            string input = Console.ReadLine();

            MessageQueue queue = new MessageQueue(@".\private$\test");

            queue.Send(input);

            Console.WriteLine("Press Enter to continue");
            Console.ReadLine();

            Console.WriteLine("Output for MSMQ Queue");
            Console.WriteLine(queue.Receive().Body.ToString());
            Console.ReadLine();

            Console.WriteLine("Complex Text");

            User tester = new User();
            tester.Birthday = DateTime.Now;
            tester.Name = "Test Name";
            queue.Send(tester);

            Console.WriteLine("Output for MSMQ Queue");
            User output = (User)queue.Receive().Body;
            Console.WriteLine(output.Birthday.ToShortDateString());
            Console.ReadLine();
        }
开发者ID:davidalmas,项目名称:Samples,代码行数:29,代码来源:Program.cs

示例4: StringMessageFormatter

        public void StringMessageFormatter()
        {
            var ids = new List<string>();
            var mq = new MessageQueue(@".\private$\QMM_");

            mq.Formatter = new StringMessageFormatter();
            mq.Send("12345");
            mq.Send("23456");

            mq.Dispose();
            mq = null;

            mq = new MessageQueue(@".\private$\QMM_");

            for (int i = 0; i < 3; i++)
            {
                Message msg = null;
                try
                {
                    msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }

                if (msg != null)
                {
                    msg.Formatter = new StringMessageFormatter();
                    Console.WriteLine(msg.Body);
                }
            }
        }
开发者ID:RickStrahl,项目名称:Westwind.QueueMessageManager,代码行数:33,代码来源:MsMqTests.cs

示例5: WriteReadMessage

        public void WriteReadMessage()
        {
            var ids = new List<string>();
            var mq = new MessageQueue(@".\private$\QMM_");

            
            mq.Send("12345");
            mq.Send("23456");

            var msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
            if (msg != null)
                Console.WriteLine(msg.Body);

            mq.Dispose();
            mq = null;

            mq = new MessageQueue(@".\private$\QMM_");
            
            msg = mq.Receive(new TimeSpan(0, 0, 0, 0, 1));
            if (msg != null)
            {
                msg.Formatter = new XmlMessageFormatter(new Type[] {typeof (string)});
                Console.WriteLine(msg.Body);
            }
        }
开发者ID:RickStrahl,项目名称:Westwind.QueueMessageManager,代码行数:25,代码来源:MsMqTests.cs

示例6: Main

        static void Main(string[] args)
        {
            //Connect to the queue
            MessageQueue orderQueue = new MessageQueue("FormatName:Direct=OS:" + ConfigurationManager.AppSettings["orderQueueName"]);

            // Create the purchase order
            PurchaseOrder po = new PurchaseOrder();
            po.customerId = "somecustomer.com";
            po.poNumber = Guid.NewGuid().ToString();

            PurchaseOrderLineItem lineItem1 = new PurchaseOrderLineItem();
            lineItem1.productId = "Blue Widget";
            lineItem1.quantity = 54;
            lineItem1.unitCost = 29.99F;

            PurchaseOrderLineItem lineItem2 = new PurchaseOrderLineItem();
            lineItem2.productId = "Red Widget";
            lineItem2.quantity = 890;
            lineItem2.unitCost = 45.89F;

            po.orderLineItems = new PurchaseOrderLineItem[2];
            po.orderLineItems[0] = lineItem1;
            po.orderLineItems[1] = lineItem2;

            // submit the purchase order
            Message msg = new Message();
            msg.Body = po;
            msg.Label = "SubmitPurchaseOrder";

            //Submit an Order.
            using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required))
            {
                
                orderQueue.Send(msg, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope.Complete();
                
            }
            Console.WriteLine("Placed the order:{0}", po);

            // submit the purchase order
            Message msg2 = new Message();
            msg2.Body = po.poNumber;
            msg2.Label = "CancelPurchaseOrder";

            //Cancel the Order.
            using (TransactionScope scope2 = new TransactionScope(TransactionScopeOption.Required))
            {
                
                orderQueue.Send(msg2, MessageQueueTransactionType.Automatic);
                // Complete the transaction.
                scope2.Complete();
               
            }
            Console.WriteLine("Cancelled the Order: {0}", po.poNumber);
            Console.WriteLine("Press <ENTER> to terminate client.");
            Console.ReadLine();
        }
开发者ID:ssickles,项目名称:archive,代码行数:58,代码来源:client.cs

示例7: Send

        /// <summary>
        /// Sends the given <paramref name="message"/>
        /// </summary>
        public void Send(TransportMessage message, SendOptions sendOptions)
        {
            var address = sendOptions.Destination;
            var queuePath = NServiceBus.MsmqUtilities.GetFullPath(address);

            var transactionType = GetTransactionTypeForSend();
            if (message.TimeToBeReceived < MessageQueue.InfiniteTimeout && WillUseTransactionThatSupportsMultipleOperations(sendOptions.EnlistInReceiveTransaction, transactionType))
            {
                throw new Exception($"Failed to send message to address: {address.Queue}@{address.Machine}. Sending messages with a custom TimeToBeReceived is not supported on transactional MSMQ.");
            }

            try
            {
                using (var q = new MessageQueue(queuePath, false, Settings.UseConnectionCache, QueueAccessMode.Send))
                {
                    using (var toSend = NServiceBus.MsmqUtilities.Convert(message))
                    {
                        toSend.UseDeadLetterQueue = Settings.UseDeadLetterQueue;
                        toSend.UseJournalQueue = Settings.UseJournalQueue;
                        toSend.TimeToReachQueue = Settings.TimeToReachQueue;

                        var replyToAddress = sendOptions.ReplyToAddress ?? message.ReplyToAddress;

                        if (replyToAddress != null)
                        {
                            toSend.ResponseQueue = new MessageQueue(NServiceBus.MsmqUtilities.GetReturnAddress(replyToAddress.ToString(), address.ToString()));
                        }

                        if (sendOptions.EnlistInReceiveTransaction && UnitOfWork.HasActiveTransaction())
                        {
                            q.Send(toSend, UnitOfWork.Transaction);
                        }
                        else
                        {
                            q.Send(toSend, transactionType);
                        }
                    }
                }
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
                {
                    var msg = address == null
                                     ? "Failed to send message. Target address is null."
                                     : string.Format("Failed to send message to address: [{0}]", address);

                    throw new QueueNotFoundException(address, msg, ex);
                }

                ThrowFailedToSendException(address, ex);
            }
            catch (Exception ex)
            {
                ThrowFailedToSendException(address, ex);
            }
        }
开发者ID:xqfgbc,项目名称:NServiceBus,代码行数:60,代码来源:MsmqMessageSender.cs

示例8: SendtoMsmq

 void SendtoMsmq(MessageQueue msmqQueue, Message msmqMessage)
 {
     if (Transaction.Current == null)
     {
         msmqQueue.Send(msmqMessage, MessageQueueTransactionType.Single);
     }
     else
     {
         msmqQueue.Send(msmqMessage, MessageQueueTransactionType.Automatic);
     }
 }
开发者ID:Azure-Samples,项目名称:azure-servicebus-messaging-samples,代码行数:11,代码来源:DurableSender.cs

示例9: Send

        /// <summary>
        /// Sends the given <paramref name="message"/>
        /// </summary>
        public void Send(TransportMessage message, SendOptions sendOptions)
        {
            var address = sendOptions.Destination;
            var queuePath = NServiceBus.MsmqUtilities.GetFullPath(address);
            try
            {
                using (var q = new MessageQueue(queuePath, false, Settings.UseConnectionCache, QueueAccessMode.Send))
                {
                    using (var toSend = NServiceBus.MsmqUtilities.Convert(message))
                    {
                        toSend.UseDeadLetterQueue = Settings.UseDeadLetterQueue;
                        toSend.UseJournalQueue = Settings.UseJournalQueue;

                        var replyToAddress = sendOptions.ReplyToAddress ?? message.ReplyToAddress;
                        
                        if (replyToAddress != null)
                        {
                            toSend.ResponseQueue = new MessageQueue(NServiceBus.MsmqUtilities.GetReturnAddress(replyToAddress.ToString(), address.ToString()));
                        }


                        if (sendOptions.EnlistInReceiveTransaction && UnitOfWork.HasActiveTransaction())
                        {
                            q.Send(toSend, UnitOfWork.Transaction);
                        }
                        else
                        {
                            q.Send(toSend, GetTransactionTypeForSend());
                        }
                    }
                }
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
                {
                    var msg = address == null
                                     ? "Failed to send message. Target address is null."
                                     : string.Format("Failed to send message to address: [{0}]", address);

                    throw new QueueNotFoundException(address, msg, ex);
                }

                ThrowFailedToSendException(address, ex);
            }
            catch (Exception ex)
            {
                ThrowFailedToSendException(address, ex);
            }
        }
开发者ID:ogdenmd,项目名称:NServiceBus,代码行数:53,代码来源:MsmqMessageSender.cs

示例10: Setup

        public void Setup()
        {
            if (!MessageQueue.Exists(_queueName))
                MessageQueue.Create(_queueName, true);

            _queue = new MessageQueue(_queueName, false, true, QueueAccessMode.SendAndReceive);
            _queue.Purge();

            _firstMsg = new Message {Label = 0.Days().FromUtcNow().ToString()};
            _secondMsg = new Message {Label = 1.Days().FromUtcNow().ToString()};

            _queue.Send(_firstMsg, MessageQueueTransactionType.Single);
            _queue.Send(_secondMsg, MessageQueueTransactionType.Single);
        }
开发者ID:KevM,项目名称:MassTransit,代码行数:14,代码来源:Receive_Specs.cs

示例11: An_undecipherable_blob_should_be_discarded

		public void An_undecipherable_blob_should_be_discarded()
		{
			var formatName = Endpoint.Address.Uri.GetInboundFormatName();
			using (var queue = new MessageQueue(formatName, QueueAccessMode.Send))
			{
				queue.Send("This is just crap, it will cause pain");
			}

			try
			{
				Endpoint.Receive(context =>
					{
						IConsumeContext<PingMessage> pingContext;
						context.TryGetContext(out pingContext);

						Assert.Fail("Receive should have thrown a serialization exception");

						return null;
					}, TimeSpan.Zero);
			}
			catch (Exception ex)
			{
				Assert.Fail("Did not expect " + ex.GetType() + " = " + ex.Message);
			}

			Assert.AreEqual(0, EndpointAddress.GetMsmqMessageCount(), "Endpoint was not empty");
			Assert.AreEqual(1, ErrorEndpointAddress.GetMsmqMessageCount(), "Error endpoint did not contain bogus message");
		}
开发者ID:cstick,项目名称:MassTransit,代码行数:28,代码来源:Receive_Specs.cs

示例12: SendMessageToQueue

        public void SendMessageToQueue(string queueName, CallDisposition data)
        {
            var msMq = new MessageQueue(queueName);
            var myMessage = new System.Messaging.Message();
            myMessage.Formatter = new XmlMessageFormatter(new Type[] { typeof(CallDisposition) });
            myMessage.Body = data;
            myMessage.Label = "MessageQueue";
            
            myMessage.UseJournalQueue = true;
            myMessage.Recoverable = true;

            //message send acknowledgement. 
            myMessage.AdministrationQueue = new MessageQueue(@".\Private$\MessageAcknowledgeQueue");
            myMessage.AcknowledgeType = AcknowledgeTypes.PositiveReceive | AcknowledgeTypes.PositiveArrival;

            try
            {
                msMq.Send(myMessage);
                Console.WriteLine("Message sent successfully!");

            }
            catch (MessageQueueException e)
            {
                Console.Write(e.ToString());
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }
            finally
            {
                msMq.Close();
            }
        }
开发者ID:adhikaribipin,项目名称:MSMQTesting,代码行数:34,代码来源:SendMsgToQueue.cs

示例13: Main

        static void Main()
        {
            Console.WriteLine("Using straight xml serialization and msmq to test interop.");
            Console.WriteLine("To exit, enter 'q'. Press 'Enter' to send a message.");

            string queueName = string.Format("FormatName:DIRECT=OS:{0}\\private$\\OrderServiceInputQueue", Environment.MachineName);
            var label = "<CorrId></CorrId><WinIdName>UDI_MOBILE_2\\Administrator</WinIdName>";

            var q = new MessageQueue(queueName);

            var serializer = new XmlSerializer(typeof(OrderMessage), new[] { typeof(OrderLine) });

            while ((Console.ReadLine().ToLower()) != "q")
            {
                var m1 = new OrderMessage
                             {
                                 PurchaseOrderNumber = Guid.NewGuid().ToString(),
                                 ProvideBy = DateTime.Now,
                                 PartnerId = Guid.NewGuid(),
                                 OrderLines = new[] {new OrderLine {ProductId = Guid.NewGuid(), Quantity = 10F}},
                                 Done = true
                             };

                var toSend = new Message();
                serializer.Serialize(toSend.BodyStream, m1);
                toSend.ResponseQueue = new MessageQueue(string.Format("FormatName:DIRECT=OS:{0}\\private$\\PartnerInputQueue", Environment.MachineName));
                toSend.Label = label;

                q.Send(toSend, MessageQueueTransactionType.Single);
                Console.WriteLine("Sent order {0}", m1.PurchaseOrderNumber);
            }
        }
开发者ID:VirtueMe,项目名称:NNUG.NServiceBusSample,代码行数:32,代码来源:Program.cs

示例14: ShouldRemoveSubscriptionsInNonTransactionalMode

        public async Task ShouldRemoveSubscriptionsInNonTransactionalMode()
        {
            var address = MsmqAddress.Parse("MsmqSubscriptionStorageQueueTests.PersistNonTransactional");
            var queuePath = address.PathWithoutPrefix;

            if (MessageQueue.Exists(queuePath))
            {
                MessageQueue.Delete(queuePath);
            }

            MessageQueue.Create(queuePath, false);

            using (var queue = new MessageQueue(queuePath))
            {
                queue.Send(new Message
                {
                    Label = "subscriber",
                    Body = typeof(MyMessage).AssemblyQualifiedName
                }, MessageQueueTransactionType.None);
            }

            var storage = new MsmqSubscriptionStorage(new MsmqSubscriptionStorageQueue(address, false));

            storage.Init();

            await storage.Unsubscribe(new Subscriber("subscriber", "subscriber"), new MessageType(typeof(MyMessage)), new ContextBag());

            using (var queue = new MessageQueue(queuePath))
            {
                CollectionAssert.IsEmpty(queue.GetAllMessages());
            }
        }
开发者ID:Particular,项目名称:NServiceBus,代码行数:32,代码来源:MsmqSubscriptionStorageIntegrationTests.cs

示例15: Send

        public void Send(string Msg)
        {
            string QueuePath = ".\\private$\\SLS_Allcai_Task_Alipay_" + MessageType;

            if (!MessageQueue.Exists(QueuePath))
            {
                return;
            }

            MessageQueue mq = null;

            try
            {
                mq = new MessageQueue(QueuePath);
            }
            catch
            {
                return;
            }

            if (mq == null)
            {
                return;
            }

            System.Messaging.Message m = new System.Messaging.Message();

            m.Body = Msg;
            m.Formatter = new System.Messaging.BinaryMessageFormatter();

            mq.Send(m);
        }
开发者ID:ichari,项目名称:ichari,代码行数:32,代码来源:Message.cs


注:本文中的System.Messaging.MessageQueue.Send方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。