public void RouteMessage(ICrmEvent crmEvent, IOrganizationService service, IBusControl busControl)
        {
            var scenario = crmEvent.Scenario;

            if (!_registrations.ContainsKey(scenario))
            {
                throw new InvalidOperationException($"No publisher registered for scenario {scenario}, aborting.");
            }

            var publishers = _registrations[scenario];

            _logger.Trace($"Routing message {scenario} to {string.Join(", ", publishers.Select(p => p.GetType().Name))}");

            Parallel.ForEach(publishers, (publisher) =>
            {
                try
                {
                    publisher.ProcessMessage(crmEvent, service, busControl);
                }
                catch (Exception ex)
                {
                    _logger.Error(ex, $"Exception occured during processing of message {crmEvent.CorrelationId} in {publisher.GetType().Name}, moving to error queue. Message: {ex.Message}");
                    throw;
                }
            });
        }
        public void ProcessMessage(ICrmEvent message, IOrganizationService service, IBusControl busControl)
        {
            _logger.Trace($"Retrieving contact with id {message.RecordId} from CRM");

            var record = service.Retrieve(message.Scenario.Entity, message.RecordId.Value, new Microsoft.Xrm.Sdk.Query.ColumnSet(true));

            _logger.Trace($"Publishing message to bus");

            busControl.Publish(new DemoCrmContactCreated
            {
                ContactId     = record.GetAttributeValue <Guid>("contactid"),
                CorrelationId = message.CorrelationId,
                EMailAddress1 = record.GetAttributeValue <string>("emailaddress1"),
                FirstName     = record.GetAttributeValue <string>("firstname"),
                LastName      = record.GetAttributeValue <string>("lastname"),
                Telephone1    = record.GetAttributeValue <string>("telephone1"),
                TimeStamp     = message.TimeStamp
            });

            _logger.Info($"Successfully published DemoCrmContactCreated message {message.CorrelationId} to bus");
        }