コード例 #1
0
        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);
        }
コード例 #2
0
        public static void DoListnning(QueueHost host)
        {
            var adapter = new QueueAdapter()
            {
                Source  = host,
                IsAsync = true,
                //Interval = 100,
                ConnectTimeout    = 5000,
                ReadTimeout       = 180000,
                WorkerCount       = 1,
                EnableDynamicWait = true,
                QueueAction       = (message) =>
                {
                    Console.WriteLine("State:{0},Arrived:{1},Host:{2},Label:{3}, Identifier:{4}, Duration:{5}", message.MessageState, message.ArrivedTime.ToString("yyyy-MM-dd HH:mm:ss.fff"), message.Host, message.Label, message.Identifier, message.Duration);

                    var    body  = message.GetBody();
                    string sbody = body == null ? "null" : body.ToString();
                    Console.WriteLine("body: " + sbody);
                },
                FaultAction = (message) =>
                {
                    Console.WriteLine(message);
                }
            };

            QueueListener listener = new QueueListener(adapter, 100);
            string        logpath  = NetlogSettings.GetDefaultPath("qlistener");

            listener.Logger = new Logger(logpath);
            //listener.ErrorOcurred += Listener_ErrorOcurred;
            //listener.MessageReceived += Listener_MessageReceived;
            listener.Start();

            //QueueApi api = new QueueApi(host);
            //api.ReceiveCompleted += api_ReceiveCompleted;

            ////api.Listener(10000, message_ReceiveCompleted);
            //bool KeepAlive = true;
            //int connectTimeout=10000;

            //    while (KeepAlive)
            //    {
            //        api.Receive(connectTimeout,message_ReceiveCompleted);
            //        Thread.Sleep(100);
            //    }



            //Console.WriteLine("QueueListener finished...");
            //Console.ReadLine();
        }