コード例 #1
0
 public SendWeatherInformationTask(IServiceProxyFactory serviceProxyFactory, AppSettings appSettings, IDataContextFactory dataContextFactory, ILogger logger)
 {
     _serviceProxyFactory = serviceProxyFactory;
     _appSettings         = appSettings;
     _dataContextFactory  = dataContextFactory;
     _logger = logger;
 }
コード例 #2
0
        public static Task RunInContext(this IServiceProxyFactory actorProxyFactory, Action <IServiceProxyFactory> action, IServiceClientLogger logger, params ServiceRequestHeader[] headers)
        {
            Task task         = null;
            var  headersArray = headers.ToArray();

            task = new Task(() =>
            {
                logger?.StartRequestContext(headersArray);
                Debug.Assert(ServiceRequestContext.Current == null);
                ServiceRequestContext.Current = new ServiceRequestContext(headers);
                try
                {
                    action(actorProxyFactory);
                }
                catch (Exception ex)
                {
                    logger?.FailedRequestContext(headers, ex);
                    throw ex;
                }
                finally
                {
                    ServiceRequestContext.Current = null;
                    logger?.StopRequestContext(headersArray);
                }
            });

            task.Start();

            return(task);
        }
コード例 #3
0
        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="serviceProxyFactory"></param>
        public static void Test(IServiceProxyFactory serviceProxyFactory)
        {
            var tracingContext = ServiceLocator.GetService <ITracingContext>();

            Task.Run(async() =>
            {
                RpcContext.GetContext().SetAttachment("xid", 124);

                var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
                var user      = userProxy.GetUser(new UserModel {
                    UserId = 1,
                    Name   = "fanly",
                    Age    = 120,
                    Sex    = 0
                }).GetAwaiter().GetResult();
                var e  = userProxy.SetSex(Sex.Woman).GetAwaiter().GetResult();
                var v  = userProxy.GetUserId("fanly").GetAwaiter().GetResult();
                var fa = userProxy.GetUserName(1).GetAwaiter().GetResult();
                userProxy.Try().GetAwaiter().GetResult();
                var v1        = userProxy.GetUserLastSignInTime(1).Result;
                var things    = userProxy.GetAllThings().Result;
                var apiResult = userProxy.GetApiResult().GetAwaiter().GetResult();
                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = 1,
                    Name   = "fanly"
                }).Wait();

                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = 1,
                    Name   = "fanly"
                }).Wait();

                var r = await userProxy.GetDictionary();
                var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();

                do
                {
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    //1w次调用
                    var watch = Stopwatch.StartNew();
                    for (var i = 0; i < 10000; i++)
                    {
                        //var a = userProxy.GetDictionary().Result;
                        var a = await userProxy.GetDictionary();
                        //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();
        }
コード例 #4
0
 public CallServiceImpl(IServiceProxyFactory serviceProxyFactory, ISerialize serialize, IEventBus eventBus, IStateManager stateManager, Oxygen.Common.Interface.ILogger logger)
 {
     this.serviceProxyFactory = serviceProxyFactory;
     this.eventBus            = eventBus;
     this.stateManager        = stateManager;
     this.serialize           = serialize;
 }
コード例 #5
0
        static async Task <int> ActivateService(IPoolProxy pools, IServiceProxyFactory serviceProxyFactory, string serviceTypeName, string serviceInstanceName, ObjectId activationId, int users)
        {
            Stopwatch timer = new Stopwatch();

            timer.Start();
            try
            {
                var serviceInstance = await PooledServiceProxy <IServiceInstance> .Create(pools, serviceProxyFactory, serviceTypeName, serviceInstanceName);

                //verify the service instance uri returned exists
                //await serviceInstance.PingAsync();
            }
            catch (AggregateException ex)
            {
                WriteConsoleActivationStatus($"Failed with message {ex.InnerException.Message}", activationId, serviceInstanceName, users);
            }
            catch (Exception ex)
            {
                WriteConsoleActivationStatus($"Failed with message {ex.Message}", activationId, serviceInstanceName, users);
            }
            finally
            {
                timer.Stop();
                WriteConsoleActivationStatus($"Finished in {timer.ElapsedMilliseconds} ms", activationId, serviceInstanceName, users);
            }

            // 'think' time
            await Task.Delay(3000);

            return((int)timer.ElapsedMilliseconds);
        }
コード例 #6
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUser(new UserModel {
             UserId = 1
         });
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 await userProxy.GetUser(new UserModel {
                     UserId = 1
                 });
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.ReadLine();
         } while (true);
     }).Wait();
 }
