Example #1
0
 public DotNettyServer(JimuAddress address, IServiceEntryContainer serviceEntryContainer, ILogger logger)
 {
     _serviceEntryContainer = serviceEntryContainer;
     _address     = address;
     _logger      = logger;
     _middlewares = new Stack <Func <RequestDel, RequestDel> >();
 }
Example #2
0
 public DotNettyServer(string serverIp, int serverPort, JimuAddress serviceInvokeAddress, IServiceEntryContainer serviceEntryContainer, ILogger logger)
 {
     _serviceEntryContainer = serviceEntryContainer;
     _serviceInvokeAddress  = serviceInvokeAddress;
     _logger      = logger;
     _middlewares = new Stack <Func <RequestDel, RequestDel> >();
     _serverIp    = serverIp;
     _serverPort  = serverPort;
 }
Example #3
0
 //private readonly Action<IWebHostBuilder> _builderAction;
 public HttpServer(string ip, int port, JimuAddress serviceInvokeAddress, IServiceEntryContainer serviceEntryContainer, ILogger logger)
 {
     _serviceEntryContainer = serviceEntryContainer;
     _serviceInvokeAddress  = serviceInvokeAddress;
     _ip          = ip;
     _port        = port;
     _logger      = logger;
     _middlewares = new Stack <Func <RequestDel, RequestDel> >();
     //_builderAction = builderAction;
 }
Example #4
0
 public DotNettyServer(string serverIp, int serverPort, JimuAddress serviceInvokeAddress, IServiceEntryContainer serviceEntryContainer, IJimuDiagnostic jimuApm, ILoggerFactory loggerFactory)
 {
     _serviceEntryContainer = serviceEntryContainer;
     _serviceInvokeAddress  = serviceInvokeAddress;
     _logger      = loggerFactory.Create(this.GetType());
     _middlewares = new Stack <Func <RequestDel, RequestDel> >();
     _serverIp    = serverIp;
     _serverPort  = serverPort;
     _jimuApm     = jimuApm;
 }
Example #5
0
 public RemoteCallerContext(JimuServiceRoute service, IDictionary <string, object> paras, string token, JimuAddress jimuAddress)
 {
     if (paras == null)
     {
         paras = new ConcurrentDictionary <string, object>();
     }
     this.Service        = service;
     this.Paras          = paras;
     this.Token          = token;
     this.ServiceAddress = jimuAddress;
 }
Example #6
0
            private async Task CheckHealth(JimuAddress address, int timeout)
            {
                using (var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
                {
                    SendTimeout = timeout
                })
                {
                    try
                    {
                        await socket.ConnectAsync(address.CreateEndPoint());

                        address.IsHealth = true;
                    }
                    catch
                    {
                        address.IsHealth = false;
                    }
                }
            }
        public ServiceInvokerContext(JimuTransportMsg transportMessage, IServiceEntryContainer serviceEntryContainer,
                                     IResponse response, ILogger logger, JimuAddress address)
        {
            Response         = response;
            TransportMessage = transportMessage;
            try
            {
                RemoteInvokeMessage = transportMessage.GetContent <JimuRemoteCallData>();
            }
            catch (Exception ex)
            {
                logger.Error("failed to convert transportmsg.content to  JimuRemoteCallerData.", ex);
                return;
            }

            ServiceEntry = serviceEntryContainer.GetServiceEntry()
                           .FirstOrDefault(x => x.Descriptor.Id == RemoteInvokeMessage.ServiceId);
            if (ServiceEntry == null)
            {
                logger.Error($"not found service: {RemoteInvokeMessage.ServiceId}", new EntryPointNotFoundException($"{RemoteInvokeMessage.ServiceId}"));
            }
            Address = address;
        }
