From messaging point of view with systems like Kafka, RabbitMQ, HornetQ, ActiveMQ, etc. is there a difference between pub/sub and prod/con or are they used interchangeably?
4 Answers
There is a difference between the publish/subscribe and producer/consumer models.
Publish/Subscriber: Subscribers subscribe to the publisher. Each message the Publisher publishes is sent to all the subscribers. That is, all subscribers receive the same message. (Think of a newspaper or magazine subscription. All subscribers receive the same magazine or newspaper)
Producer/Consumer: Each message the producer produces will be consumed by a single consumer. This is a mechanism to distribute the workload to multiple consumers. (Think of the several cash registers at the supermarket. Each customer goes to a single cash register. The customers are like the messages that are produced and the cash registers are the consumers)

- 62
- 1
- 9

- 12,714
- 9
- 63
- 91
-
1Consumers in different consumer groups can consume the same message from a topic. – Hackerman Jul 30 '21 at 21:54
-
2@Hackerman `consumer group` is a term that is specific to certain message brokers such as Kafka. – Can't Tell Aug 05 '21 at 09:07
Although both Publish/Subscribe and Producer/Consumer terms are related to messaging, they are different and can't be used interchangeably.
Publish/Subscribe is a messaging pattern where a publication is distributed to multiple receivers. A Producer is the sender of messages and consumer is the receiver of messages. Producers and consumers are an integral part of both Publish/Subscribe and Point-to-Point messaging patterns.
Hope this helps.

- 14,980
- 2
- 33
- 52
-
But they are quite often used interchangibly. Publiser and Subscriber then? – user432024 Feb 27 '17 at 05:31
-
1Yes, Publisher/Subscriber and Producer/Consumer are used interchangeably but not Pub/Sub and Producer/Consumer. Publisher/Subscriber is specifically used in Pub/Sub messaging pattern and Producer/Consumer in P2P messaging pattern. – Shashi Feb 27 '17 at 05:44
-
You wrong I think. The point is when a message is consumed will not process with other consumer in producer/consumer pattern. In contrast a message will be sent to all subscribers when publisher/subscriber (Observer pattern) is being used. *** So they mustn't be used interchangeably!!! *** – Bijan Dec 19 '21 at 16:43
In producer consumer , message produced by producer is only consumed by one consumers . Even with n number of consumers each message will be consumed by only one consumer . Producing n messages to n consumers , each message will be consumed by one consumer (round robin algorithm) .
In contrast in Publisher subscriber , message produced by publisher is consumed by all subscribers that have subscribed to specific queue . Publishers produce messages while subscriber consumes message . Messages are posted in subscription queue .

- 127
- 1
- 15

- 91
- 1
- 3
As per my understanding - Prod/Consu - Producer produces and Consumer consumes the produced task . - Publisher/Subscriber - Publisher produces and Subscriber consumes the produced task only if Subscriber is subscribed to Publisher.
Both can be interchanged but the later one makes sense in terms of Architectural real use cases .Produce and publish only if it is subscribed based upon subscription agreement .
Thanks

- 207
- 3
- 4
-
1This is the actual answer for this question. Publish-Subscribe involves registration of subscribers before consuming – overexchange Apr 08 '19 at 13:42