示例#1
0
        static void Main(string[] args)
        {
            try
            {
                _manager = new StitchMessageManager(args);
                _manager.ReceiveHeartbeats  = true;
                _manager.ReceiveExitMessage = true;
                _manager.Start();

                while (true)
                {
                    var msg = _manager.GetNextMessage();
                    if (msg == null)
                    {
                        continue;
                    }

                    if (msg.IsExitMessage())
                    {
                        //Log("Got EXIT message from manager");
                        Environment.Exit(0);
                    }
                    if (msg.IsHeartbeatMessage())
                    {
                        Log($"Got HEARTBEAT message from manager");
                        _manager.SyncHeartbeat(msg.Id);
                        _manager.SendLogs(_manager.CrossStitchParameters.ToString());
                    }
                    else
                    {
                        // TODO: Real processing.
                        Log($"Message received {msg.ChannelName}, {msg.Id}");
                        _manager.AckMessage(msg.Id);
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.ToString());
            }
            Log("Stopped");
        }
示例#2
0
        static void Main(string[] args)
        {
            _manager = new StitchMessageManager(args);
            _manager.ReceiveHeartbeats = true;
            try
            {
                _manager.Start();
                string groupName = _manager.CrossStitchParameters.ApplicationGroupName;

                while (true)
                {
                    var msg = _manager.GetNextMessage();
                    if (msg == null)
                    {
                        continue;
                    }

                    // When we receive a heartbeat, broadcast a message to all stitches in the application group
                    if (msg.IsHeartbeatMessage())
                    {
                        _manager.SyncHeartbeat(msg.Id);
                        _manager.Send(FromStitchMessage.ToGroupData(groupName, "A"));
                    }

                    // When we receive a message "B", log it
                    else if (msg.Data == "B")
                    {
                        _manager.SendLogs(new[] { "Received B" });
                    }

                    // Else, log that we've gotten something unexpected
                    else
                    {
                        _manager.SendLogs(new[] { "Unknown data " + msg.Data });
                    }
                }
            }
            catch (Exception e)
            {
                _manager.SendLogs(new[] { e.ToString() });
            }
        }
示例#3
0
        static void Main(string[] args)
        {
            _manager = new StitchMessageManager(args);
            _manager.ReceiveHeartbeats  = true;
            _manager.ReceiveExitMessage = true;
            try
            {
                _manager.Start();
                while (true)
                {
                    var msg = _manager.GetNextMessage();
                    if (msg == null)
                    {
                        continue;
                    }

                    if (msg.IsExitMessage())
                    {
                        return;
                    }
                    else if (msg.IsHeartbeatMessage())
                    {
                        _manager.SyncHeartbeat(msg.Id);
                        _manager.SendLogs(_manager.CrossStitchArguments.Select(kvp => kvp.Key + "=" + kvp.Value).ToArray());
                    }
                    else
                    {
                        // TODO: Real processing.
                        Log($"Message received {msg.ChannelName}, {msg.Id}");
                        _manager.AckMessage(msg.Id);
                    }
                }
            }
            catch (Exception e)
            {
                Log(e.ToString());
            }
            Log("Stopped");
        }