Skip to content

[Reliability] Order messages lost if consumer crashes before acknowledgment — no persistence guarantees #46

@anshul23102

Description

@anshul23102

Executive Summary

RabbitMQ messages are not persisted to disk and consumers don't acknowledge processing. If a service crashes, in-flight orders are lost permanently.

Proposed Solution

@Configuration
public class OrderQueueConfig {
  @Bean
  public DirectExchange orderExchange() {
    return new DirectExchange("orders.exchange", true, false);
  }
  
  @Bean
  public Queue orderQueue() {
    return QueueBuilder.durable("orders.queue")
      .withArgument("x-message-ttl", 86400000)  // 24h retention
      .build();
  }
  
  @Bean
  public Binding orderBinding() {
    return BindingBuilder.bind(orderQueue())
      .to(orderExchange())
      .with("order.*");
  }
}

@Service
public class OrderConsumer {
  @RabbitListener(queues = "orders.queue", ackMode = AcknowledgmentMode.MANUAL)
  public void consumeOrder(Order order, Channel channel, @Header(AmqpHeaders.DELIVERY_TAG) long tag) 
    throws IOException {
    try {
      processOrder(order);
      channel.basicAck(tag, false);  // Acknowledge only after processing
    } catch (Exception e) {
      channel.basicNack(tag, false, true);  // Requeue on failure
      logger.error("Failed to process order", e);
    }
  }
}

Checklist

  • I have searched existing issues and confirmed this is not a duplicate
  • I have read the CONTRIBUTING.md guidelines
  • I have provided clear steps to reproduce the issue
  • I have described expected vs. actual behavior clearly
  • This issue title is clear and specific
  • This repository has been verified as NSOC on https://www.nsoc.in/projects

@pooranjoyb Could you please /assign this issue to me? I would like to implement message persistence and acknowledgment under NSOC '26.

/assign

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions