我可以将查询绑定到StreamInsight服务器的现有进程吗?

时间:2016-08-09 03:20:15

标签: c# .net c#-4.0 streaminsight

我有StreamInsight服务器

static void Main(string[] args)  
    {  
        // Create an embedded StreamInsight server  
        using (var server = Server.Create("Default"))  
        {  
            // Create a local end point for the server embedded in this program  
            var host = new ServiceHost(server.CreateManagementService());  
            host.AddServiceEndpoint(typeof(IManagementService), new WSHttpBinding(SecurityMode.Message), "http://localhost/MyStreamInsightServer");  
            host.Open();  

            /* The following entities will be defined and available in the server for other clients:  
             * serverApp  
             * serverSource  
             * serverSink  
             * serverProcess  
             */  

            // CREATE a StreamInsight APPLICATION in the server  
            var myApp = server.CreateApplication("serverApp");  

            // DEFINE a simple SOURCE (returns a point event every second)  
            var mySource = myApp.DefineObservable(() => Observable.Interval(TimeSpan.FromSeconds(1))).ToPointStreamable(x => PointEvent.CreateInsert(DateTimeOffset.Now, x), AdvanceTimeSettings.StrictlyIncreasingStartTime);  

            // DEPLOY the source to the server for clients to use  
            mySource.Deploy("serverSource");  

            // Compose a QUERY over the source (return every even-numbered event)  
            var myQuery = from e in mySource  
                          where e % 2 == 0  
                          select e;  

            // DEFINE a simple observer SINK (writes the value to the server console)  
            var mySink = myApp.DefineObserver(() => Observer.Create<long>(x => Console.WriteLine("sink_Server..: {0}", x)));  

            // DEPLOY the sink to the server for clients to use  
            mySink.Deploy("serverSink");  

            // BIND the query to the sink and RUN it  
            using (var proc = myQuery.Bind(mySink).Run("serverProcess"))  
            {  
                // Wait for the user stops the server  
                Console.WriteLine("----------------------------------------------------------------");  
                Console.WriteLine("MyStreamInsightServer is running, press Enter to stop the server");  
                Console.WriteLine("----------------------------------------------------------------");  
                Console.WriteLine(" ");  
                Console.ReadLine();  
            }  
            host.Close();  
        }  
    }  

StreamInsight客户端A:

static void Main(string[] args)  
    {  
        // Connect to the StreamInsight server  
        using (var server = Server.Connect(new System.ServiceModel.EndpointAddress(@"http://localhost/MyStreamInsightServer")))  
        {  
            /* The following entities are expected to be defined in the server:  
             * serverApp0  
             * serverSource0  
             * serverSink0  
             */  
            /* The following entity will be defined in the server by this client:  
             * serverProcess_Client_A  
             */  

            // Get the existing StreamInsight APPLICATION  
            var myApp = server.Applications["serverApp"];  

            // GET the SOURCE from the server  
            var mySource = myApp.GetStreamable<long>("serverSource");  

            // Compose a QUERY on the source (return every even-numbered item + 1000)  
            var myQuery = from e in mySource  
                          where e % 2 == 0  
                          select e + 1000;  

            // GET the SINK from the server  
            var mySink = myApp.GetObserver<long>("serverSink");  

            // BIND the QUERY to the SINK and RUN it  
            using (var proc = myQuery.Bind(mySink).Run("serverProcess_Client_A"))  
            {  
                // Wait for the user to stop the program  
                Console.WriteLine("----------------------------------------------------------------");  
                Console.WriteLine("Client A is running, press Enter to exit the client");  
                Console.WriteLine("----------------------------------------------------------------");  
                Console.WriteLine(" ");  
                Console.ReadLine();  
            }  
        }  
    }

我有另一个客户端B,我想将客户端B的查询绑定到客户端A的此进程(该进程具有名称“serverProcess_Client_A”)。我不想从客户B创建新流程

问题:我可以这样做吗?

另一个问题:我可以将查询绑定到StreamInsight的现有流程吗?

1 个答案:

答案 0 :(得分:1)

我想不到。进程名称对每个客户端都是唯一的。如果对多个客户端使用相同的进程,则会引发“进程已存在”的异常。

相关问题