public static QueueHost GetHost(string protocol, string host_address, string queueName) { //127.0.0.1:15000 var host = QueueHost.Parse(protocol + ":" + host_address + "?" + queueName); return(host); }
protected override void OnAsyncExecutingWorker(AsyncCallEventArgs e) { base.OnAsyncExecutingWorker(e); try { DataSet ds = new DataSet("RemoteQueue"); ds.ReadXml(filename); dt = ds.Tables[0]; int count = dt.Rows.Count; this.ProgressBar1.Maximum = count; var hostPipe = QueueHost.Parse("ipc:.:nistec_queue_manager?" + queueName); QueueApi Client = new QueueApi(hostPipe); foreach (DataRow dr in dt.Rows) { Client.Enqueue(QueueItem.Create(dr)); this.ProgressBar1.Increment(1); } } catch (Exception ex) { MsgBox.ShowError(ex.Message); } finally { //Closewindow(); } }
public static void SendItem(bool isAsync) { var host = QueueHost.Parse("tcp:127.0.0.1:15000?NC_Bulk"); QueueApi q = QueueClient.GetApi(host); var item = QueueClient.CreateQueueItem("Hello world " + DateTime.Now.ToString("s"), "test"); item.Host = "NC_Bulk"; //IQueueAck ack = null; QueueClient.EnqueueItem(q, item, 0, (IQueueAck ack) => { 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.Id); }); //if (q.IsAsync) //{ // IQueueAck ack = QueueClient.SendItemAsync(q, item, 0); // 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.Id); //} //else //{ // QueueClient.SendItemAsync(q, item, 0, (IQueueAck ack) => // { // 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.Id); // }); //} //var duration = DateTime.Now.Subtract(start); //var milliseconds = duration.TotalMilliseconds; //Console.WriteLine("duration: {0}, item: {1}", milliseconds, item); }
public static QueueHost GetHost(string host_address, string queueName) { //"tcp:127.0.0.1:15000?NC_Quick" var host = QueueHost.Parse("tcp:127.0.0.1:15000?" + queueName); return(host); }
public static void DoSbscriberListener() { var settings = new TcpSettings() { Address = "127.0.0.1", ConnectTimeout = 5000, HostName = "Netcell", Port = 15002, IsAsync = false }; var host = QueueHost.Parse(string.Format("file:{0}:Queues?{1}", Assists.EXECPATH, settings.HostName)); host.CoverMode = CoverMode.FileStream; host.CommitMode = PersistCommitMode.OnMemory; host.ReloadOnStart = true; var listener = new TopicSbscriberListener(host, true) { OnItemReceived = (IQueueItem message) => { Console.WriteLine("State:{0},Arrived:{1},Host:{2},Label:{3}, Identifier:{4}", message.MessageState, message.ArrivedTime, message.Host, message.Label, message.Identifier); return(new QueueAck(Nistec.Messaging.MessageState.Received, message).ToTransStream()); }, OnError = (string message) => { Console.WriteLine("OnError:{0}", message); } }; string logpath = NetlogSettings.GetDefaultPath("topicSubs"); listener.Logger = new Logger(logpath, LoggerMode.Console | LoggerMode.File); listener.InitServerQueue(settings, true); //listener.PausePersistQueue(true); }
//public QueueApi(string queueName) : this() //{ // _QueueName = queueName; // _HostProtocol = HostProtocol.ipc; // RemoteHostAddress = null; // Protocol = NetProtocol.Pipe; //} public QueueApi(string queueName, string hostAddress) : this() { var qh = QueueHost.Parse(hostAddress); _QueueName = queueName; _HostProtocol = qh.Protocol; RemoteHostAddress = qh.Endpoint; RemoteHostPort = qh.Port; Protocol = qh.Protocol.GetProtocol(); }
public QueueHost GetRoutHost() { if (Mode == CoverMode.Rout) { if (TargetPath == null || TargetPath == "") { return(null); } return(QueueHost.Parse(TargetPath)); } return(null); }
public static void PublishItem() { var host = QueueHost.Parse("tcp:127.0.0.1:15000?Netcell"); QueueApi q = QueueClient.GetApi(host); var item = QueueClient.CreateQueueItem("Hello world " + DateTime.Now.ToString("s"), "test"); item.Host = "Netcell"; item.QCommand = QueueCmd.Enqueue; //IQueueAck ack = null; QueueClient.PublishItem(q, item, 0, (IQueueAck ack) => { 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.Id); }); }
static void Main(string[] args) { Console.WriteLine("QueueTasker started..."); var host = QueueHost.Parse("ipc:.:nistec_queue_channel?NC_Quick"); QueueApi q = new QueueApi(host); while (true) { var msg = q.Report(QueueCmdReport.ReportQueueStatistic, "NC_Quick"); Console.WriteLine("State:{0},Creation:{1},Host:{2},Label:{3}", msg.MessageState, msg.Creation, msg.Host, msg.Label); Thread.Sleep(10000); } Console.WriteLine("QueueTasker finished..."); Console.ReadLine(); }
public IQueueAck SendItem(QueueItem item) { try { string address = item.Host;//.Args["HostAddress"]; QueueHost qh = QueueHost.Parse(address); item.Host = qh.HostName; var api = new QueueApi(qh); var ack = api.PublishItem(item); if (!ack.MessageState.IsStateOk()) { Controller.JournalAddItem(item); } return(ack); } catch (Exception ex) { Logger.Exception("Topic Sender Subscriber error ", ex); Controller.JournalAddItem(item); return(new QueueAck(MessageState.FailedEnqueue, item)); } }
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, 0, (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.Enqueue(item, 0); 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); }