/// Publishes the messages of sampled values to the broker for the duration of the
/// simulation time frame.
///
/// * `simulation_time` - the time frame that is simulated
Publishes the messages of sampled values to the broker for the duration of the
simulation time frame.

`simulation_time` - the time frame that is simulated
Publishes the messages of sampled values to the broker for the duration of the simulation time frame . ` simulation_time ` - the time frame that is simulated
pub fn publish_samples_to_broker_until(
        &self,
        simulation_time: SimulatedDateTime,
    ) -> Result<(), PvError> {
        // Open an insecure connection to omit OpenSSL as dependency for
        // this example.
        let mut connection = Connection::insecure_open(&self.broker_url)?;
        let channel = connection.open_channel(None)?;
        let exchange = Exchange::direct(&channel);
        let total_messages = simulation_time.count();
        // Notify roughly every 5%.
        let notification_threshold = total_messages / 20;
        for (message_index, time_point) in simulation_time.enumerate() {
            let message = self.sample_message(time_point)?;
            self.publish_to_broker(message, &exchange)?;
            // Print a notification on how the status of the simulation.
            if (message_index + 1) % notification_threshold == 0 {
                let percent_completion = (message_index + 1) as f64 / total_messages as f64 * 100.0;
                println!("    Simulation at {:.2}%", percent_completion);
            }
        }
        // Notifies clients that the simulation has finished.
        self.publish_to_broker(BrokerMessage::simulation_end_message(), &exchange)?;
        channel.close()?;
        Ok(())
    }
pub fn publish_samples_to_broker_until ( & self , simulation_time : SimulatedDateTime , ) -> Result < ( ) , PvError > { // Open an insecure connection to omit OpenSSL as dependency for // this example. let mut connection = Connection :: insecure_open ( & self . broker_url ) ? ; let channel = connection . open_channel ( None ) ? ; let exchange = Exchange :: direct ( & channel ) ; let total_messages = simulation_time . count ( ) ; // Notify roughly every 5%. let notification_threshold = total_messages / 20 ; for ( message_index , time_point ) in simulation_time . enumerate ( ) { let message = self . sample_message ( time_point ) ? ; self . publish_to_broker ( message , & exchange ) ? ; // Print a notification on how the status of the simulation. if ( message_index + 1 ) % notification_threshold == 0 { let percent_completion = ( message_index + 1 ) as f64 / total_messages as f64 * 100.0 ; println ! ( " " percent_completion ) ; } } // Notifies clients that the simulation has finished. self . publish_to_broker ( BrokerMessage :: simulation_end_message ( ) , & exchange ) ? ; channel . close ( ) ? ; Ok ( ( ) ) }
Publishes the messages of sampled values to the broker for the duration of the
simulation time frame.
Publishes the messages of sampled values to the broker for the duration of the simulation time frame .
&self
simulation_time
SimulatedDateTime