Beispiel #1
0
 public HttpClient Client()
 {
     GatewayConfiguration = new HttpGatewayConfiguration();
     _timeout             = Convert.ToDouble(GatewayConfiguration.OrderServiceConfiguration.Timeout);
     _client = new ThreadLocal <HttpClient>(() => CreateClient(_timeout));
     return(_client.Value);
 }
Beispiel #2
0
        public OrdersClientController()
        {
            var gatewayConfiguration = HttpGatewayConfiguration.GetConfiguration();

            foreach (OrderAPIServerElement serverDefinition in gatewayConfiguration.OrderServiceConfiguration.Servers)
            {
                _serverList.Add(
                    new Server()
                {
                    Uri     = serverDefinition.Uri,
                    Timeout = Convert.ToDouble(serverDefinition.Timeout)
                }
                    );
            }

            _retryPolicy = Policy
                           .Handle <AggregateException>()
                           .Or <Exception>()
                           .WaitAndRetry(new[]
            {
                TimeSpan.FromMilliseconds(50),
                TimeSpan.FromMilliseconds(150),
                TimeSpan.FromMilliseconds(250),
            }, (exception, timespan) =>
            {
                LogError(exception);
                TrySelectNextServer();
            });

            TrySelectNextServer();
        }
        /// <summary>
        /// Registers the specified client.
        /// </summary>
        /// <param name="client">The client.</param>
        public void Register(Client client)
        {
            var gatewayConfiguration = HttpGatewayConfiguration.GetConfiguration();

            foreach (OrderAPIServerElement serverDefinition in gatewayConfiguration.OrderServiceConfiguration.Servers)
            {
                var registration = new AgentServiceRegistration()
                {
                    ID      = serverDefinition.Id,
                    Name    = serverDefinition.Name,
                    Address = serverDefinition.Address,
                    Port    = serverDefinition.Port,
                    Tags    = new [] { "Orders" }
                };

                //clear any old registration - we don't respond to services running/not running in this version
                client.Agent.ServiceDeregister(registration.ID);
                client.Agent.ServiceRegister(registration);
            }
        }
Beispiel #4
0
        public OrdersClientController()
        {
            var gatewayConfiguration = HttpGatewayConfiguration.GetConfiguration();

            _baseAddres = gatewayConfiguration.OrderServiceConfiguration.Uri;
        }