Open Closed

Urgent - Distributed Event Handler not listening to published messages continuously #538


User avatar
0
Repunjay created

Check the docs before asking a question: https://docs.abp.io/en/commercial/latest/ Check the samples, to see the basic tasks: https://docs.abp.io/en/commercial/latest/samples/index The exact solution to your question may have been answered before, please use the search on the homepage.

  • ABP Framework version: v3.0.4
  • UI type: Angular
  • Tiered (MVC) or Identity Server Seperated (Angular): yes
  • Exception message and stack trace:
  • Steps to reproduce the issue:

Hi,

We have one service/api which runs in docker container. When one of the operation of this api is invoked, it publishes an event to a Distributed Event Bus (Rabbit MQ). The event is consumed by the Event handler which is a part of another service/api (Application project). This api is hosted in another container. We have noticed a problem that when the second service is idle, the event handler doesn't listens to the messages published by first service. Thus we have to restart the container of second service and than the handler consumes the event and process it. Is there a way to make that event handler continously listening to the messages despite service becomes idle? The Event Handler is written in the Application project of the second service. Below is the code snippet. Let me know if require further information.

using Microsoft.Extensions.Logging;
using FinanceManagement.SharedServices;
using FinanceManagement.TradeFinanceDetails;
using Shared.MqServices.ETO;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;

namespace FinanceManagement.MessagingServices
{
    public class TradeFinanceBatchEventHandler : IDistributedEventHandler<BatchCreatedEto>, ITransientDependency
    {
        private readonly IDistributedEventBus _distributedEventBus;
        private readonly ISharedAppService _sharedAppService;
        private readonly ITradeFinanceBatchAppService _tradeFinanceBatchAppService;
        private readonly ILogger _logger;

        public TradeFinanceBatchEventHandler(IDistributedEventBus distributedEventBus,
            ITradeFinanceBatchAppService tradeFinanceBatchAppService,
            ISharedAppService sharedAppService,
            ILogger<TradeFinanceBatchEventHandler> logger
            )
        {
            _distributedEventBus = distributedEventBus;
            _sharedAppService = sharedAppService;
            _tradeFinanceBatchAppService = tradeFinanceBatchAppService;
            _logger = logger;
        }
        public async Task HandleEventAsync(BatchCreatedEto eventData)
        {
            if (eventData.BatchId != Guid.Empty)
            {
                _logger.LogInformation("Start Process..");

                _logger.LogInformation("BatchId : " + eventData.BatchId.ToString());

                var batch = await _sharedAppService.GetBatchDetailById(eventData.BatchId);

                //Save TradeFinance
                var tradeFinancebatch = await _tradeFinanceBatchAppService.SaveRequestForFinancingAsync(batch);

                _logger.LogInformation("End Process.");
                //Send Acknowledgement
                //Update status in BatchService Batch using API
            }
        }
    }
}

Thanks & regards, Repunjay


7 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    What is service is idle, Is the container not started?

  • User Avatar
    0
    Repunjay created

    The container is started and it is running fine but if there is no call made to the api, the TradeFinanceBatchEventHandler doesn't listens to the published messages until the container is restarted. So for any messages which are published by service1, I have to start the container of service 2 every time in order to consume and process those messages successfully. How do i keep my Handler listening continously the published messages. Hope I was able to porvide the needed information. Let me know if you need further details.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    I will check it out.

  • User Avatar
    0
    Repunjay created

    Please advise if you have any update on this issue.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    I used the rabbitmq samples: https://github.com/abpframework/abp-samples/tree/master/RabbitMqEventBus

    It will publish an event every 10 seconds. I ran the program for more than an hour and everything worked fine.

    Could you provide steps to reproduce or you can use the CLI to create a sample project ro reproduce this problem. thanks.

  • User Avatar
    0
    Repunjay created

    Hi, Thanks for your reply. Sorry but it is not I was looking for. The default implementation of RabbitMQ and sample application works just fine.

    As I said earlier, the event gets published sucessfully from the first microservice. The Event Handler which is written in the "Application" project of second microservice doesn't listen to it until the docker container which host the second microservice is restarted. Do I need to move the Event Handler to a specific project for it to continously listening to the published events?

    Let me know if you understand the problem or suggest a way to connect online and discuss this issue.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi.

    Could you provide steps to reproduce or you can use the CLI to create a sample project to reproduce this problem? thanks

Made with ❤️ on ABP v9.1.0-preview. Updated on December 13, 2024, 06:09