Beispiel #1
0
        /// <summary>
        /// Xử lý tạo các Entities, hứng các dữ liệu thay đổi, lưu trữ WebhookEvent vào Queue chờ
        /// </summary>
        /// <typeparam name="T">Kiểu dữ liệu cho data thay đổi</typeparam>
        /// <param name="action">Hành động xảy ra với địa chỉ (Thêm, Sửa, Xóa)</param>
        /// <param name="data">Dữ liệu thay đổi</param>
        /// Created by bvbao (13/8/2020)
        ///  Modified by bvbao (2/10/2020)
        public void WebhookStorage <T>(string action, T data)
        {
            //Khởi tạo payload từ dữ liệu địa chỉ thay đổi
            var payload = new WebhookEntitiesDefine().CreateWebhookPayload(data, action);
            //Kết nối đến RabbitMQ
            var queueName = _configuration["rabbitmq:queueWait"];

            using (var channel = _connection.CreateModel())
            {
                channel.QueueDeclare(queueName, true, false, false, null);
                //Gửi payload lên Queue chờ trên RabbitMQ
                var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload));
                channel.BasicPublish("", queueName, null, body);
            }
        }
Beispiel #2
0
        public async Task SendWebhookAsync()
        {
            var sendStorage = GetWaitSendingQueue();

            // Lấy toàn bộ các WebhookSubscription từ nguồn lưu trữ
            var webhookSubscriptions = getAllWebhookSubscription();

            //Nếu không có Uri đăng ký nào thì thôi
            if (sendStorage.Count <= 0 || webhookSubscriptions.Count <= 0)
            {
                Console.WriteLine("Check storage length");
                return;
            }

            //Khởi tạo WebhookEvent với từng WebhookUri cùng data
            foreach (var webhookSubscription in webhookSubscriptions)
            {
                WebhookEvent webhookEvent = new WebhookEntitiesDefine().CreateWebhookEvent(sendStorage, webhookSubscription.WebhookUri);

                //Gửi dữ liệu sang web client
                await PublishAsync(webhookEvent, 0);
            }
        }