Example #1
0
        public void Ping(object stateInfo)
        {
            if (WebSocket != null)
            {
                Task.Run(async() =>
                {
                    try
                    {
                        if (WebSocket.State == WebSocketState.Open)
                        {
                            await WebsocketSendingSemaphore.WaitAsync();
                            try
                            {
                                await JsonStreaming.Send(WebSocket, new QueueControlMessage
                                {
                                    Type    = QueueControlMessage.QueueControlMessageTypes.Ping,
                                    Queue   = QueueName,
                                    Message = new QueueMessage()
                                });
                            }
                            finally
                            {
                                WebsocketSendingSemaphore.Release();
                            }
                        }

                        if (!this.IsExecuting &&
                            this.LastPing != null &&
                            DateTime.Now.Subtract(this.LastPing.Value).TotalMilliseconds > PING_TIMEOUT_THRESHOLD
                            )
                        {
                            Connection.Logger.LogWarning("Ping timeout, closing");
                            //Console.WriteLine("Ping timeout, closing");
                            await this.Close();
                        }
                    }
                    catch (Exception)
                    {
                        //Console.WriteLine("Exception in ping handler: " + e);
                    }
                });
            }
        }
Example #2
0
        public async Task Ack(QueueMessage message, bool success)
        {
            await WebsocketSendingSemaphore.WaitAsync();

            try
            {
                await JsonStreaming.Send(WebSocket, new QueueControlMessage
                {
                    Type = success
                    ? QueueControlMessage.QueueControlMessageTypes.Ack
                    : QueueControlMessage.QueueControlMessageTypes.Nak,
                    Message = message,
                    Queue   = QueueName
                });
            }
            finally
            {
                WebsocketSendingSemaphore.Release();
            }
        }