Example #8
0
        public override void DoInit(IContainer container)
        {
            if (_options != null)
            {
                var logger = container.Resolve <ILogger>();
                logger.Info($"[config]use jose.jwt for Auth");

                //while (!container.IsRegistered<IServer>() || !container.IsRegistered<IServiceDiscovery>())
                //{
                //    Thread.Sleep(200);
                //}
                var server = container.Resolve <IServer>();
                server.UseMiddleware <JwtAuthorizationMiddleware>(_options, container);

                if (string.IsNullOrEmpty(_options.TokenEndpointPath))
                {
                    return;
                }
                var discovery  = container.Resolve <IServiceDiscovery>();
                var addr       = new JimuAddress(_options.ServiceInvokeIp, Convert.ToInt32(_options.ServiceInvokePort), _options.Protocol);
                var tokenRoute =
                    new JimuServiceRoute
                {
                    Address = new List <JimuAddress> {
                        addr
                    },
                    ServiceDescriptor = new JimuServiceDesc
                    {
                        Id         = _options.GetServiceId(),
                        Service    = "Token",
                        RoutePath  = JimuServiceRoute.ParseRoutePath("", "", _options.TokenEndpointPath, new[] { "username", "password" }, false),
                        Parameters = JimuHelper.Serialize <string>(new List <JimuServiceParameterDesc> {
                            new JimuServiceParameterDesc
                            {
                                Comment = "username",
                                Format  = "System.String",
                                Name    = "username",
                                Type    = "object"
                            },
                            new JimuServiceParameterDesc
                            {
                                Comment = "password",
                                Format  = "System.String",
                                Name    = "password",
                                Type    = "object"
                            },
                        }),
                        ReturnDesc = JimuHelper.Serialize <string>(new JimuServiceReturnDesc
                        {
                            Comment      = "Token",
                            ReturnType   = "object",
                            ReturnFormat = "{\"access_token\":\"System.String | token\", \"expired_in\":\"System.Int32 | expired timestamp which is the number of seconds between 1970-01-01 and expired datetime\"}"
                        })
                    }
                };
                //discovery.ClearServiceAsync(tokenRoute.First().ServiceDescriptor.Id).Wait();
                ////discovery.SetRoutesAsync(tokenRoute);
                //discovery.AddRouteAsync(tokenRoute).Wait();
                discovery.OnBeforeSetRoutes += (routes) =>
                {
                    routes.Add(tokenRoute);
                };
            }

            base.DoInit(container);
        }
Example #9
0
        public override void DoInit(IContainer container)
        {
            if (_options != null)
            {
                var loggerFactory = container.Resolve <ILoggerFactory>();
                var logger        = loggerFactory.Create(this.GetType());
                logger.Info($"[config]use jose.jwt for Auth");

                //while (!container.IsRegistered<IRemoteServiceCaller>() || !container.IsRegistered<IClientServiceDiscovery>())
                //{
                //    Thread.Sleep(100);
                //}

                var caller = container.Resolve <IRemoteServiceCaller>();
                caller.UseMiddleware <JwtAuthorizationMiddleware>(_options);

                if (string.IsNullOrEmpty(_options.TokenEndpointPath))
                {
                    return;
                }
                var discovery  = container.Resolve <IClientServiceDiscovery>();
                var addr       = new JimuAddress(_options.ServiceInvokeIp, Convert.ToInt32(_options.ServiceInvokePort), _options.Protocol);
                var tokenRoute = new List <JimuServiceRoute> {
                    new JimuServiceRoute
                    {
                        Address = new List <JimuAddress> {
                            addr
                        },
                        ServiceDescriptor = new JimuServiceDesc
                        {
                            Id               = _options.GetServiceId(),
                            Service          = "Token",
                            HttpMethod       = "POST",
                            AllowAnonymous   = true,
                            ServiceClassPath = "",
                            RoutePath        = JimuServiceRoute.ParseRoutePath("POST", "", _options.TokenEndpointPath, new[] { "username", "password", "grant_type" }, false),
                            Parameters       = JimuHelper.Serialize <string>(new List <JimuServiceParameterDesc> {
                                new JimuServiceParameterDesc
                                {
                                    Comment = "username",
                                    Name    = "username",
                                    Type    = "System.String"
                                },
                                new JimuServiceParameterDesc
                                {
                                    Comment = "password",
                                    Name    = "password",
                                    Type    = "System.String"
                                },
                                new JimuServiceParameterDesc
                                {
                                    Comment = "grant_type",
                                    Default = "password",
                                    Name    = "grant_type",
                                    Type    = "System.String"
                                },
                            }),
                            ReturnDesc = JimuHelper.Serialize <string>(new JimuServiceReturnDesc {
                                Comment    = "Token",
                                ReturnType = "object",
                                Properties = new List <JimuServiceParameterDesc>
                                {
                                    new JimuServiceParameterDesc {
                                        Comment = "token",
                                        Name    = "access_token",
                                        Type    = "System.String"
                                    },
                                    new JimuServiceParameterDesc {
                                        Comment = "expired timestamp which is the number of seconds between 1970-01-01 and expired datetime",
                                        Name    = "expired_in",
                                        Type    = "System.Int32"
                                    }
                                }
                            })
                        }
                    }
                };
                discovery.AddRoutesGetter(() =>
                {
                    return(Task.FromResult(tokenRoute));
                });
            }

            base.DoInit(container);
        }
