Ejemplo n.º 1
0
        /// <summary>
        /// Handle a push onto the queue
        /// </summary>
        /// <param name="reader">The json object</param>
        /// <param name="client">The client stream.</param>
        /// <returns>A task</returns>
        private static async Task HandlePush(JObject reader, Stream client)
        {
            var queueName = reader["queue"].ToString();

            var payload = reader["data"].ToString();

            var result = QueueManager.Intance[queueName].Enqueue(payload);

            // Get the response bytes. These should be constants.
            var response = QueueEndpoint.ConstructResponse(queueName, "push", result, String.Empty);

            await client.WriteAsync(response, 0, response.Length);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Handle a pop from the queue
        /// </summary>
        /// <param name="reader">The json object</param>
        /// <param name="client">The stream client</param>
        /// <returns>A task</returns>
        private static async Task HandlePop(JObject reader, Stream client)
        {
            var queueName = reader["queue"].ToString();

            var payload = QueueManager.Intance[queueName].Dequeue()?.Payload;

            var status = Status.Success;

            if (String.IsNullOrWhiteSpace(payload))
            {
                status = Status.Empty;
            }

            var response = QueueEndpoint.ConstructResponse(queueName, "pop", status, payload);

            await client.WriteAsync(response, 0, response.Length);
        }