Hello team,
Here are 2 consumer classes but one is from the 3.6.0 version and the other is the modified version with 3.11.17.
The older version was synchronous and it worked well. The newer version is asynchronous and is throwing an out of memory exception on the consumer.Received event (the text marked red) . Could you please help understand why it would run out of memory here?
Consumer class - RabbitMQ 3.6.0
public void Start(string rabbitQueue)
{
Subscript = new Subscription(Model, rabbitQueue, false);
var consumer = new ConsumeDelegate(Poll);
consumer.Invoke();
}
private void Poll()
{
if (Process == null)
{
if (Logger != null) { Logger.Error("Process is null in Consumer<TMessage>.Poll()"); }
throw new InvalidOperationException("Process is null in Consumer<TMessage>.Poll()");
}
if (Routing.IsEnabled)
{
BasicDeliverEventArgs delivery;
do
{
if (Subscript.Next(500, out delivery) && delivery != null)
{
var jsonString = Encoding.Default.GetString(delivery.Body);
var message = JsonConvert.DeserializeObject<TMessage>(jsonString);
Process(message);
Subscript.Ack(delivery);
}
} while(delivery != null);
}
}
Consumer class - RabbitMQ
3.11.17
public void Start(string rabbitQueue)
{
var consumer = new EventingBasicConsumer(Model);
Model.BasicConsume(rabbitQueue, false, consumer);
while (Routing.IsEnabled)
{
consumer.Received += (model, ea) =>
{
var body = ea.Body.ToArray();
string jsonString = Encoding.Default.GetString(body);
var message = JsonConvert.DeserializeObject<TMessage>(jsonString);
Process(message);
Model.BasicAck(ea.DeliveryTag, false);
}; }
}