<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def publish_amqp_message_by_unit(self, sentry_unit, message, queue="test", ssl=False, username="testuser1", password="changeme", port=None):
 """Publish an amqp message to a rmq juju unit. :param sentry_unit: sentry unit pointer :param message: amqp message string :param queue: message queue, default to test :param username: amqp user name, default to testuser1 :param password: amqp user password :param ssl: boolean, default to False :param port: amqp port, use defaults if None :returns: None. Raises exception if publish failed. """

        self.log.debug('Publishing message to {} queue:\n{}'.format(queue,
                                                                    message))
        connection = self.connect_amqp_by_unit(sentry_unit, ssl=ssl,
                                               port=port,
                                               username=username,
                                               password=password)

        # NOTE(beisner): extra debug here re: pika hang potential:
        #   https://github.com/pika/pika/issues/297
        #   https://groups.google.com/forum/#!topic/rabbitmq-users/Ja0iyfF0Szw
        self.log.debug('Defining channel...')
        channel = connection.channel()
        self.log.debug('Declaring queue...')
        channel.queue_declare(queue=queue, auto_delete=False, durable=True)
        self.log.debug('Publishing message...')
        channel.basic_publish(exchange='', routing_key=queue, body=message)
        self.log.debug('Closing channel...')
        channel.close()
        self.log.debug('Closing connection...')
        connection.close()