def publish(self, topic, payload, qos, retain=False): self._logger.info("Performing sync publish...") ret = False if ClientStatus.STABLE != self._client_status.get_status(): self._handle_offline_request(RequestTypes.PUBLISH, (topic, payload, qos, retain)) else: if qos > 0: event = Event() rc, mid = self._publish_async(topic, payload, qos, retain, self._create_blocking_ack_callback(event)) if not event.wait(self._operation_timeout_sec): self._internal_async_client.remove_event_callback(mid) self._logger.error("Publish timed out") raise publishTimeoutException() else: self._publish_async(topic, payload, qos, retain) ret = True return ret
def publish(self, topic, payload, qos, retain=False): self._logger.info("Performing sync publish...") ret = False if ClientStatus.STABLE != self._client_status.get_status(): self._handle_offline_request(RequestTypes.PUBLISH, (topic, payload, qos, retain)) else: if qos > 0: event = Event() rc, mid = self._publish_async(topic, payload, qos, retain, self._create_blocking_ack_callback(event)) if not event.wait(self._operation_timeout_sec): self._internal_async_client.remove_event_callback(mid) self._logger.error("Publish timed out") raise publishTimeoutException() else: self._publish_async(topic, payload, qos, retain) ret = True return ret