private async void btnWriteTask_Click(object sender, EventArgs e) { if (!double.IsNaN(double.Parse(txtNrThreads.Text.Trim()))) { int total = Int32.Parse(txtNrThreads.Text.Trim()); lblProcessing.Text = "Processing..."; string message = GetMessage(); List<Tuple<string, string>> messageList = new List<Tuple<string, string>>(); for (int i = 0; i < total; i++) { Tuple<string, string> tm = Tuple.Create("message_" + i.ToString(), message); messageList.Add(tm); } TimeSpan inicio = new TimeSpan(DateTime.Now.Ticks); ActiveMQWriter w = new ActiveMQWriter(System.Configuration.ConfigurationManager.AppSettings["ActiveMQURL"], System.Configuration.ConfigurationManager.AppSettings["ActiveMQName"]); await w.WriteMessageListToQueueAsync(messageList, chkPersist.Checked); ; TimeSpan fim = new TimeSpan(DateTime.Now.Ticks); txtResult.Text += "==== Async Output ==== Message size: " + cmbMessageSize.Text + " ==== # Threads: " + txtNrThreads.Text + " \r\n"; txtResult.Text += "Inicio: " + inicio.ToString() + "\r\n"; txtResult.Text += "Fim: " + fim.ToString() + "\r\n"; txtResult.Text += "Total: " + (fim - inicio).ToString() + "\r\n"; lblProcessing.Text = "Completed."; } }
public void CreateQueue() { ActiveMQWriter w = new ActiveMQWriter(this._queueUrl, this._queueName); w.WriteMessageToQueue("DEL", "__DEL__", false); ActiveMQReader r = new ActiveMQReader(this._queueUrl, this._queueName); r.ReadMessage("__DEL__"); }
private void WriteResponseToQueue(string id) { //Task.Factory.StartNew(() => // { ActiveMQWriter w = new ActiveMQWriter(System.Configuration.ConfigurationManager.AppSettings["ActiveMQURL"], System.Configuration.ConfigurationManager.AppSettings["ActiveMQRS"]); w.WriteMessageToQueue(ResponseMessage, id, false); // }); }
private void DoSeach(int numRequests) { StringBuilder resp = new StringBuilder(); ActiveMQWriter w = new ActiveMQWriter(System.Configuration.ConfigurationManager.AppSettings["ActiveMQURL"], System.Configuration.ConfigurationManager.AppSettings["RQQueue"]); string id = Guid.NewGuid().ToString(); w.WriteMessageListToQueue(CreateRequestList(numRequests, id), false); ActiveMQReader r = new ActiveMQReader(System.Configuration.ConfigurationManager.AppSettings["ActiveMQURL"], System.Configuration.ConfigurationManager.AppSettings["RSQueue"]); bool nextMessage = true; int i = 0; int count = 0; while (count <= numRequests * 100) { // Thread.Sleep(100); Tuple<string, string> tup = r.ReadMessage(id); nextMessage = tup.Item1 != null; if (nextMessage) { resp.Append(tup.Item1 + ", "); i++; if (i >= numRequests) break; } count++; } resp.Append("Total = " + i); litResponse.Text = resp.ToString(); r = null; w = null; resp = null; }