コード例 #7
0
ファイル: ActorBase.cs プロジェクト: ben-kotvis/ASF.Wellness
 /// <summary>
 /// Initializes a new instance of Participant
 /// </summary>
 /// <param name="actorService">The Microsoft.ServiceFabric.Actors.Runtime.ActorService that will host this actor instance.</param>
 /// <param name="actorId">The Microsoft.ServiceFabric.Actors.ActorId for this actor instance.</param>
 public ActorBase(ActorService actorService, ActorId actorId, IActorProxyFactory actorProxyFactory, IServiceProxyFactory serviceProxyFactory, IRepositoryFactories factories)
     : base(actorService, actorId)
 {
     _actorProxyFactory   = actorProxyFactory;
     _serviceProxyFactory = serviceProxyFactory;
     _factories           = factories;
 }
コード例 #8
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUserId("user");
         var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 var a = userProxy.GetUser(new IModuleServices.Common.Models.UserModel()
                 {
                     Name = "fanly"
                 }).Result;
                 //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.WriteLine("Press any key to continue, q to exit the loop...");
             var key = Console.ReadLine();
             if (key.ToLower() == "q")
             {
                 break;
             }
         } while (true);
     }).Wait();
 }
コード例 #9
0
 /// <summary>
 /// Creates a new default instance.
 /// </summary>
 public BrokerServiceLocator(Uri brokerServiceUri = null, IHashingHelper hashingHelper = null)
 {
     _hashingHelper       = hashingHelper ?? new HashingHelper();
     _fabricClient        = new FabricClient();
     _serviceProxyFactory = new ServiceProxyFactory(c => new FabricTransportServiceRemotingClientFactory());
     _brokerServiceUri    = brokerServiceUri;
 }
コード例 #10
0
        public MockActorService(
            ICodePackageActivationContext codePackageActivationContext,
            IServiceProxyFactory serviceProxyFactory,
            IActorProxyFactory actorProxyFactory,
            NodeContext nodeContext,
            StatefulServiceContext statefulServiceContext,
            ActorTypeInformation actorTypeInfo,
            Func <ActorService, ActorId, ActorBase> actorFactory = null,
            Func <ActorBase, IActorStateProvider,
                  IActorStateManager> stateManagerFactory = null,
            IActorStateProvider stateProvider             = null,
            ActorServiceSettings settings = null

            ) :
            base(
                context: statefulServiceContext,
                actorTypeInfo: actorTypeInfo,
                actorFactory: actorFactory,
                stateManagerFactory: stateManagerFactory,
                stateProvider: stateProvider,
                settings: settings)
        {
            _codePackageActivationContext = codePackageActivationContext;
            _serviceProxyFactory          = serviceProxyFactory;
            _actorProxyFactory            = actorProxyFactory;
            _nodeContext = nodeContext;
        }
コード例 #11
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         await userProxy.GetUserId("user");
         do
         {
             Console.WriteLine("正在循环 1w次调用 GetUser.....");
             //1w次调用
             var watch = Stopwatch.StartNew();
             for (var i = 0; i < 10000; i++)
             {
                 var a = userProxy.GetDictionary().Result;
             }
             watch.Stop();
             Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
             Console.WriteLine("Press any key to continue, q to exit the loop...");
             var key = Console.ReadLine();
             if (key.ToLower() == "q")
             {
                 break;
             }
         } while (true);
     }).Wait();
 }
コード例 #12
0
 /// <summary>
 /// 测试
 /// </summary>
 /// <param name="serviceProxyFactory"></param>
 public static void Test(IServiceProxyFactory serviceProxyFactory)
 {
     Task.Run(async() =>
     {
         var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
         var result    = await userProxy.GetUserName(123);
     }).Wait();
 }
コード例 #13
0
 public Item(IServiceProxyFactory serviceProxyFactory, IItemDTO dto)
 {
     this.serviceProxyFactory = serviceProxyFactory;
     this.ID         = dto.ID;
     this.Name       = dto.Name;
     this.ParameterA = dto.ParameterA;
     this.ParameterB = dto.ParameterB;
     this.Product    = dto.Product;
 }
