Exemple #1
0
 def _publish_async(self,
                    topic,
                    payload,
                    qos,
                    retain=False,
                    ack_callback=None):
     rc, mid = self._internal_async_client.publish(topic, payload, qos,
                                                   retain, ack_callback)
     if MQTT_ERR_SUCCESS != rc:
         self._logger.error("Publish error: %d", rc)
         raise publishError(rc)
     return rc, mid
Exemple #2
0
 def publish(self, topic, payload, qos, retain):
     if (topic is None or payload is None or qos is None or retain is None):
         self._log.error("publish: None type inputs detected.")
         raise TypeError("None type inputs detected.")
     # Return publish succeeded/failed
     ret = False
     # Queueing should happen when disconnected or draining is in progress
     self._offlinePublishQueueLock.acquire()
     queuedPublishCondition = not self._drainingComplete or self._connectResultCode == sys.maxsize
     if queuedPublishCondition:
         if self._connectResultCode == sys.maxsize:
             self._log.info("Offline publish request detected.")
         # If the client is connected but draining is not completed...
         elif not self._drainingComplete:
             self._log.info("Drainging is still on-going.")
         self._log.info("Try queueing up this request...")
         # Publish to the queue and report error (raise Exception)
         currentQueuedPublishRequest = _publishRequest(
             topic, payload, qos, retain)
         # Try to append the element...
         appendResult = self._offlinePublishQueue.append(
             currentQueuedPublishRequest)
         # When the queue is full...
         if appendResult == self._offlinePublishQueue.APPEND_FAILURE_QUEUE_FULL:
             self._offlinePublishQueueLock.release()
             raise publishQueueFullException()
         # When the queue is disabled...
         elif appendResult == self._offlinePublishQueue.APPEND_FAILURE_QUEUE_DISABLED:
             self._offlinePublishQueueLock.release()
             raise publishQueueDisabledException()
         # When the queue is good...
         else:
             self._offlinePublishQueueLock.release()
     # Publish to Paho
     else:
         self._offlinePublishQueueLock.release()
         self._publishLock.acquire()
         # Publish
         (rc, mid) = self._pahoClient.publish(topic, payload, qos,
                                              retain)  # Throw exception...
         self._log.debug("Try to put a publish request " + str(mid) +
                         " in the TCP stack.")
         ret = rc == 0
         if (ret):
             self._log.debug("Publish request " + str(mid) + " succeeded.")
         else:
             self._log.error("Publish request " + str(mid) +
                             " failed with code: " + str(rc))
             self._publishLock.release(
             )  # Release the lock when exception is raised
             raise publishError(rc)
         self._publishLock.release()
     return ret
 def publish(self, topic, payload, qos, retain):
     if(topic is None or payload is None or qos is None or retain is None):
         self._log.error("publish: None type inputs detected.")
         raise TypeError("None type inputs detected.")
     # Return publish succeeded/failed
     ret = False
     # Queueing should happen when disconnected or draining is in progress
     self._offlinePublishQueueLock.acquire()
     queuedPublishCondition = not self._drainingComplete or self._connectResultCode == sys.maxsize
     if queuedPublishCondition:
         if self._connectResultCode == sys.maxsize:
             self._log.info("Offline publish request detected.")
         # If the client is connected but draining is not completed...
         elif not self._drainingComplete:
             self._log.info("Drainging is still on-going.")
         self._log.info("Try queueing up this request...")
         # Publish to the queue and report error (raise Exception)
         currentQueuedPublishRequest = _publishRequest(topic, payload, qos, retain)
         # Try to append the element...
         appendResult = self._offlinePublishQueue.append(currentQueuedPublishRequest)
         # When the queue is full...
         if appendResult == self._offlinePublishQueue.APPEND_FAILURE_QUEUE_FULL:
             self._offlinePublishQueueLock.release()
             raise publishQueueFullException()
         # When the queue is disabled...
         elif appendResult == self._offlinePublishQueue.APPEND_FAILURE_QUEUE_DISABLED:
             self._offlinePublishQueueLock.release()
             raise publishQueueDisabledException()
         # When the queue is good...
         else:
             self._offlinePublishQueueLock.release()
     # Publish to Paho
     else:
         self._offlinePublishQueueLock.release()
         self._publishLock.acquire()
         # Publish
         (rc, mid) = self._pahoClient.publish(topic, payload, qos, retain)  # Throw exception...
         self._log.debug("Try to put a publish request " + str(mid) + " in the TCP stack.")
         ret = rc == 0
         if(ret):
             self._log.debug("Publish request " + str(mid) + " succeeded.")
         else:
             self._log.error("Publish request " + str(mid) + " failed with code: " + str(rc))
             self._publishLock.release()  # Release the lock when exception is raised
             raise publishError(rc)
         self._publishLock.release()
     return ret
 def _publish_async(self, topic, payload, qos, retain=False, ack_callback=None):
     rc, mid = self._internal_async_client.publish(topic, payload, qos, retain, ack_callback)
     if MQTT_ERR_SUCCESS != rc:
         self._logger.error("Publish error: %d", rc)
         raise publishError(rc)
     return rc, mid