public Tweet[] Dequeue()
        {
            string serializedTweet;

            if (!_client.TryReceiveFrameString(TimeSpan.FromSeconds(1), out serializedTweet))
            {
                return(new Tweet[0]);
            }

            var tweet = JsonConvert.DeserializeObject <Tweet>(serializedTweet);

            return(new[] { tweet });
        }
Beispiel #2
0
 public void StartPull(string navn, int antal)
 {
     toRead = antal;
     name   = navn;
     Console.WriteLine(name + " started");
     using (var receiver = new PullSocket(">tcp://localhost:5556"))
     {
         while (toRead > 0)
         {
             string workload = "";
             bool   b        = receiver.TryReceiveFrameString(out workload);
             if (b)
             {
                 //Console.WriteLine(name + " Resived ");
                 Thread.Sleep(2);
                 toRead--;
             }
             else if (toRead != antal && !b)
             {
                 break;
             }
         }
     }
 }
Beispiel #3
0
        private void FanInPubEntry(object n)
        {
            FansInPubRun f;
            string       name = (string)n;

            if (FunInPubRM.ContainsKey(name))
            {
                f = FunInPubRM[name];
            }
            else
            {
                Logging.logger.Error("FunInPubEntry get name failed " + name);
                return;
            }

            PullSocket      pull = new PullSocket();
            PublisherSocket pub  = new PublisherSocket();
            string          le   = "tcp://" + f.PullPoint.ip + ":" + f.PullPoint.port;
            string          pe   = "tcp://*:" + f.PubPoint.port;

            try
            {
                pull.Bind(le);
                pub.Bind(pe);
                f.pull = pull;
                f.pub  = pub;
            }
            catch (Exception err)
            {
                Logging.logger.Error(ModName + " bind funin socket failed " + le + " " + pe + " " + err.Message);
                throw (err);
            }
            string str;
            string outdata;
            bool   result;

            f.Working = true;
            while (f.Running)
            {
                str    = string.Empty;
                result = pull.TryReceiveFrameString(out str);

                outdata = string.Empty;
                if (result == true)
                {
                    try
                    {
                        outdata = Entry4FanInPubData(name, str);

                        if (outdata != null)
                        {
                            pub.SendFrame(outdata);
                        }
                    }
                    catch (Exception err)
                    {
                        Logging.logger.Error("exception occur " + name + err.Message);
                        continue;
                    }
                }

                DelayTime();
            }
            f.Working = false;
            pull.Close();
            pub.Close();
            return;
        }