public Task OnMessage(Message theMessage)
        {
            Task returnTask;

            try {
                SyntheticMessageProcessor processor = new SyntheticMessageProcessor(_connectionString, _monitoringTopic, _logger);
                Task messageTask = processor.OnMessage(theMessage);
                returnTask = Task.WhenAll(new Task[] { messageTask });
            } catch (MonitoringException mex) {
                _logger.LogError($"ERROR - {mex.Message} {mex.StackTrace}");
                returnTask = Task.FromException(mex);
            } catch (Exception ex) {
                _logger.LogWarning($"Error scenario found in monitored service - {ex.Message}");

                string         dataJSON     = Encoding.UTF8.GetString(theMessage.Body);
                MonitorMessage errorMessage = JsonConvert.DeserializeObject <MonitorMessage>(dataJSON);
                errorMessage.AssociatedId = $"{errorMessage.AssociatedId}_DLQ";
                if (ts is null)
                {
                    ts = new SessionlessTopicSender(_connectionString, _monitoringTopic);
                }
                Task sendTask = ts.Send(JsonConvert.SerializeObject(errorMessage), theMessage.UserProperties["CollectionId"].ToString(), theMessage.UserProperties["Context"].ToString(), DateTime.MinValue, "SYNTHETIC_ERROR");
                returnTask = Task.WhenAll(new Task[] { sendTask });
            }

            return(returnTask);
        }
 /// <summary>
 /// Processes a synthetic message by forwarding it to a monitoring topic (e.g. monitoring.infrastructure.topic)
 /// with eventType="LAST_SYNTHETIC_MESSAGE_PUBLISHED" to be monitored for arrival at monitoring endpoint
 /// </summary>
 /// <param name="servicebusConnectionStr">Azure Service Bus connection string</param>
 /// <param name="monitoringTopic">Monitoring topic name to which synthetic messages should be forwarded</param>
 /// <param name="log">Log to write errors and warnings</param>
 public SyntheticMessageProcessor(string servicebusConnectionStr, string monitoringTopic, ILogger log) : base(log)
 {
     if (ts is null)
     {
         ts = new SessionlessTopicSender(servicebusConnectionStr, monitoringTopic, log);
     }
     if (_logger is null)
     {
         _logger = log;
     }
 }