Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JMS vs Kafka in specific conditions

I am reading both concepts. Mainly Kafka. And comparing with JMS to understand better.

Kafka guarantees ordered delivery and multiple subscriber. How does kafka achieve it?

Kafka has multiple partitions. If one consumer per partition, then we can guarantee ordering. We can achieve load balancing with multiple partitions. So Both at the same time is possible.

In case of JMS, if we have multiple queues, isn't same as Kafka?

Q1: Which is better in this scenario?

Q2: Am I looking narrowly? Does kafka do more than this?

Please advise me.

Even If I am wrong about JMS, please let me know.

like image 455
Gibbs Avatar asked Mar 08 '17 06:03

Gibbs


People also ask

How is Kafka better than JMS?

Kafka is a distributed streaming platform that offers high horizontal scalability. Also, it provides high throughput and that's why it's used for real-time data processing. JMS is a general-purpose messaging solution that supports various messaging protocols. Kafka is way faster than JMS.

What is difference between JMS and Kafka?

JMS provides the functionality of filtering messages. 7. Kafka is a pulling-based messaging system. JMS is a pushing-based system.

Can you use JMS with Kafka?

Applications written using the Confluent kafka-jms-client can exchange messages with other application written using kafka-jms-client as well as any application that produces or consumes messages using any other Kafka client library.

Why Kafka is better than other messaging systems?

Kafka is Highly Reliable. Kafka replicates data and is able to support multiple subscribers. Additionally, it automatically balances consumers in the event of failure. That means that it's more reliable than similar messaging services available.


2 Answers

I was asking myself the same question before :)

As you wrote, Kafka guarantees ordered delivery only within a single partition. Period. If you are using multiple partitions (which is a must to have the parallelism), then it is possible that a consumer who listens on several partitions gets a message A from partition 1 before a message B from partition 2, even though message B arrived first.

Now, about the differences between Kafka and JMS. In JMS, you have a queue and you have a topic. With queues, when first consumer consumes a message, others cannot take it anymore. With topics, multiple consumers receive each message but it is much harder to scale. Consumer group from Kafka is a generalization of these two concepts - it allows scaling between members of the same consumer group, but it also allows broadcasting the same message between many different consumer groups.

Even more important difference is the following. Imagine that you have Kafka topic with 500 partitions and on the other hand, 500 JMS message queues. Let's also imagine that you have certain number of producers and consumers. In case of JMS, you need to configure each of them so they know which queues belong to them. What if e.g. some consumer crashes or you detect that you need to increase number of consumers? You have to reconfigure manually the whole system. This comes for free with Kafka, i.e. Kafka provides automatic rebalancing which is an extremely useful feature.

Finally, Kafka is tremendously faster, mostly because of some clever disk/memory transfer techniques and because consumers take care about the messages they consumed, not the broker like in JMS. Because of this, consumer is also able to "rewind", i.e. reread the messages from e.g. 2 days ago.

See also:

  • Apache Kafka order of messages with multiple partitions
  • Benchmarking Apache Kafka
like image 71
Miljen Mikic Avatar answered Sep 21 '22 18:09

Miljen Mikic


Here's a fairly good article on the differences: http://blog.hampisoftware.com/index.php/2016/01/20/apache-kafka-differences-from-jms/

Kafka does not guarantee message ordering across multiple partitions of a topic. Order is maintained only within a partition. In order to achieve strict ordering, you need to use one partition per topic.

like image 38
abstax Avatar answered Sep 19 '22 18:09

abstax