Mercurial > silverbladetech
view Messaging/Client/MainWindow.xaml.cs @ 29:9919ee227c93
msmq added
author | adminsh@apollo |
---|---|
date | Wed, 21 Mar 2012 22:09:18 +0000 |
parents | 4c0dea4760c5 |
children |
line wrap: on
line source
using System; using System.Collections.Generic; using System.Messaging; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using Common; using RabbitMQ.Client; namespace Client { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public const int MessageCount = 10000; public MainWindow() { InitializeComponent(); } private void BtnRabbitClick(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { var cf = new ConnectionFactory {Address = "localhost:" + Settings.RabbitPortNumber}; using (var conn = cf.CreateConnection()) using (var channel = conn.CreateModel()) { for (var i = 0; i < MessageCount; i++) { channel.BasicPublish("amq.direct", Settings.RabbitQueueName, null, Encoding.UTF8.GetBytes("hello from the client!")); } } }); } private void btnMsmq_Click(object sender, RoutedEventArgs e) { Task.Factory.StartNew(() => { var msMq = !MessageQueue.Exists(Settings.MsmqQueueName) ? MessageQueue.Create(Settings.MsmqQueueName) : new MessageQueue(Settings.MsmqQueueName); try { for (var i = 0; i < MessageCount; i++) { msMq.Send("Sending data to MSMQ at " + DateTime.Now.ToString()); } } catch (MessageQueueException ee) { Console.Write(ee.ToString()); } catch (Exception eee) { Console.Write(eee.ToString()); } finally { msMq.Close(); } }); } } }