Search code examples
asp.net-corerabbitmqmessaging

Exception in Consuming message with EasyNetQ


I'm using easyNetQ to publish and receive message from queue but ..

Exception in Getting message from queue.

The server reported 0 messages 
Exchange    ErrorExchange_
type:   EasyNetQ.SystemMessages.Error, EasyNetQ

"RoutingKey":"", "Exchange":"SSO.Login", "Queue":"SSO.Login_SSOQueue.LoginQueue", "Exception":"System.IO.FileNotFoundException: Could not load file or assembly 'OAuth.Admin.Infrastructures.RabbitMQEventBus, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.\r\nFile name: 'OAuth.Admin.Infrastructures.RabbitMQEventBus, Culture=neutral, PublicKeyToken=null'\r\n at System.Reflection.RuntimeAssembly.nLoad(AssemblyName fileName, String codeBase, RuntimeAssembly locationHint, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)\r\n at System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, RuntimeAssembly reqAssembly, StackCrawlMark& stackMark, IntPtr pPrivHostBinder, Boolean throwOnFileNotFound, IntPtr ptrLoadContextBinder)\r\n at System.Reflection.Assembly.Load(AssemblyName assemblyRef)\r\n at EasyNetQ.DefaultTypeNameSerializer.GetTypeFromTypeNameKey(TypeNameKey typeNameKey)\r\n at EasyNetQ.DefaultTypeNameSerializer.<>c.b__3_0(String t)\r\n at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func2 valueFactory)\r\n at EasyNetQ.DefaultMessageSerializationStrategy.DeserializeMessage(MessageProperties properties, Byte[] body)\r\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass17_0.b__0(Byte[] body, MessageProperties properties, MessageReceivedInfo messageReceivedInfo)\r\n at EasyNetQ.RabbitAdvancedBus.<>c__DisplayClass21_0.b__0(Byte[] body, MessageProperties properties, MessageReceivedInfo receivedInfo)\r\n at EasyNetQ.Consumer.HandlerRunner.InvokeUserMessageHandlerInternalAsync(ConsumerExecutionContext context)\r\n\r\n", "Message":"{\"PhoneNumber\":\"09---------\",\"ApplicationName\":\"somthing\",\"CampaignId\":2}", "DateTime":"2020-01-14T05:37:19.9778013Z",

this assembly is in my publisher that is separate application

"Exception":"System.IO.FileNotFoundException: Could not load file or assembly 'OAuth.Admin.Infrastructures.RabbitMQEventBus, Culture=neutral, PublicKeyToken=null'.

Solution

  • the problem is that my consumer couldn't deserialize messages i use this code in my Consumer and my problem is fixed

    protected override Task ExecuteAsync(CancellationToken stoppingToken)
        {
            stoppingToken.ThrowIfCancellationRequested();
    
            var consumer = new EventingBasicConsumer(_channel);
    
            consumer.Received += HandleMessageAsync; ;
    
            _channel.BasicConsume("BlaBlaBlaQueue", false, consumer);
            return Task.CompletedTask;
        }
    
        private async void HandleMessageAsync(object sender, BasicDeliverEventArgs e)
        {
            var content = System.Text.Encoding.UTF8.GetString(e.Body);
            ConfirmRequest confirmRequest  = JsonConvert.DeserializeObject<ConfirmRequest>(content);
    
            var result =await sendConfirmBlaBlaBlaResuest.ConfirmBlaBlaBlaAsync(new BlaBlaBlaDto {});
            var responce = new ConfirmBlaBlaBlaResponceEvent(confirmRequest);
    
            if (result.IsFailure)
            {
                responce.Message = result.Error;
                responce.IsSuccess = false;
            }
            else
            {
                responce.IsSuccess = true;
            }
    
            await bus.PublishBlaBlaBlaResponceEventAsync(responce);
            _channel.BasicAck(e.DeliveryTag, false);
        }
    

    and my producer is

    public async Task PublishBlaBlaBlaEventAsync(BlaBlaBlaEvent myEvent)
        {
            var exchange = _bus.ExchangeDeclare(rabbitOptions.BlaBlaBlaExchangeName, ExchangeType.Topic);
            var queue = _bus.QueueDeclare(rabbitOptions.BlaBlaBlaQueueName);
            _bus.Bind(exchange, queue, "#");
            var message = new Message<BlaBlaBlaEvent>(myEvent);
            await _bus.PublishAsync(exchange, queue.Name, false, message);
        }