コード例 #14
0
 public StatelessBackendServiceController(StatelessServiceContext serviceContext, ConfigSettings settings)
 {
     this.serviceContext      = serviceContext;
     this.configSettings      = settings;
     this.serviceProxyFactory = new CorrelatingServiceProxyFactory(
         serviceContext,
         callbackClient => new FabricTransportServiceRemotingClientFactory(null, callbackClient, null, null, null)
         );
 }
コード例 #15
0
        public WebScraperService(StatelessServiceContext context)
            : base(context)
        {
            _actorProxyFactory   = new ActorProxyFactory();
            _serviceProxyFactory = new ServiceProxyFactory();            //retrySettings: new OperationRetrySettings(TimeSpan.FromMilliseconds(3), TimeSpan.FromMilliseconds(3), 1));

            _speakerActorApplicationName = FabricRuntime.GetActivationContext().ApplicationName;
            _speakerActorServiceName     = $"{typeof(ISpeakerActor).Name.Substring(1)}Service";
            _speakerActorServiceUri      = new Uri($"{_speakerActorApplicationName}/{_speakerActorServiceName}");
        }
コード例 #16
0
        public static TServiceInterface CreateServiceProxy <TServiceInterface>(this IServiceProxyFactory actorProxyFactory, ServiceReference serviceReference)
            where TServiceInterface : IService
        {
            if (serviceReference == null)
            {
                throw new ArgumentNullException(nameof(serviceReference));
            }

            return(actorProxyFactory.CreateServiceProxy <TServiceInterface>(serviceReference.ServiceUri, GetPartitionKey(serviceReference)));
        }
コード例 #17
0
 internal static I ForService<I>(IServiceProxyFactory serviceProxyFactory, Uri serviceAddress, ServicePartitionKey partitionKey = null)
     where I : class, IService
 {
     if (serviceProxyFactory == null)
     {
         throw new ArgumentNullException(nameof(serviceProxyFactory), "Invalid node call. Must supply service proxy factory.");
     }
     Debug.Assert(typeof(I).IsInterface);
     return serviceProxyFactory.CreateServiceProxy<I>(serviceAddress, partitionKey: partitionKey, listenerName: Naming.Listener<I>());
 }
コード例 #18
0
 public static I ForComponent<I>(IServiceProxyFactory serviceProxyFactory, StatefulService caller, ServicePartitionKey partitionKey = null)
     where I : class, IService
 {
     if (serviceProxyFactory == null)
     {
         throw new ArgumentNullException(nameof(serviceProxyFactory), "Invalid component call. Must supply service proxy factory.");
     }
     Debug.Assert(caller != null, "Invalid component call. Must supply stateful service caller.");
     return ForService<I>(serviceProxyFactory, Addressing.Component<I>(caller), partitionKey);
 }
コード例 #19
0
        public HomeController()
        {
            _actorProxyFactory   = new ActorProxyFactory();
            _serviceProxyFactory = new ServiceProxyFactory();            //retrySettings: new OperationRetrySettings(TimeSpan.FromMilliseconds(3), TimeSpan.FromMilliseconds(3), 1));

            _speakerActorApplicationName = FabricRuntime.GetActivationContext().ApplicationName;
            _speakerActorServiceName     = $"{typeof(ISpeakerActor).Name.Substring(1)}Service";
            _speakerActorServiceUri      = new Uri($"{_speakerActorApplicationName}/{_speakerActorServiceName}");

            GetSpeakerActorPartitionList();
        }
 public static IKernel WithCore(this IKernel kernel,
                                ServiceContext serviceContext,
                                IActorStateManager stateManager,
                                IClusterClient clusterClient             = null,
                                TelemetryClient telemetry                = null,
                                IActorProxyFactory actorProxyFactory     = null,
                                IServiceProxyFactory serviceProxyFactory = null)
 {
     kernel.Load(new CoreModule(serviceContext, stateManager, clusterClient, telemetry, actorProxyFactory, serviceProxyFactory));
     return(kernel);
 }
コード例 #21
0
ファイル: Startup.cs プロジェクト: zhupeng0929/surging
 public static void TestRabbitMq(IServiceProxyFactory serviceProxyFactory)
 {
     serviceProxyFactory.CreateProxy <IUserService>("User").PublishThroughEventBusAsync(new UserEvent()
     {
         Age    = 18,
         Name   = "fanly",
         UserId = 1
     });
     Console.WriteLine("Press any key to exit...");
     Console.ReadLine();
 }
