private void StartSSEListeningBooks(IActorRef actor)
        {
            Log.Info(
                $"Read Events From: {Context.System.Settings.Config.GetString("container.bootcamp.einbuchen.url")}");
            var evr = new EventSourceReader(
                new Uri(Context.System.Settings.Config.GetString("container.bootcamp.einbuchen.url")));

            /*
             * open the object via reflection otherwise the last event id could not.
             * This is important to read only new events and not all on scs restart.
             */
            var prop = evr.GetType().GetField("LastEventId", BindingFlags.NonPublic | BindingFlags.Instance);

            prop.SetValue(evr, booksLastMessageId);
            evr.Start();

            evr.MessageReceived += (sender, e) => actor.Tell(e);
            evr.Disconnected    += async(sender, e) =>
            {
                await Task.Delay(e.ReconnectDelay);

                // Reconnect to the same URL
                evr.Start();
            };
        }
Beispiel #2
0
        protected override void StartListener()
        {
            object symbolsStr = string.Join(",", symbols);

            _eventSource = new EventSourceReader(new Uri($"https://cloud-sse.iexapis.com/{client.Options.Version}/deep?token={client.Options.PublicToken}&symbols={symbolsStr}&channels=trades"));
            _eventSource.MessageReceived += HandleTradeEvent;
            _eventSource.Disconnected    += async(object sender, DisconnectEventArgs e) => {
                Console.WriteLine($"Retry after {e.ReconnectDelay}ms - Error: {e.Exception.Message}");
                await Task.Delay(e.ReconnectDelay);

                _eventSource.Start(); // Reconnect to the same URL
            };
            _eventSource.Start();
            started = true;
        }
Beispiel #3
0
        static void Main(string[] args)
        {
            string url = _kaazingSSE;

            if (args.Length > 0)
            {
                url = args[0];
            }

            var evt = new EventSourceReader(new Uri(url), new Http2CustomHandler()).Start();

            evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => {
                Console.WriteLine($"{e.Message}");
            };
            evt.Disconnected += async(object sender, DisconnectEventArgs e) => {
                Console.WriteLine($"Retry: {e.ReconnectDelay} - Error");
                await Task.Delay(e.ReconnectDelay);

                evt.Start(); // Reconnect to the same URL
            };

            Console.WriteLine($"Opening SSE Stream: {url}");
            while (true)
            {
                Thread.Sleep(1000);
            }
        }
Beispiel #4
0
        public void StartWalletWatcher()
        {
            var lastToken = _wallet.LastToken;

            if (string.IsNullOrWhiteSpace(lastToken))
            {
                _url += "?cursor=now";
            }
            else
            {
                _url += $"?cursor={lastToken}";
            }

            AppSettings.Logger.Information($"Starting watcher with cursor at {lastToken}");

            Console.Write("Waiting for incoming payments...\n");
            var eventStream = new EventSourceReader(new Uri(_url)).Start();

            eventStream.MessageReceived += (sender, response) => ShowOperationResponse(response);
            eventStream.Disconnected    += async(sender, response) =>
            {
                if (!response.Exception.Message.Contains("GATEWAY_TIMEOUT"))
                {
                    Console.WriteLine($"Retry: {response.ReconnectDelay} - Error: {response.Exception}");
                }

                await Task.Delay(response.ReconnectDelay);

                eventStream.Start(); // Reconnect to the same URL
            };
        }
        public LucidNotifications(LucidHelper helper)
        {
            EventSource = new EventSourceReader(new Uri(helper.BuildNotificationsUri())).Start();
            EventSource.Disconnected += async(object sender, DisconnectEventArgs e) => {
                await Task.Delay(e.ReconnectDelay);

                EventSource.Start();
            };
        }
        /// <summary>
        /// Starts the Event Listener
        /// </summary>
        public void StartListen()
        {
            _evt = new EventSourceReader(UriBuilder.GetEventStreamUri(_serverUri)).Start();
            _evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => NewEvent(e);
            _evt.Disconnected    += async(object sender, DisconnectEventArgs err) => {
                _isConnected = false;
                connectedEventBus?.Invoke(false); // Lost the eventbus, handle thiswith reconnection after 3 secs.
                Console.WriteLine($"Retry in: {err.ReconnectDelay} - Error: {err.Exception}");
                await Task.Delay(err.ReconnectDelay);

                _evt.Start(); // Reconnect to the same URL
            };
        }
        internal void ConnectToSseEndPoint(string sseurl)
        {
            var evt = new EventSourceReader(new Uri(sseurl)).Start();

            logger.Log("Connected to SSE endpoint for push notifications, press any key to abort.");
            Task.Run(() => { Spin(); });
            evt.MessageReceived += (object sender, EventSourceMessageEventArgs ev) => RenderResponse(JsonConvert.DeserializeObject <Rootobject>(ev.Message));
            evt.Disconnected    += async(object sender, DisconnectEventArgs e) =>
            {
                logger.Log($"Reconnecting - Error: {e.Exception.Message}");
                await Task.Delay(e.ReconnectDelay);

                evt.Start(); // Reconnect to the same URL
            };
        }
