public static IQueueAck SendItem(QueueApi q, QueueItem item, int connectTimeOut) { var ack = q.Send(item, connectTimeOut); //Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}, item:{6}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration, item); return(ack); }
//protected override Listener CreateListener(AdapterProperties lp) //{ // return new ListenerQ(this, lp); //} //public override Listener Find(string hostName) //{ // if (hostName == null) // { // throw new ArgumentNullException("Find.hostName"); // } // return Listeners.Where(q => q.Source.HostName == hostName).FirstOrDefault<Listener>(); //} //public void Abort(Ptr ptr) //{ // var listener = EnsureListener(_adapter.Source); // listener.Abort(ptr); //} //public void Commit(Ptr ptr) //{ // var listener = EnsureListener(_adapter.Source); // listener.Commit(ptr); //} #endregion //bool _isalive; //void TaskWorker() //{ // _isalive = true; // // Start queue listener... // Console.WriteLine("QListener started..."); // while (_isalive) // { // try // { // if (Interlocked.Read(ref delay) > 0) // { // Thread.Sleep((int)delay); // Interlocked.Exchange(ref delay, 0); // } // Monitor.Enter(_locker, ref lockWasTaken); // switch (_AdapterOperation) // { // case AdapterOperations.Transfer: // Task.Factory.StartNew(() => ReceiveTo()); // break; // case AdapterOperations.Async: // Task.Factory.StartNew(() => ReceiveAsync()); // break; // case AdapterOperations.Sync: // Message item = Receive(); // if (item != null) // { // if (_Action != null) // { // Task.Factory.StartNew(() => _Action(item)); // } // else // Task.Factory.StartNew(() => DoMessageReceived(item)); // } // break; // } // } // catch (Exception ex) // { // Console.WriteLine("QListener error: " + ex.Message); // Task.Factory.StartNew(() => DoErrorOcurred(ex.Message)); // } // finally // { // if (lockWasTaken) Monitor.Exit(_locker); // } // Thread.Sleep(_Interval); // } // Console.WriteLine("QListener stoped..."); //} //public class ListenerQ : Listener //{ // AdapterBase _Adapter; // internal ListenerQ(IListenerHandler owner, AdapterProperties properties) // : base(owner, properties) // { // _Adapter = properties.GetAdapter(); // _Adapter.ConnectTimeout = properties.ConnectTimeout; // } protected override IQueueAck Send(QueueItem message) { return(_api.Send(message)); }
public static void SendMulti(bool isAsync, int maxItems) { long counter = 0; int interval = 1; DateTime start = DateTime.Now; var host = QueueHost.Parse("tcp:127.0.0.1:15000?NC_Bulk"); QueueApi q = QueueClient.GetApi(host); //IQueueAck ack = null; for (int i = 0; i < maxItems; i++) { var item = QueueClient.CreateQueueItem("Hello world " + DateTime.Now.ToString("s"), i.ToString()); Task.Factory.StartNew(() => { if (isAsync) { q.SendAsync(item, 50000000, (ack) => { Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration); Interlocked.Increment(ref counter); }); } else { var ack = q.Send(item, 50000000); Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier, ack.Duration); Interlocked.Increment(ref counter); } }); //Thread.Sleep(interval); } while (Interlocked.Read(ref counter) < (maxItems)) { Thread.Sleep(interval); } //while (true) //{ // if (counter > maxItems) // break; // Interlocked.Increment(ref counter); // Task.Factory.StartNew(() => SendItem(q, Interlocked.Read(ref counter))); // //SendItem(q,counter); // //QueueItem msg = new QueueItem(); // //msg.SetBodyText("Hello world " + DateTime.Now.ToString("s")); // //q.SendAsync(msg, 5000, (ack) => // //{ // // Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}", ack.MessageState, ack.Creation, ack.Host, ack.Label, ack.Identifier); // //}); // //Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}, Identifier:{4}", ack.MessageState,ack.Creation,ack.Host,ack.Label, ack.Identifier); // //counter++; // Thread.Sleep(interval); //} var duration = DateTime.Now.Subtract(start); var milliseconds = duration.TotalMilliseconds; Console.WriteLine("duration: {0}, count: {1}, itemDuration: {2}", milliseconds - (interval * counter), counter, (milliseconds - (interval * counter)) / counter); }