コード例 #22
0
 public static I ForMicroservice<I>(IServiceProxyFactory serviceProxyFactory, ServicePartitionKey partitionKey = null)
     where I : class, IService
 {
     if (serviceProxyFactory == null)
     {
         throw new ArgumentNullException(nameof(serviceProxyFactory), "Invalid microservice call. Must supply service proxy factory.");
     }
     Debug.Assert(
         typeof(I).Namespace.Contains(Constant.Manager),
         $"Invalid microservice call. Use only the {Constant.Manager} interface to access a microservice.");
     return ForService<I>(serviceProxyFactory, Addressing.Microservice<I>(), partitionKey);
 }
コード例 #23
0
 public GoodsUseCaseService(IGoodsRepository repository, IGoodsCategoryRepository goodsCategoryRepository, IEsGoodsRepository esGoodsRepository, ILocalEventBus localEventBus, IServiceProxyFactory serviceProxyFactory, IEventBus eventBus, IStateManager stateManager, IUnitofWork unitofWork)
 {
     this.repository = repository;
     this.goodsCategoryRepository = goodsCategoryRepository;
     this.unitofWork          = unitofWork;
     this.eventBus            = eventBus;
     this.stateManager        = stateManager;
     this.serviceProxyFactory = serviceProxyFactory;
     this.actorService        = serviceProxyFactory.CreateActorProxy <IGoodsActorService>();
     this.esGoodsRepository   = esGoodsRepository;
     this.localEventBus       = localEventBus;
 }
コード例 #24
0
 public CoreModule(ServiceContext serviceContext,
                   IActorStateManager stateManager,
                   IClusterClient clusterClient             = null,
                   TelemetryClient telemetry                = null,
                   IActorProxyFactory actorProxyFactory     = null,
                   IServiceProxyFactory serviceProxyFactory = null)
 {
     this.serviceContext      = serviceContext;
     this.stateManager        = stateManager;
     this.clusterClient       = clusterClient;
     this.telemetry           = telemetry;
     this.actorProxyFactory   = actorProxyFactory;
     this.serviceProxyFactory = serviceProxyFactory;
 }
コード例 #25
0
        public MockFabricRuntime(string applicationName)
        {
            ApplicationName = applicationName;
            _stateManager   = new MockReliableStateManager();

            var serviceProxyFactory = new MockServiceProxyFactory(this);
            var actorProxyFactory   = new MockActorProxyFactory(this);

            _serviceProxyFactory = serviceProxyFactory;
            _actorProxyFactory   = actorProxyFactory;

            FG.ServiceFabric.Services.Remoting.Runtime.Client.ServiceProxyFactory.SetInnerFactory((factory, serviceType) => _serviceProxyFactory);;
            FG.ServiceFabric.Actors.Client.ActorProxyFactory.SetInnerFactory((factory, serviceType, actorType) => _actorProxyFactory);;
        }