Beispiel #8
0
        /// <inheritdoc />
        public void ReceiveTransmissionsMessages(Action <EventSourceMessageEventArgs> onReceive, Action <DisconnectEventArgs> onDisconnection)
        {
            EventSourceReader evt = new EventSourceReader(new Uri($"{this.ApiUrl}/subscribe/transmissions")).Start();

            evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) =>
            {
                onReceive(e);
            };
            evt.Disconnected += async(object sender, DisconnectEventArgs e) =>
            {
                onDisconnection(e);
                await Task.Delay(e.ReconnectDelay);

                evt.Start(); // Reconnect to the same URL
            };
        }
Beispiel #9
0
        private void subscribeServerEvents()
        {
            var host = DotNetEnv.Env.GetString("SERVER_ADDRESS") + "/api/stream/solver";

            var evt = new EventSourceReader(new Uri(host)).Start();

            evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => {
                Task.Run(() => {
                    var parsedMessage = JObject.Parse(e.Message);

                    var type = parsedMessage["type"];

                    if (type == null)
                    {
                        return;
                    }

                    switch (type.ToString())
                    {
                    case "issue":
                        InsertUnassignedIssue(parsedMessage["issue"]);
                        break;

                    case "question":
                        UpdateQuestion(parsedMessage["question"]);
                        break;

                    case "assign":
                        RemoveIssue(parsedMessage["issue"]);
                        break;

                    default:
                        break;
                    }
                });
            };
            evt.Disconnected += async(object sender, DisconnectEventArgs e) => {
                if (e.ReconnectDelay != 3000)
                {
                    Console.WriteLine($"Retry: {e.ReconnectDelay} - Error: {e.Exception.Message}");
                }
                await Task.Delay(e.ReconnectDelay);

                evt.Start(); // Reconnect to the same URL
            };
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            // Create custom handler for HTTP/2
            var h2handler = new Http2CustomHandler();

            // Set HTTP/2 to use only 1 connection per server to force connection sharing
            h2handler.MaxConnectionsPerServer = 1;

            if (args.Length == 0)
            {
                Console.WriteLine("Usage: ConsoleSSE <Server-Sent Events URL> [<Server-Sent Events URL>] ...");
                System.Environment.Exit(1);
            }

            for (int i = 0; i < args.Length; i++)
            {
                var evt = new EventSourceReader(new Uri(args[i]), h2handler).Start();

                evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) => {
                    Console.WriteLine($"{e.Message}");
                };
                evt.Disconnected += async(object sender, DisconnectEventArgs e) =>
                {
                    // Default ReceiveDataTimeout is 30 seconds, thus is EventSource data is not received for 30 seconds
                    // this will be triggered to reconnect.  If you'd like to set a longer timeout, add
                    // h2handler.ReceiveDataTimeout = new TimeSpan(days, hours, mins, sec) after h2handler is
                    // instantiated above.  Given reconnects are automatic, the Console.WriteLine message
                    // isn't required, but left in for informational purposes.
                    Console.WriteLine($"Receive Timeout: {e.ReconnectDelay}ms - Reconnecting...");
                    await Task.Delay(e.ReconnectDelay);

                    evt.Start(); // Reconnect to the same URL
                };
            }

            while (true)
            {
                Thread.Sleep(1000);
            }
        }
        /// <summary>
        /// Initialise the default settings and setup things for overrides.
        /// </summary>
        public static void Init()
        {
            // Restart the stream if everything is initialised
            if (Enabled)
            {
                Stream.Start();
                return;
            }

            // Get JSON
            Program.LogMessage($"Reading JSON config", "EventStreams");
            string json = "";

            if (!File.Exists(JSON_PATH))
            {
                Program.LogMessage($"Please create a JSON file called \"{JSON_PATH}\" before trying to use EventStreams.", "EventStreams", "error");
                return;
            }
            json = File.ReadAllText(JSON_PATH, Encoding.Default);

            Data = JObject.Parse(json);

            // Check if default domain is a Wikimedia project
            if (!CanBeUsed(Config.GetDomain(), out string[] temp))
Beispiel #12
0
        private async Task OpenConnection(AccessToken accessToken)
        {
            var condition = string.Format(Format, accessToken.UserId, accessToken.UserId);
            Uri url       = new Uri(
                App.GetApp().URL + "summonrequests/change-stream?access_token=" + accessToken.Id + "&options=" + condition
                );

            evt = new EventSourceReader(url);
            evt.MessageReceived += (object sender, EventSourceMessageEventArgs e) =>
            {
                Console.WriteLine($"{e.Event} : {e.Message}");
                var message = JsonConvert.DeserializeObject <SummonRequestMessage>(e.Message);
                if (message != null)
                {
                    var request = message.Request();
                    var update  = new SummonRequestUpdate {
                        Request = request
                    };
                    if (request.TargetId == accessToken.UserId)
                    {
                        switch (message.MessageType)
                        {
                        case "create":
                            update.UpdateType = UpdateType.Create;
                            break;

                        case "cancel":
                            update.UpdateType = UpdateType.Cancel;
                            break;

                        default:
                            return;
                        }
                    }
                    else if (request.CallerId == accessToken.UserId)
                    {
                        switch (message.MessageType)
                        {
                        case "accept":
                            update.UpdateType = UpdateType.Accept;
                            break;

                        case "reject":
                            update.UpdateType = UpdateType.Reject;
                            break;

                        default:
                            return;
                        }
                    }
                    else
                    {
                        return;
                    }
                    subject.OnNext(update);
                }
            };
            evt.Disconnected += async(object sender, DisconnectEventArgs e) =>
            {
                Console.WriteLine($"Retry: {e.ReconnectDelay} - Error: {e.Exception.Message}");
                await Task.Delay(e.ReconnectDelay);

                evt = evt?.Start(); // Reconnect to the same URL
            };
            await Task.Run(() => { evt = evt?.Start(); });

            connected = true;
        }
Beispiel #13
0
        async static Task <int> Main(string[] args)
        {
            string url   = Environment.GetEnvironmentVariable("URL");
            string notty = Environment.GetEnvironmentVariable("NOTTY");

            if (string.IsNullOrWhiteSpace(url))
            {
                Console.WriteLine("Please specify URL environment variable");
                return(2);
            }

            int duration = 30;

            if (args.Length > 0 && int.TryParse(args[0], out int d) && d > 0 && d <= 86400)
            {
                duration = d;
            }

            int lines = 25;

            if (args.Length > 1 && int.TryParse(args[1], out int l) && l > 0)
            {
                lines = l;
            }

            bool repeat = false;

            do
            {
                channelCounts.Clear();
                userCounts.Clear();
                active = true;
                using (var evt = new EventSourceReader(new Uri(url)))
                {
                    evt.MessageReceived += Evt_MessageReceived;
                    evt.Start();

                    Console.WriteLine($"Reading for {duration} seconds...");
                    await Task.Delay(duration * 1000);

                    active = false;
                    Console.WriteLine("Deactivating...");
                }

                await Task.Delay(500);

                var total = channelCounts.Values.Sum();
                PrintTop(channelCounts, lines, total);
                PrintTop(userCounts, lines, total);
                if (notty != "1")
                {
                    Console.Write("Repeat? [y/N] ");
                    char c = Console.ReadKey().KeyChar;
                    switch (c)
                    {
                    case 'y':
                    case 'Y':
                        repeat = true;
                        break;

                    default:
                        repeat = false;
                        break;
                    }
                    Console.WriteLine();
                }
            }while (repeat);

            return(0);
        }