/// <summary>
        /// Send message. Recipient resolved by the object type.
        /// </summary>
        public void Send(params object[] messages)
        {
            // Skip if there is no messages
            if (messages == null || messages.Length < 1)
            {
                return;
            }

            // Create transport message
            var serviceBusMessage =
                new ServiceBusMessage(messages)
            {
                SentFromQueueName = _inputTransportEndpointAddress.GetFriendlyName()
            };

            // Get list of endpoints we need send message to
            var endpoints = _endpointMapping.GetEndpoints(messages[0].GetType());

            foreach (var endpoint in endpoints)
            {
                // Create EndpointMessage from TransportMessage
                var provider         = TransportRegistry.GetQueueProvider(endpoint.Address);
                var transportMessage = provider.TranslateToTransportMessage(serviceBusMessage);

                // Send message
                var queue = provider.OpenEndpoint(endpoint.Address);
                queue.Send(transportMessage);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="T:System.Object"/> class.
        /// </summary>
        public ServiceBus(ServiceBusConfiguration configuration)
        {
            if (configuration.ServiceLocator == null)
            {
                throw new ArgumentException("Service Locator doesn't registered. Use SetServiceLocator() method.");
            }

            if (configuration.InputQueue == null)
            {
                throw new ArgumentException("Input queue not configured. Use SetInputQueue() method.");
            }

            _configuration = configuration;
            _provider      = configuration.Transport;
            _inputTransportEndpointAddress = configuration.InputQueue;
            _errorTransportEndpointAddress = configuration.ErrorQueue;
            _endpointMapping = configuration.EndpointsMapping;

            // use container of ServiceBus, if not specified for dispatcher
            if (_configuration.DispatcherConfiguration.ServiceLocator == null)
            {
                _configuration.DispatcherConfiguration.ServiceLocator = configuration.ServiceLocator;
            }

            TransportRegistry.Register(_inputTransportEndpointAddress, _provider);
            TransportRegistry.Register(_errorTransportEndpointAddress, _provider);
        }
        /// <summary>
        /// Run service bus and start input endpoint observing
        /// </summary>
        public void Run()
        {
            // Registration of endpoints
            foreach (var endpoint in _endpointMapping.Endpoints)
            {
                if (TransportRegistry.GetQueueProvider(endpoint.Address) == null)
                {
                    TransportRegistry.Register(endpoint.Address, endpoint.Transport ?? _provider);
                }
            }

            // Check existence of input and error endpoint and create them if needed
            PrepareQueues();

            // Create dispatcher
            _dispatcher = new Dispatcher(_configuration.DispatcherConfiguration);

            // Open error queue
            _errorTransportEndpoint = _provider.OpenEndpoint(_errorTransportEndpointAddress);

            // Create and configure observer of input queue
            _transportEndpointObserver = _provider.CreateObserver(_inputTransportEndpointAddress);
            _transportEndpointObserver.MessageReceived += EndpointObserverMessageReceived;
            _transportEndpointObserver.Start();

            // Set servise bus state into Running state
            _status = ServiceBusStatus.Running;
        }