コード例 #26
0
        /// <summary>
        /// 测试
        /// </summary>
        /// <param name="serviceProxyFactory"></param>
        public static void Test(IServiceProxyFactory serviceProxyFactory)
        {
            Task.Run(async() =>
            {
                var userProxy = serviceProxyFactory.CreateProxy <IUserService>("User");
                var v         = userProxy.GetUserId("fanly").GetAwaiter().GetResult();
                var fa        = userProxy.GetUserName(1).GetAwaiter().GetResult();
                var apiResult = userProxy.GetApiResult().GetAwaiter().GetResult();
                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = "1",
                    Name   = "fanly"
                }).Wait();

                userProxy.PublishThroughEventBusAsync(new UserEvent
                {
                    UserId = "1",
                    Name   = "fanly"
                }).Wait();

                var r = await userProxy.GetDictionary();
                var serviceProxyProvider = ServiceLocator.GetService <IServiceProxyProvider>();

                do
                {
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    //1w次调用
                    var watch = Stopwatch.StartNew();
                    for (var i = 0; i < 10000; i++)
                    {
                        //var a = userProxy.GetDictionary().Result;
                        var a = userProxy.GetDictionary().Result;
                        //var result = serviceProxyProvider.Invoke<object>(new Dictionary<string, object>(), "api/user/GetDictionary", "User").Result;
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();
        }
コード例 #27
0
        public Pool(
            ActorService actorService,
            ActorId actorId,
            IGuidGetter guidGetter                   = null,
            TelemetryClient telemetry                = null,
            IActorProxyFactory actorProxyFactory     = null,
            IServiceProxyFactory serviceProxyFactory = null)
            : base(actorService, actorId)
        {
            _kernel = new StandardKernel(new PoolActorModule(guidGetter))
                      .WithCore(actorService.Context, StateManager, telemetry: telemetry,
                                actorProxyFactory: actorProxyFactory, serviceProxyFactory: serviceProxyFactory)
                      .WithMediator()
                      .WithPools();

            _telemetryClient = _kernel.Get <TelemetryClient>();
            _mediator        = _kernel.Get <Mediator>();
        }
コード例 #28
0
        /// <summary>
        /// Creates a new default instance.
        /// </summary>
        public BrokerServiceLocator(bool useRemotingV2 = false, IHashingHelper hashingHelper = null)
        {
            _hashingHelper = hashingHelper ?? new HashingHelper();
            _fabricClient  = new FabricClient();

#if NETSTANDARD2_0
            _serviceProxyFactory = new ServiceProxyFactory(c => new FabricTransportServiceRemotingClientFactory());
#else
            if (useRemotingV2)
            {
                _serviceProxyFactory = new ServiceProxyFactory(c => new FabricTransportServiceRemotingClientFactory());
            }
            else
            {
                _serviceProxyFactory = new ServiceProxyFactory();
            }
#endif
        }
コード例 #29
0
        /// <summary>
        /// This method is called whenever an actor is activated.
        /// An actor is activated the first time any of its methods are invoked.
        /// </summary>
        protected override async Task OnActivateAsync()
        {
            ActorEventSource.Current.ActorMessage(this, "Actor activated.");

            _tokenSource         = new CancellationTokenSource();
            _builder             = new SharedUriBuilder(ActorService.Context.CodePackageActivationContext, InventoryServiceNameKey);
            _serviceProxyFactory = new ServiceProxyFactory();

            var orderStatusResult = await GetOrderStatusAsync();

            // Init order if it's new
            if (orderStatusResult == OrderStatusTypeDto.Unknown)
            {
                await StateManager.SetStateAsync(OrdersKey, new List <OrderDto>());

                await StateManager.SetStateAsync <long>(RequestIdPropertyKey, 0);
                await SetOrderStatusAsync(OrderStatusTypeDto.New);
            }
        }
コード例 #30
0
        public static void TestThriftInvoker(IServiceProxyFactory serviceProxyFactory)
        {
            var proxy  = serviceProxyFactory.CreateProxy <IAsyncService>();
            var proxy1 = serviceProxyFactory.CreateProxy <IThirdAsyncService>();

            Task.Run(async() =>
            {
                do
                {
                    var result1 = await proxy.SayHelloAsync();
                    var result2 = await proxy1.SayHelloAsync();
                    Console.WriteLine("正在循环 1w次调用 GetUser.....");

                    var watch = Stopwatch.StartNew();

                    for (var i = 0; i < 10000; i++)
                    {
                        try
                        {
                            var result = await proxy.SayHelloAsync();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                    }
                    watch.Stop();
                    Console.WriteLine($"1w次调用结束,执行时间:{watch.ElapsedMilliseconds}ms");
                    Console.WriteLine("Press any key to continue, q to exit the loop...");
                    var key = Console.ReadLine();
                    if (key.ToLower() == "q")
                    {
                        break;
                    }
                } while (true);
            }).Wait();

            Console.ReadLine();
        }
 /// <summary>
 /// Adding this method to support DI/Testing 
 /// We need to do some work to create the actor object and make sure it is constructed completely
 /// In local testing we can inject the components we need, but in a real cluster
 /// those items are not established until the actor object is activated. Thus we need to 
 /// have this method so that the tests can have the same init path as the actor would in prod
 /// </summary>
 /// <returns></returns>
 public async Task InternalActivateAsync(ICodePackageActivationContext context, IServiceProxyFactory proxyFactory)
 {
     this.tokenSource = new CancellationTokenSource();
     this.builder = new ServiceUriBuilder(context, InventoryServiceName);
     this.ServiceProxyFactory = proxyFactory;
 }