code: def publish_message(self, message, content_type=None, headers=None, mandatory=False, immediate=False):
          
          logger.debug("Publishing message")
          try:
              self._connect()
              return self._do_publish(mandatory=mandatory,
                                      immediate=immediate,
                                      content_type=content_type,
                                      headers=headers,
                                      message=message)
          except pika.exceptions.AMQPConnectionError:
              logger.error("AMQPConnectionError occurred. Message not published.")
              raise PublishMessageError
          except NackError:
              # raised when a message published in publisher-acknowledgments mode
              # is returned via `Basic.Return` followed by `Basic.Ack`.
              logger.error("NackError occurred. Message not published.")
              raise PublishMessageError
          except UnroutableError:
              # raised when a message published in publisher-acknowledgments
              # mode is returned via `Basic.Return` followed by `Basic.Ack`.
              logger.error("UnroutableError occurred. Message not published.")
              raise PublishMessageError
          except Exception:
              logger.exception("Unknown exception occurred. Message not published.")
              raise PublishMessageError
docs: Publish a response message to a RabbitMQ instance.
  
          :param message: Response message
          :param content_type: Pika BasicProperties content_type value
          :param headers: Message header properties
          :param mandatory: The mandatory flag
          :param immediate: The immediate flag
  
          :returns: Boolean corresponding to the success of publishing
          :rtype: bool