how can i differentiate queue and pub/sub programmatically through java code?
Sumanth Reddy Kaveti
1

if the consumers have the same group-id, they are using the “queue” like mode.

If the consumers have different group-id, they will all receive the same messages. So they are in the pub/sub mode.

The group-id is a property passed to the constructor:

Properties props = new Properties();

props.put(ConsumerConfig.BOOTSTRAP_SERVERS_CONFIG, brokerHosts);

props.put(ConsumerConfig.GROUP_ID_CONFIG, “my-group-id”);

KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props);