# Difference between subscribe and publishes in Java HiveMQ Client

**URL:** <https://community.hivemq.com/t/difference-between-subscribe-and-publishes-in-java-hivemq-client/1895>\
**Category:** HiveMQ Client Library\
**Created:** [March 14, 2023, 9:15pm UTC](https://community.hivemq.com/t/difference-between-subscribe-and-publishes-in-java-hivemq-client/1895 "2023-03-14T21:15:14Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dlowrey](https://avatars.discourse-cdn.com/v4/letter/d/a6a055/32.png) [@dlowrey](https://community.hivemq.com/u/dlowrey)\
**Post date:** [March 14, 2023, 9:15pm UTC](https://community.hivemq.com/t/difference-between-subscribe-and-publishes-in-java-hivemq-client/1895/1 "2023-03-14T21:15:14Z")

</div>

What is the difference between the `subscribe(..)` methods and the `publishes(..)` method(s) in the HiveMQ Java Client library?

When I use `subscribe(...)`, I know it will send a SUBSCRIBE to the MQTT broker in some way, but does the same (or similar) happen when I do a `publishes(...)`, or is it completely client side?

If the latter, does that mean I could connect to a persistent session and use `publishes(...)` to process ANY incoming messages that the broker may have queued up for me? As in, does `publishes(...)` automatically get all messages that that client got sent by the broker, without having to explicitly subscribe?

For example, say I have an IoT device that has extremely low bandwidth and power constraints. I turn the device on, it connects, sets up a persistent session, and subscribes to a topic. Then, I turn the device off and then on again. It connects, sees that a persistent session exists, so does NOT subscribe. No messages will be processed by this client now (even though the broker seems to queue them and deliver them), because the subscribe code was what hooked up the callback logic. Is using `publishes` the way to get around this? Is there a different way to have that callback logic hooked up without explicitly calling `subscribe()`?

---

<div class="post-metadata">

**Author:** ![azo](https://avatars.discourse-cdn.com/v4/letter/a/e36b37/32.png) [@azo](https://community.hivemq.com/u/azo)\
**Post date:** [March 25, 2023, 5:05pm UTC](https://community.hivemq.com/t/difference-between-subscribe-and-publishes-in-java-hivemq-client/1895/2 "2023-03-25T17:05:46Z")

</div>

I would think that device connecting to broker and subscribing to topic are two different activities. So persistent connection will enable not requiring establishing an underlying TCP connection, subscribing to a topic may still be needed, have you tried subscribing again ?
