/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { // Listeners can be opened and closed multiple times over the lifetime of a service instance. // A new Orleans silo will be both created and initialized each time the listener is opened and will be shutdown // when the listener is closed. var listener = OrleansServiceListener.CreateStateless( (serviceContext, builder) => { // Use Service Fabric for cluster membership. builder.AddServiceFabricMembership(serviceContext); // Optional: configure logging. builder.ConfigureLogging(logging => logging.AddDebug()); var config = new ClusterConfiguration(); config.Globals.RegisterBootstrapProvider <BootstrapProvider>("poke_grains"); config.Globals.ReminderServiceType = GlobalConfiguration.ReminderServiceProviderType.ReminderTableGrain; // Service Fabric manages port allocations, so update the configuration using those ports. config.Defaults.ConfigureServiceFabricSiloEndpoints(serviceContext); // Tell Orleans to use this configuration. builder.UseConfiguration(config); // Add your application assemblies. builder.AddApplicationPart(typeof(ICalculatorGrain).Assembly); // Alternative: add all loadable assemblies in the current base path (see AppDomain.BaseDirectory). builder.AddApplicationPartsFromBasePath(); }); return(new[] { listener }); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { // Listeners can be opened and closed multiple times over the lifetime of a service instance. // A new Orleans silo will be both created and initialized each time the listener is opened // and will be shutdown when the listener is closed. var listener = OrleansServiceListener.CreateStateless( (fabricServiceContext, builder) => { builder.Configure <ClusterOptions>(options => { // The service id is unique for the entire service over its lifetime. This is // used to identify persistent state such as reminders and grain state. options.ServiceId = fabricServiceContext.ServiceName.ToString(); // The cluster id identifies a deployed cluster. Since Service Fabric uses rolling // upgrades, the cluster id can be kept constant. This is used to identify which // silos belong to a particular cluster. options.ClusterId = "development"; }); // Configure clustering. Other clustering providers are available, but for the purpose // of this sample we will use Azure Storage. // TODO: Pick a clustering provider and configure it here. builder.UseAzureStorageClustering( options => options.ConnectionString = "UseDevelopmentStorage=true"); // Optional: configure logging. builder.ConfigureLogging(loggingBuilder => loggingBuilder.AddDebug()); builder.AddStartupTask <StartupTask>(); // Service Fabric manages port allocations, so update the configuration using those // ports. // Gather configuration from Service Fabric. var activation = fabricServiceContext.CodePackageActivationContext; var endpoints = activation.GetEndpoints(); // These endpoint names correspond to TCP endpoints specified in ServiceManifest.xml var siloEndpoint = endpoints["OrleansSiloEndpoint"]; var gatewayEndpoint = endpoints["OrleansProxyEndpoint"]; var hostname = fabricServiceContext.NodeContext.IPAddressOrFQDN; builder.ConfigureEndpoints(hostname, siloEndpoint.Port, gatewayEndpoint.Port); // Add your application assemblies. builder.ConfigureApplicationParts(parts => { //parts.AddApplicationPart(typeof(CalculatorGrain).Assembly).WithReferences(); // Alternative: add all loadable assemblies in the current base path // (see AppDomain.BaseDirectory). parts.AddFromApplicationBaseDirectory(); }); }); return(new[] { listener }); }
protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { var listener = OrleansServiceListener.CreateStateless( (fabricServiceContext, builder) => { builder.Configure <ClusterOptions>(options => { options.ServiceId = fabricServiceContext.ServiceName.ToString(); options.ClusterId = "RitRunProto"; }); builder.UseAzureStorageClustering(options => options.ConnectionString = ConnectionString); builder.UseAzureTableReminderService(options => options.ConnectionString = ConnectionString); builder.AddAzureTableGrainStorageAsDefault(options => options.ConnectionString = ConnectionString); builder.ConfigureLogging(logging => logging.AddConsole().AddDebug()); var azBlobClient = new BlobServiceClient(ConnectionString); builder.ConfigureServices(svc => { svc.AddSingleton(azBlobClient); svc.AddSingleton <IRWBlobClient, RWBlobClient>(); }); var activation = fabricServiceContext.CodePackageActivationContext; var endpoints = activation.GetEndpoints(); var siloEndpoint = endpoints["OrleansSiloEndpoint"]; var gatewayEndpoint = endpoints["OrleansProxyEndpoint"]; var hostname = fabricServiceContext.NodeContext.IPAddressOrFQDN; builder.ConfigureEndpoints(hostname, siloEndpoint.Port, gatewayEndpoint.Port); builder.ConfigureApplicationParts(parts => { parts.AddFromApplicationBaseDirectory(); }); builder.UseDashboard(options => { }); }); return(new[] { listener }); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { // Listeners can be opened and closed multiple times over the lifetime of a service instance. // A new Orleans silo will be both created and initialized each time the listener is opened and will be shutdown // when the listener is closed. var listener = OrleansServiceListener.CreateStateless( (serviceContext, builder) => { builder.Configure <ClusterOptions>(options => { options.ServiceId = Guid.Empty; options.ClusterId = "dev"; }); // Optional: use Service Fabric for cluster membership. builder.UseServiceFabricClustering(serviceContext); // Optional: configure logging. builder.ConfigureLogging(logging => logging.AddDebug()); builder.AddStartupTask <StartupTask>(); builder.UseInMemoryReminderService(); // Service Fabric manages port allocations, so update the configuration using those ports. // Gather configuration from Service Fabric. var activation = serviceContext.CodePackageActivationContext; var endpoints = activation.GetEndpoints(); var siloEndpoint = endpoints[ServiceFabricConstants.SiloEndpointName]; var gatewayEndpoint = endpoints[ServiceFabricConstants.GatewayEndpointName]; var hostname = serviceContext.NodeContext.IPAddressOrFQDN; builder.ConfigureEndpoints(hostname, siloEndpoint.Port, gatewayEndpoint.Port); // Add your application assemblies. builder.ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(CalculatorGrain).Assembly).WithReferences(); // Alternative: add all loadable assemblies in the current base path (see AppDomain.BaseDirectory). parts.AddFromApplicationBaseDirectory(); }); }); return(new[] { listener }); }
/// <summary> /// 可选择性地替代以创建侦听器(如 TCP、HTTP),从而使此服务副本可以处理客户端或用户请求。 /// </summary> /// <returns>侦听器集合。</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { var configBuilder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true); var config = configBuilder.Build(); GlobalConfig.AddConfigurationObject(config, "all"); // Listeners can be opened and closed multiple times over the lifetime of a service instance. // A new Orleans silo will be both created and initialized each time the listener is opened and will be shutdown // when the listener is closed. var listener = OrleansServiceListener.CreateStateless( (fabricServiceContext, builder) => { builder.Configure <ClusterOptions>(options => { // The service id is unique for the entire service over its lifetime. This is used to identify persistent state // such as reminders and grain state. //options.ServiceId = fabricServiceContext.ServiceName.ToString(); options.ServiceId = config.GetSection("Orleans:ServiceId").Value; // The cluster id identifies a deployed cluster. Since Service Fabric uses rolling upgrades, the cluster id // can be kept constant. This is used to identify which silos belong to a particular cluster. options.ClusterId = config.GetSection("Orleans:ClusterId").Value; }); // Configure clustering. Other clustering providers are available, but for the purpose of this sample we // will use Azure Storage. // TODO: Pick a clustering provider and configure it here. //builder.UseAzureStorageClustering(options => options.ConnectionString = "UseDevelopmentStorage=true"); builder.UseAdoNetClustering(option => { option.ConnectionString = config.GetSection("Orleans:ConnectionString").Value; option.Invariant = config.GetSection("Orleans:Invariant").Value; }); // Optional: configure logging. builder.ConfigureLogging(logging => logging.AddConsole()); builder.AddStartupTask <StartupTask>(); //builder.AddStartupTask<StartupTask>(); // Service Fabric manages port allocations, so update the configuration using those ports. // Gather configuration from Service Fabric. var activation = fabricServiceContext.CodePackageActivationContext; var endpoints = activation.GetEndpoints(); //// These endpoint names correspond to TCP endpoints specified in ServiceManifest.xml var siloEndpoint = endpoints["OrleansSiloEndpoint"]; var gatewayEndpoint = endpoints["OrleansProxyEndpoint"]; var hostname = fabricServiceContext.NodeContext.IPAddressOrFQDN; builder.ConfigureEndpoints(hostname, siloEndpoint.Port, gatewayEndpoint.Port); // Add your application assemblies. builder.ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(HelloGrain).Assembly).WithReferences(); // Alternative: add all loadable assemblies in the current base path (see AppDomain.BaseDirectory). parts.AddFromApplicationBaseDirectory(); }); builder.UseDashboard(options => { options.Username = "******"; options.Password = "******"; options.Host = "*"; options.Port = 8080; options.HostSelf = true; options.CounterUpdateIntervalMs = 1000; }); }); return(new[] { listener }); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { ServiceEventSource.Current.Message($"[PID {Process.GetCurrentProcess().Id}] CreateServiceInstanceListeners()"); ClusterStartup.Service = this; return(new[] { OrleansServiceListener.CreateStateless(this.GetClusterConfiguration()) }); }
/// <summary> /// This factory creates a new listener for the Oreleans /// tier of our application. The table storage connection /// strings and other configuration information is presented /// in FabricSettings. /// </summary> /// <param name="settings">The <see cref="FabricSettings"/></param> /// <returns>A <see cref="ServiceInstanceListener"/> </returns> public static ServiceInstanceListener Get(FabricSettings settings) { return(OrleansServiceListener.CreateStateless( (ctx, builder) => Configure(ctx, builder, settings))); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { return(new[] { OrleansServiceListener.CreateStateless(this.GetClusterConfiguration()) }); }
/// <summary> /// Optional override to create listeners (e.g., TCP, HTTP) for this service replica to handle client or user requests. /// </summary> /// <returns>A collection of listeners.</returns> protected override IEnumerable <ServiceInstanceListener> CreateServiceInstanceListeners() { // Listeners can be opened and closed multiple times over the lifetime of a service instance. // A new Orleans silo will be both created and initialized each time the listener is opened and will be shutdown // when the listener is closed. var orleansListener = OrleansServiceListener.CreateStateless( (fabricServiceContext, siloBuilder) => { siloBuilder.Configure <ClusterOptions>(options => { // The service id is unique for the entire service over its lifetime. This is used to identify persistent state // such as reminders and grain state. options.ServiceId = fabricServiceContext.ServiceName.ToString(); // The cluster id identifies a deployed cluster. Since Service Fabric uses rolling upgrades, the cluster id // can be kept constant. This is used to identify which silos belong to a particular cluster. options.ClusterId = "development"; }); // Configure clustering to use Service Fabric membership. siloBuilder.UseServiceFabricClustering(fabricServiceContext); siloBuilder.ConfigureLogging(logging => logging.AddDebug()); siloBuilder.AddStartupTask <StartupTask>(); // Service Fabric manages port allocations, so update the configuration using those ports. // Gather configuration from Service Fabric. var activation = fabricServiceContext.CodePackageActivationContext; var endpoints = activation.GetEndpoints(); var siloEndpoint = endpoints["OrleansSiloEndpoint"]; var gatewayEndpoint = endpoints["OrleansProxyEndpoint"]; var hostname = fabricServiceContext.NodeContext.IPAddressOrFQDN; siloBuilder.ConfigureEndpoints(hostname, siloEndpoint.Port, gatewayEndpoint.Port); var configurationSection = activation.GetConfigurationPackageObject("Config").Settings.Sections["CosmosDbConfig"]; var configParameters = configurationSection.Parameters; siloBuilder.AddCosmosDbGraphGrainStorage("CosmosDBGraph", options => { options.Endpoint = configParameters["Endpoint"].Value; options.AuthKey = configParameters["AuthKey"].Value; options.Database = configParameters["Database"].Value; options.Collection = configParameters["Collection"].Value; }); // Add the application assemblies. siloBuilder.ConfigureApplicationParts(parts => { parts.AddApplicationPart(typeof(IAgent).Assembly); parts.AddApplicationPart(typeof(AgentGrain).Assembly); parts.AddApplicationPart(typeof(IVertex).Assembly); parts.AddApplicationPart(typeof(VertexGrain).Assembly); parts.AddApplicationPart(typeof(IPerson).Assembly); parts.AddApplicationPart(typeof(PersonVertex).Assembly); }); siloBuilder.UseSiloUnobservedExceptionsHandler(); }); return(new[] { orleansListener }); }
public static ServiceInstanceListener Get() { return(OrleansServiceListener.CreateStateless(Configure)); }