Kafka vs RabbitMQ

Two Different Models

Kafka is a distributed log: records stay for days, many groups read the same data, and you can replay. RabbitMQ is a message broker with queues: a message is routed through an exchange into queues and removed once a consumer acknowledges it.

Apache KafkaRabbitMQ
ModelPartitioned log, consumers pullExchanges + queues, broker pushes
After readingRecord kept (retention); replay possibleMessage deleted after ack
OrderingPer partition (per key)Per queue (single consumer)
ThroughputVery high (millions/s per cluster)High (tens of thousands/s per node)
RoutingBy topic onlyRich: direct, topic patterns, fanout, headers
Per-message featuresFewTTL, priorities, delayed messages, per-message ack
Spring supportspring-kafka: KafkaTemplate, @KafkaListenerspring-boot-starter-amqp: RabbitTemplate, @RabbitListener
Choose forEvent streaming, many consumers, analytics, audit log, high volumeTask queues, work distribution, complex routing, RPC-style jobs

The Same Event with RabbitMQ

@Configuration
class RabbitConfig {
    static final String EXCHANGE = "shopease.orders";
    static final String PAYMENT_QUEUE = "payment.order-placed";

    @Bean TopicExchange ordersExchange() { return new TopicExchange(EXCHANGE); }

    @Bean Queue paymentQueue() {
        return QueueBuilder.durable(PAYMENT_QUEUE).deadLetterExchange("shopease.dlx").build();
    }

    @Bean Binding paymentBinding(Queue paymentQueue, TopicExchange ordersExchange) {
        return BindingBuilder.bind(paymentQueue).to(ordersExchange).with("order.placed");
    }

    @Bean MessageConverter jsonMessageConverter() {   // send records as JSON
        return new Jackson2JsonMessageConverter();
    }
}

// order-service: publish
rabbitTemplate.convertAndSend(RabbitConfig.EXCHANGE, "order.placed", event);

// payment-service: consume
@RabbitListener(queues = RabbitConfig.PAYMENT_QUEUE)
void onOrderPlaced(OrderPlacedEvent event) {
    paymentService.startPayment(event);
}

Example

docker run -d --name rabbitmq -p 5672:5672 -p 15672:15672 rabbitmq:3.13-management

Example output

# management UI at http://localhost:15672 (guest / guest)
Queues
Name                   Messages Ready  Unacked  Incoming/s  Deliver/s
payment.order-placed   0               0        12.0        12.0

Tip: Both are fine for ShopEase. A common split in Indian product companies: Kafka for business events and analytics streams, RabbitMQ (or SQS) for background jobs like sending emails and generating invoices.