# HiveMQ how to create a topic without subscribing first

**URL:** <https://community.hivemq.com/t/hivemq-how-to-create-a-topic-without-subscribing-first/1268>\
**Category:** MQTT\
**Created:** [June 21, 2022, 9:04am UTC](https://community.hivemq.com/t/hivemq-how-to-create-a-topic-without-subscribing-first/1268 "2022-06-21T09:04:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 21, 2022, 9:04am UTC](https://community.hivemq.com/t/hivemq-how-to-create-a-topic-without-subscribing-first/1268/1 "2022-06-21T09:04:34Z")

</div>

Hello, I am currently testing some MQTT setup.  
So far I am with RabbitMQ, MQTT WSS, HiveMQ client library.

My use case is such that a publisher posts messages to a topic before actually a subscriber subscribes to the topic for the first time ever. I wish that messages published before the first subscription/connection would be delivered to the subscriber upon its first connection. But this is not happening.

From link below I get the notion that topic is created with either publish or subscribe.

> **[MQTT Topics, Wildcards, & Best Practices - MQTT Essentials: Part 5](https://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices/)**
>
> MQTT Topics, Wildcards and Best Practices: We explain MQTT topics, topic wildcards, MQTT $SYS topics and best practices of topic naming.

Quoting: “ **the client does not need to create the desired topic before they publish or subscribe to it** ”

Similiar idea is also mentioned here:

> **[Using MQTT to send and receive data for your next project](https://opensource.com/article/18/6/mqtt)**
>
> From open data to open event streams with the MQTT publish/subscribe (pubsub) wire protocol.

**"…Unlike more “enterprisey” message buses, in MQTT topics are not preregistered. A sender can create topics on the fly…"**

I tried to emulate the “A sender can create topics on the fly” && “the client does not need to create the desired topic before they publish or subscribe to it” using the client here:

> **[MQTT Websocket Client](http://www.hivemq.com/demos/websocket-client/)**
>
> Try HiveMQ MQTT browser client – a websocket client that you can use to experiment with publishing and subscribing MQTT messages over port 8000

1. create a connection  
2.publish to a testtopic/blabla1 content: “blabla1”-\> message not listed in messages  
3.subsrcibe to a testtopic/blabla1 → **message from point 2 not received - PROBLEM FOR ME**  
4.publish to a testtopic/blabla1 content: “blabla2”-\> message listed in messages

The topic in my use case refers to entities which are created and deleted in multiple ways and ad hoc. So having some procedure to initialize the first subscription is not an option either because it would need to be incorporated to many part of our software.

My question is: can I consume a message published to a topic to which a subscriber has not ever connected yet?

Thank you for your effort

---

<div class="post-metadata">

**Author:** ![YannickWeber](https://yyz1.discourse-cdn.com/flex035/user_avatar/community.hivemq.com/yannickweber/32/103_2.png) [@YannickWeber](https://community.hivemq.com/u/YannickWeber)\
**Post date:** [June 24, 2022, 6:27am UTC](https://community.hivemq.com/t/hivemq-how-to-create-a-topic-without-subscribing-first/1268/2 "2022-06-24T06:27:55Z")

</div>

> [@PeNo](#):
>
> My question is: can I consume a message published to a topic to which a subscriber has not ever connected yet?

In MQTT messages with no subscribers are dropped, keep in mind that MQTT is a broadcasting protocol not a message queuing system like Kafka or RabbitMQ.

However there are [Retained Messages](https://www.hivemq.com/blog/mqtt-essentials-part-8-retained-messages/) which are persistent even when there are no subscribers. Maybe this could help you with your goal, but only on retained message is possible per topic.

---

<div class="post-metadata">

**Author:** ![PeNo](https://avatars.discourse-cdn.com/v4/letter/p/e9bcb4/32.png) [@PeNo](https://community.hivemq.com/u/PeNo)\
**Post date:** [June 24, 2022, 7:06am UTC](https://community.hivemq.com/t/hivemq-how-to-create-a-topic-without-subscribing-first/1268/3 "2022-06-24T07:06:13Z")

</div>

Thank you very much. I think that you described my problem well. I got a task which sees MQTT as a MQ system. Required is as well as the light weight transfer (I have no choice but MQTT) as well message queueing approach as eg AMQP offers.

I tested this aspect of retained messages successfully. However same as above, for the requirement it is not enough to deliver only the last message. In my requirement all messages sent to a Topic (to which no subscriber subscribed yet) need to be delivered after first subsrciption.
