public async Task Idle_sensor(consumer_queue <WaypointsType> Consumer, TimeSpan Idle_timeout) { var Async_delay = Task.Delay(Idle_timeout); await Async_delay; try { if (Async_delay.Status != TaskStatus.RanToCompletion) { throw new Exception("await Task.Delay for Idle_timeout"); } if (Consumer.stopped == false) { if (Received_flag == false) { Consumer.Forget_topic(amqp.routing_key); // Should (eventually) take itself out from dict of accumulated messages. return; } Received_flag = false; Task.Run(async() => Idle_sensor(Consumer, Idle_timeout)); } } catch (Exception e) { lock (Consumer.queue) { Consumer.AddToExceptionText(e.Message); } } }
public message_envelope(message_base msg_, consumer_queue <WaypointsType> Consumer, TimeSpan?Idle_timeout) { msg = msg_; if (Idle_timeout != null) { Task.Run(async() => Idle_sensor(Consumer, Idle_timeout.Value)); } }
subscribe(ReaderWriterLockSlim rwl, message_factory_base message_factory, string topic_name, ulong begin_utc = 0, ulong end_utc = 0, ulong delayed_delivery_tolerance = 0, bool supply_metadata = false, bool tcp_no_delay = false, bool preroll_if_begin_timestamp_in_future = false, bool Save_raw_data_on_wire = false, TimeSpan?Idle_timeout = null) { if (consumer == null) { consumer = new consumer_queue <WaypointsType>(rwl, message_factory, ch, Save_raw_data_on_wire, Idle_timeout); } var dictionary = new Dictionary <string, object>(); // currently 'l' in RabbitMQ is chosen as signed type (not the same in other language AMQP libs)... so our interface/API/and-server-side is uint64_t and then each lib/language/implementation casts as necessary (timestamping is under 63 bits at the moment at the server side anyways) if (begin_utc != 0) { dictionary.Add("begin_timestamp", (long)begin_utc); } if (end_utc != 0) { dictionary.Add("end_timestamp", (long)end_utc); } if (delayed_delivery_tolerance != 0) { dictionary.Add("delayed_delivery_tolerance", (long)delayed_delivery_tolerance); } if (supply_metadata == true) { dictionary.Add("supply_metadata", (int)1); } if (tcp_no_delay == true) { dictionary.Add("tcp_no_delay", (int)1); } if (preroll_if_begin_timestamp_in_future == true) { dictionary.Add("preroll_if_begin_timestamp_in_future", (int)1); } // not too fast at the moment (bare bones example), TODO later will set topic_name elsewhere so as not to resend it everytime ch.BasicConsume(topic_name, true, "", dictionary, consumer); }
close() { if (consumer != null) { consumer.stop(); consumer = null; } // ... done lock (publishing_channels) { foreach (var pub_i in publishing_channels) { pub_i.Value.AMQP_channel.Close(); } publishing_channels.Clear(); } if (ch != null) { ch.Close(); ch = null; } }