Example #10
0
 public HttpClientSender(ClientListener clientListener, ILogger logger, JimuAddress address) : base(clientListener, logger)
 {
     _address        = address;
     _clientListener = clientListener;
 }
Example #11
0
 public HttpClientSender(JimuAddress address, IClientListener clientListener)
 {
     _address        = address;
     _clientListener = clientListener;
 }
Example #12
0
        public override void DoInit(IContainer container)
        {
            if (_options != null)
            {
                var logger = container.Resolve <ILogger>();
                logger.Info($"[config]use jose.jwt for Auth");

                while (!container.IsRegistered <IRemoteServiceCaller>() || !container.IsRegistered <IClientServiceDiscovery>())
                {
                    Thread.Sleep(100);
                }

                var caller = container.Resolve <IRemoteServiceCaller>();
                caller.UseMiddleware <JwtAuthorizationMiddleware>(_options);

                if (string.IsNullOrEmpty(_options.TokenEndpointPath))
                {
                    return;
                }
                var discovery  = container.Resolve <IClientServiceDiscovery>();
                var addr       = new JimuAddress(_options.ServerIp, _options.ServerPort, _options.Protocol);
                var tokenRoute = new List <JimuServiceRoute> {
                    new JimuServiceRoute
                    {
                        Address = new List <JimuAddress> {
                            addr
                        },
                        ServiceDescriptor = new JimuServiceDesc
                        {
                            Id         = _options.GetServiceId(),
                            RoutePath  = JimuServiceRoute.ParseRoutePath("", "", _options.TokenEndpointPath, new[] { "username", "password" }, false),
                            Parameters = JimuHelper.Serialize <string>(new List <JimuServiceParameterDesc> {
                                new JimuServiceParameterDesc
                                {
                                    Comment = "username",
                                    Format  = "System.String",
                                    Name    = "username",
                                    Type    = "object"
                                },
                                new JimuServiceParameterDesc
                                {
                                    Comment = "password",
                                    Format  = "System.String",
                                    Name    = "password",
                                    Type    = "object"
                                },
                            }),
                            ReturnDesc = JimuHelper.Serialize <string>(new JimuServiceReturnDesc {
                                Comment      = "Token",
                                ReturnType   = "object",
                                ReturnFormat = "{\"access_token\":\"System.String | token\", \"expired_in\":\"System.Int32 | expired timestamp which is the number of seconds between 1970-01-01 and expired datetime\"}"
                            })
                        }
                    }
                };
                discovery.AddRoutesGetter(() =>
                {
                    return(Task.FromResult(tokenRoute));
                });
            }

            base.DoInit(container);
        }