def publish_message(self):
        """If the class is not stopping, publish a message to RabbitMQ,
        appending a list of deliveries with the message number that was sent.
        This list will be used to check for delivery confirmations in the
        on_delivery_confirmations method.

        Once the message has been sent, schedule another message to be sent.
        The main reason I put scheduling in was just so you can get a good idea
        of how the process is flowing by slowing down and speeding up the
        delivery intervals by changing the PUBLISH_INTERVAL constant in the
        class.

        """

        if self.m_stopping:
            self.lg("Stopping Publish Messages", 6)
            return

        if self.m_num_amqp_msgs != 0 and self.m_num_amqp_msgs <= self.m_message_number:

            self.lg("Published(" + str(self.m_message_number) + ") All Messages(" + str(self.m_num_amqp_msgs) + ") Results Acked(" + str(self.m_acked) + ") Nacked(" + str(self.m_nacked) + ")", 6)
            self.run_summary()
            self.stop()
        
        else:

            
            if self.m_debug:
                self.lg("MessageTemplate(" + str(self.m_cur_message_template) + ")", 6)

            # Depending on the message template
            if self.m_message_type  == "AMQP":
                send_results        = self.send_amqp_message_template()
            elif self.m_message_type == "Stop Broker":
                send_results        = self.stop_broker(self.m_cur_message)
            elif self.m_message_type == "Start Broker":
                send_results        = self.start_broker(self.m_cur_message)
            elif self.m_message_type == "Start Worker Publisher":
                send_results        = self.start_worker_publisher(self.m_cur_message)
            elif self.m_message_type == "Add Network Latency Event":
                send_results        = self.add_network_latency_using_iptables(self.m_cur_message)
            elif self.m_message_type == "Remove All Network Latency Events":
                send_results        = self.remove_all_network_latency_events_using_iptables(self.m_cur_message)
            elif self.m_message_type == "Validate SSH Credentials":
                self.m_run_summary  = False
                send_results        = self.validate_ssh_credentials(self.m_cur_message)
            elif self.m_message_type == "Validate Docker Credentials":
                self.m_run_summary  = False
                send_results        = self.validate_docker_credentials(self.m_cur_message)
            elif self.m_message_type == "Reset All Broker Entities":
                if self.m_number_of_message_templates == 1:
                    self.m_run_summary  = False
                send_results        = self.____reset_cluster_entities(self.m_cur_message)
            else:
                err_msg             = "Unsupported Message Type(" + str(self.m_message_type) + ") found in Test"
                self.elg(err_msg, True)
            # end of handling specific message template types

            # if the current count is over the template message set amount
            if self.m_debug:
                print "Sent Template(" + str(self.m_cur_message_template) + ") Count(" + str(self.m_cur_count) + ") >= Number(" + str(self.m_cur_message["NumberToSend"]) + ")"

            if self.m_cur_count >= int(self.m_cur_message["NumberToSend"]):

                log_msg                     = "Done with NumberToSend(" + str(self.m_cur_message["NumberToSend"]) + ") CurCount(" + str(self.m_cur_count) + ")"
                self.m_cur_count            = 0
                self.m_cur_message_template += 1

                if self.m_cur_message_template >= self.m_number_of_message_templates:
                    self.m_connection.add_timeout(self.m_wait_interval, self.check_if_done)
                else:
                    self.m_cur_message      = self.m_messages[self.m_cur_message_template]
                    self.m_message_type     = str(self.m_cur_message["MessageType"])
                    self.m_number_to_send   = int(self.m_cur_message["NumberToSend"])
                    self.lg("Next MessageTemplate(" + str(self.m_cur_message_template) + ") Message(" + str(self.m_cur_message) + ")", 6)
                    self.m_connection.add_timeout(self.m_publish_interval, self.publish_message)
            # end of if/else

        # end of if/else

    # end of publish_message
dataset/ETHPy150Open GetLevvel/message-simulator/src/rabbit_message_publisher.py/RabbitMessagePublisher.publish_message/original