By default, topic consumers will receive only messages sent after they subscribe. However, it is possible to configure the consumer to use a retroactive subscription[1] to receive any previously sent messages that haven't been acked by all existing subscribers and deleted by the broker. By default, this is just the messages which at least one other subscriber has not acked, so you'll only get messages when one consumer is slow. You can configure your topic to retain some subset of the recently sent messages via the subscription recovery policy[2], to allow retroactive consumption even when no slow consumers exist.
All of that applies to new consumers. If what you really want is to not lose messages during periods when your consumer disconnects after the initial subscription, then you'll want to use a durable consumer[3, 4]. Be sure to always explicitly unsubscribe your durable consumer when you are done using it, because by default the broker will keep messages for it indefinitely and will eventually run out of space - or worse, memory - if you don't. Or (and, really; you should do this to protect the broker even if you expect your consumers to be well-behaved) use the configuration options to manage offline durable subscriptions[4]. Tim 1. https://activemq.apache.org/retroactive-consumer 2. https://activemq.apache.org/subscription-recovery-policy 3. https://activemq.apache.org/how-do-durable-queues-and-topics-work 4. https://activemq.apache.org/manage-durable-subscribers On Wed, Apr 7, 2021, 4:30 AM ヤ艾枫o.-- <1169114...@qq.com> wrote: > hello: > i want to know something about topic > Do you have to subscribe in advance when using topic to accept > messages? > After the producer sends a message and starts the consumer to connect to > topic, will the consumer receive the message > > > > > > > > thanks