protected virtual void Initialize(StatelessService instance, IStartable starter) { var path = Utility.GetDefaultPartitionUri(instance); this.Path = Util.GetWcfUri(path); this.Stateless = instance; this.Starter = starter; }
public ICommunicationListener CreateCommunicationListener(StatelessService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } return new AspNetCoreCommunicationListener(this, service); }
public void ServiceMessage(StatelessService service, string message, params object[] args) { if (IsEnabled()) { ServiceMessage( service.Context.ServiceName.ToString(), service.Context.ServiceTypeName, service.Context.InstanceId, service.Context.PartitionId, service.Context.CodePackageActivationContext.ApplicationName, service.Context.CodePackageActivationContext.ApplicationTypeName, service.Context.NodeContext.NodeName, string.Format(message, args)); } }
public void ServiceMessage(StatelessService service, string message, params object[] args) { if (this.IsEnabled()) { string finalMessage = string.Format(message, args); this.ServiceMessage( service.Context.ServiceName.ToString(), service.Context.ServiceTypeName, service.Context.InstanceId, service.Context.PartitionId, service.Context.CodePackageActivationContext.ApplicationName, service.Context.CodePackageActivationContext.ApplicationTypeName, FabricRuntime.GetNodeContext().NodeName, finalMessage); } }
public void ServiceMessage(StatelessService service, string message, params object[] args) { if (this.IsEnabled()) { string finalMessage = string.Format(message, args); ServiceMessage( service.ServiceInitializationParameters.ServiceName.ToString(), service.ServiceInitializationParameters.ServiceTypeName, service.ServiceInitializationParameters.InstanceId, service.ServiceInitializationParameters.PartitionId, service.ServiceInitializationParameters.CodePackageActivationContext.ApplicationName, service.ServiceInitializationParameters.CodePackageActivationContext.ApplicationTypeName, FabricRuntime.GetNodeContext().NodeName, finalMessage); } }
/// <summary> /// Unregisters a Service as a subscriber for messages of type <paramref name="messageType"/> using a <see cref="IRelayBrokerActor"/> approach. /// </summary> /// <param name="service">The service registering itself as a subscriber for messages of type <paramref name="messageType"/></param> /// <param name="messageType">The type of message to unregister for (each message type has its own <see cref="IBrokerActor"/> instance)</param> /// <param name="relayBrokerActorId">The ID of the relay broker to unregister with.</param> /// <param name="sourceBrokerActorId">(optional) The ID of the source <see cref="IBrokerActor"/> that was used as the source for the <paramref name="relayBrokerActorId"/> /// If not specified, the default <see cref="IBrokerActor"/> for the message type <paramref name="messageType"/> will be used.</param> /// <param name="flushQueue">Publish any remaining messages.</param> /// <returns></returns> public static Task UnregisterMessageTypeWithRelayBrokerAsync(this StatelessService service, Type messageType, ActorId relayBrokerActorId, ActorId sourceBrokerActorId, bool flushQueue) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } if (relayBrokerActorId == null) { throw new ArgumentNullException(nameof(relayBrokerActorId)); } return(UnregisterMessageTypeWithRelayBrokerAsync(service.Context, service.GetServicePartition().PartitionInfo, messageType, relayBrokerActorId, sourceBrokerActorId, flushQueue)); }
public void ServiceMessage(StatelessService service, string message, string correlationId, params object[] args) { if (this.IsEnabled()) { string finalMessage = string.Format(message, args); ServiceMessage( service.Context.ServiceName.ToString(), service.Context.ServiceTypeName, service.Context.InstanceId, service.Context.PartitionId, service.Context.CodePackageActivationContext.ApplicationName, service.Context.CodePackageActivationContext.ApplicationTypeName, service.Context.NodeContext.NodeName, finalMessage, correlationId); } }
/// <summary> /// Adds Service Fabric support to the provided service collection. /// </summary> /// <param name="serviceCollection">The service collection.</param> /// <param name="service">The Service Fabric service.</param> /// <returns>The provided service collection.</returns> public static IServiceCollection AddServiceFabricSupport( this IServiceCollection serviceCollection, StatelessService service) { AddStandardServices(serviceCollection); // Use Service Fabric for cluster membership. serviceCollection.AddSingleton <IFabricServiceSiloResolver>( sp => new FabricServiceSiloResolver( service.Context.ServiceName, sp.GetService <IFabricQueryManager>(), sp.GetService <Func <string, Logger> >())); serviceCollection.AddSingleton <IMembershipOracle, FabricMembershipOracle>(); serviceCollection.AddSingleton <IGatewayListProvider, FabricGatewayProvider>(); serviceCollection.AddTransient <ServiceContext>(_ => service.Context); return(serviceCollection); }
void MockServiceContext <I>(StatelessService target) { ServiceContext context = new ServiceContext(); if (target == null) { Type serviceType = FabricRuntime.Services.Values.SelectMany(types => types.Where(type => type.GetInterfaces().Any(i => i == typeof(I)))).FirstOrDefault(); context.ServiceName = ServiceAddress(serviceType); ServiceContextHelper.Add(OperationContext.Current.OutgoingMessageHeaders, context); AddStandardContexts(OperationContext.Current.OutgoingMessageHeaders); } else { context.ServiceName = ServiceAddress(target.GetType()); MockMessage(); ServiceContextHelper.Add(OperationContext.Current.IncomingMessageHeaders, context); AddStandardContexts(OperationContext.Current.IncomingMessageHeaders); } }
void MockServiceContext <I>(StatelessService target) { ServiceContext context = new ServiceContext(); if (target == null) { Type serviceType = FabricRuntime.Services.Values.SelectMany(types => types.Where(type => type.GetInterfaces().Any(i => i == typeof(I)))).FirstOrDefault(); context.ServiceName = ServiceAddress(serviceType); ServiceContextHelper.Add(OperationContext.Current.OutgoingMessageHeaders, context); } else { context.ServiceName = ServiceAddress(target.GetType()); FieldInfo request = typeof(OperationContext).GetField("request", BindingFlags.NonPublic | BindingFlags.Instance); Message message = Message.CreateMessage(MessageVersion.Soap12, "void"); request.SetValue(OperationContext.Current, message); ServiceContextHelper.Add(OperationContext.Current.IncomingMessageHeaders, context); } }
IEnumerable <ServiceRemotingDispatcher> GetDispatchers(Type serviceType, ServiceEndpoint endpoint) { List <ServiceRemotingDispatcher> dispatchers = new List <ServiceRemotingDispatcher>(); StatelessServiceContext serviceContext = new StatelessServiceContext(); StatelessService service = Activator.CreateInstance(serviceType, serviceContext) as StatelessService; foreach (ServiceInstanceListener instanceListener in service.ServiceInstanceListeners) { if (instanceListener.Name.Equals(endpoint.Contract.Name)) { IServiceRemotingListener listener = instanceListener.CreateCommunicationListener(serviceContext) as IServiceRemotingListener; if (listener.Dispatcher != null) { dispatchers.Add(listener.Dispatcher); } } } return(dispatchers); }
public static async Task PublishMessageAsync(this StatelessService service, object message, string applicationName = null) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (message == null) { throw new ArgumentNullException(nameof(message)); } if (string.IsNullOrWhiteSpace(applicationName)) { applicationName = service.Context.CodePackageActivationContext.ApplicationName; } var brokerActor = GetBrokerActorForMessage(applicationName, message); var wrapper = message.CreateMessageWrapper(); await brokerActor.PublishMessageAsync(wrapper); }
public HttpCommunicationListener(string uriPrefix, string uriPublished, StatelessService svc) { this.svc = svc; ServiceEventSource.Current.ServiceMessage(this.svc, "Building config " + uriPrefix); var config = new ConfigurationBuilder() .AddJsonFile("config.json") .AddCommandLine(new string[] { "--detailedErrors", "true", "--webroot", "../../../wwwroot", "--server", "Microsoft.AspNet.Server.WebListener", "--server.urls", uriPrefix }) .AddEnvironmentVariables().Build(); ServiceEventSource.Current.ServiceMessage(this.svc, "Building engine"); this.engine = new WebApplicationBuilder().UseConfiguration(config).UseStartup(typeof(GearUp.Startup)).Build(); ServiceEventSource.Current.ServiceMessage(this.svc, "starting"); this.application = engine.Start(); ServiceEventSource.Current.ServiceMessage(this.svc, "started"); this.publishUri = uriPublished; }
public static async Task UnregisterMessageTypeWithBrokerServiceAsync(this StatelessService service, Type messageType, bool flushQueue, Uri brokerServiceName = null) { if (service == null) { throw new ArgumentNullException(nameof(service)); } if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } if (brokerServiceName == null) { brokerServiceName = await PublisherServices.PublisherServiceExtensions.DiscoverBrokerServiceNameAsync(new Uri(service.Context.CodePackageActivationContext.ApplicationName)); if (brokerServiceName == null) { throw new InvalidOperationException("No brokerServiceName was provided or discovered in the current application."); } } var brokerService = await PublisherActors.PublisherActorExtensions.GetBrokerServiceForMessageAsync(messageType.Name, brokerServiceName); var serviceReference = CreateServiceReference(service.Context, service.GetServicePartition().PartitionInfo); await brokerService.UnregisterServiceSubscriberAsync(serviceReference, messageType.FullName, flushQueue); }
/// <summary> /// Invokes CreateServiceInstanceListeners on the provided <paramref name="service"/>. /// </summary> /// <param name="service"></param> /// <returns></returns> public static IEnumerable <ServiceInstanceListener> InvokeCreateServiceInstanceListeners(this StatelessService service) { if (service == null) { throw new ArgumentNullException(nameof(service)); } //protected virtual IEnumerable<ServiceInstanceListener> CreateServiceInstanceListeners() var method = FindMethodInfo(service, "CreateServiceInstanceListeners"); return((IEnumerable <ServiceInstanceListener>)method.Invoke(service, null)); }
public ServiceReference CreateServiceReference(StatelessService service, string listenerName = null) { return(new ServiceReference()); }
public Task UnregisterMessageTypeAsync(StatelessService service, Type messageType, bool flushQueue, Uri brokerServiceName = null) { return(Task.CompletedTask); }
public Task RegisterMessageTypeAsync(StatelessService service, Type messageType, Uri brokerServiceName = null, string listenerName = null) { return(Task.CompletedTask); }
public static IMessageConsumer CreateConsumer(this StatelessService service, ServicePartitionInformation partition, IBrokerServiceLocator serviceLocator) { return(service.Context.CreateConsumer(partition, serviceLocator)); }
public static IMessageConsumer CreateConsumer(this StatelessService service, ServicePartitionInformation partition) { return(service.Context.CreateConsumer(partition)); }
//TcpRouter router = new TcpRouter(); public void Initialize(StatelessService stateless) { base.Initialize(stateless, router.Service); this.Path = Utility.GetDefaultServiceUri(stateless.ServiceInitializationParameters).Uri; router.Initialize(this.Path, resolver); }
public Handler(StatelessService service) { _service = service; }
internal static Task UnsubscribeAsync(this IBrokerClient brokerClient, StatelessService service, Type messageType) { return(brokerClient.UnsubscribeAsync(CreateReferenceWrapper(service), messageType)); }
// subscribe/unsubscribe using Type (useful when processing Subscribe attributes) internal static Task SubscribeAsync <T>(this IBrokerClient brokerClient, StatelessService service, Type messageType, Func <T, Task> handler, string listenerName = null, string routingKey = null, bool isOrdered = true) where T : class { return(brokerClient.SubscribeAsync(CreateReferenceWrapper(service, listenerName, routingKey), messageType, handler, isOrdered)); }
public ServiceLogger(StatelessService service) { _service = service; _client = new FabricClient(); }
public void Initialize(StatelessService stateless) { base.Initialize(stateless, service); service.Initialize(this.Path, stateless); }
public void ServiceMessage(StatelessService service, string message, params object[] args) { this.ServiceMessage(service.Context, message, args); }
public static void Should_invoke_packages_events_On_stateless_service_package_activation_events() { // Arrange var actualCallStack = new ConcurrentQueue <string>(); var mockCodePackageActivationContext = new Mock <ICodePackageActivationContext>(); mockCodePackageActivationContext .Setup(instance => instance.ApplicationName) .Returns("Application"); mockCodePackageActivationContext .Setup(instance => instance.ApplicationTypeName) .Returns("ApplicationType"); var mockDelegateCodePackageAdded = new Mock <Action>(); mockDelegateCodePackageAdded .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("codepackage.added")) .Verifiable(); var mockDelegateCodePackageModified = new Mock <Action>(); mockDelegateCodePackageModified .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("codepackage.modified")) .Verifiable(); var mockDelegateCodePackageRemoved = new Mock <Action>(); mockDelegateCodePackageRemoved .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("codepackage.removed")) .Verifiable(); var mockDelegateConfigPackageAdded = new Mock <Action>(); mockDelegateConfigPackageAdded .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("configpackage.added")) .Verifiable(); var mockDelegateConfigPackageModified = new Mock <Action>(); mockDelegateConfigPackageModified .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("configpackage.modified")) .Verifiable(); var mockDelegateConfigPackageRemoved = new Mock <Action>(); mockDelegateConfigPackageRemoved .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("configpackage.removed")) .Verifiable(); var mockDelegateDataPackageAdded = new Mock <Action>(); mockDelegateDataPackageAdded .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("datapackage.added")) .Verifiable(); var mockDelegateDataPackageModified = new Mock <Action>(); mockDelegateDataPackageModified .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("datapackage.modified")) .Verifiable(); var mockDelegateDataPackageRemoved = new Mock <Action>(); mockDelegateDataPackageRemoved .Setup(instance => instance()) .Callback(() => actualCallStack.Enqueue("datapackage.removed")) .Verifiable(); var mockEventSourceReplicator = MockStatefulServiceHostEventSourceReplicator(); var mockDelegateReplicators = new[] { MockDelegateReplicatorForEvent( mockDelegateCodePackageAdded.Object, StatelessServiceLifecycleEvent.OnCodePackageAdded), MockDelegateReplicatorForEvent( mockDelegateCodePackageModified.Object, StatelessServiceLifecycleEvent.OnCodePackageModified), MockDelegateReplicatorForEvent( mockDelegateCodePackageRemoved.Object, StatelessServiceLifecycleEvent.OnCodePackageRemoved), MockDelegateReplicatorForEvent( mockDelegateConfigPackageAdded.Object, StatelessServiceLifecycleEvent.OnConfigPackageAdded), MockDelegateReplicatorForEvent( mockDelegateConfigPackageModified.Object, StatelessServiceLifecycleEvent.OnConfigPackageModified), MockDelegateReplicatorForEvent( mockDelegateConfigPackageRemoved.Object, StatelessServiceLifecycleEvent.OnConfigPackageRemoved), MockDelegateReplicatorForEvent( mockDelegateDataPackageAdded.Object, StatelessServiceLifecycleEvent.OnDataPackageAdded), MockDelegateReplicatorForEvent( mockDelegateDataPackageModified.Object, StatelessServiceLifecycleEvent.OnDataPackageModified), MockDelegateReplicatorForEvent( mockDelegateDataPackageRemoved.Object, StatelessServiceLifecycleEvent.OnDataPackageRemoved) }; var statelessContext = MockStatelessServiceContextFactory.Create( mockCodePackageActivationContext.Object, "Mock", new Uri("fabric:/mock"), Guid.NewGuid(), 0); var statelessInstance = new StatelessService( statelessContext, mockEventSourceReplicator, mockDelegateReplicators, Array.Empty <IStatelessServiceHostListenerReplicator>()); // Act mockCodePackageActivationContext .Raise(instance => instance.CodePackageAddedEvent -= null, new PackageAddedEventArgs <CodePackage>()); mockCodePackageActivationContext .Raise(instance => instance.CodePackageModifiedEvent -= null, new PackageModifiedEventArgs <CodePackage>()); mockCodePackageActivationContext .Raise(instance => instance.CodePackageRemovedEvent -= null, new PackageRemovedEventArgs <CodePackage>()); mockCodePackageActivationContext .Raise(instance => instance.ConfigurationPackageAddedEvent -= null, new PackageAddedEventArgs <ConfigurationPackage>()); mockCodePackageActivationContext .Raise(instance => instance.ConfigurationPackageModifiedEvent -= null, new PackageModifiedEventArgs <ConfigurationPackage>()); mockCodePackageActivationContext .Raise(instance => instance.ConfigurationPackageRemovedEvent -= null, new PackageRemovedEventArgs <ConfigurationPackage>()); mockCodePackageActivationContext .Raise(instance => instance.DataPackageAddedEvent -= null, new PackageAddedEventArgs <DataPackage>()); mockCodePackageActivationContext .Raise(instance => instance.DataPackageModifiedEvent -= null, new PackageModifiedEventArgs <DataPackage>()); mockCodePackageActivationContext .Raise(instance => instance.DataPackageRemovedEvent -= null, new PackageRemovedEventArgs <DataPackage>()); // Assert mockDelegateCodePackageAdded.Verify(); mockDelegateCodePackageModified.Verify(); mockDelegateCodePackageRemoved.Verify(); mockDelegateConfigPackageAdded.Verify(); mockDelegateConfigPackageModified.Verify(); mockDelegateConfigPackageRemoved.Verify(); mockDelegateDataPackageAdded.Verify(); mockDelegateDataPackageModified.Verify(); mockDelegateDataPackageRemoved.Verify(); Assert.Equal(9, actualCallStack.Count); Assert.Equal( "codepackage.added", actualCallStack.TryDequeue(out var result) ? result : null); Assert.Equal( "codepackage.modified", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "codepackage.removed", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "configpackage.added", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "configpackage.modified", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "configpackage.removed", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "datapackage.added", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "datapackage.modified", actualCallStack.TryDequeue(out result) ? result : null); Assert.Equal( "datapackage.removed", actualCallStack.TryDequeue(out result) ? result : null); }
public static ServiceInstanceListener CreateWcfListener <TStatelessService, TStatelessServiceImpl>(this StatelessService serviceImplementation, string endpointName) where TStatelessServiceImpl : TStatelessService { return(new ServiceInstanceListener(context => CreateWcfTcpCommunicationListener <TStatelessService, TStatelessServiceImpl>(context, endpointName, Activator.CreateInstance <TStatelessServiceImpl>(), null))); }
public static I ForComponent <I>(StatelessService caller, ServicePartitionKey partitionKey = null) where I : class, IService { Debug.Assert(caller != null, "Invalid component call. Must supply stateless service caller."); return(ForService <I>(defaultProxyFactory, Addressing.Component <I>(caller), partitionKey)); }
/// <summary> /// Gets a reference to a StatelessService. /// </summary> /// <param name="service">The service.</param> /// <returns><see cref="ServiceReference"/></returns> public static ServiceReference GetServiceReference(this StatelessService service) { return(CreateServiceReference(service.Context, GetServicePartition(service).PartitionInfo)); }
public AspNetCoreCommunicationListener(AspNetCoreCommunicationContext context, StatelessService service) { if (context == null) { throw new ArgumentNullException(nameof(context)); } if (service == null) { throw new ArgumentNullException(nameof(service)); } _context = context; _service = service; _registry = _context.WebHost.Services.GetService <ServiceFabricServiceRegistry>(); }
public static I ForComponent <I>(StatelessService caller) where I : class, IService { Debug.Assert(caller != null, "Invalid component call. Must supply stateless service caller."); return(Create <I>(Addressing.Component <I>(caller), null)); }
public static ServiceInstanceListener CreateCorrelatingServiceInstanceListener <TServiceInterface>(this StatelessService service, IService serviceImplementation, string listenerName = "", Action <CallSummary> raiseSummary = null) { var handler = new CorrelatingRemotingMessageHandler(L.G <TServiceInterface>(), service.Context, serviceImplementation, raiseSummary); var listener = new ServiceInstanceListener(c => new FabricTransportServiceRemotingListener(c, handler), listenerName); return(listener); }
/// <summary> /// Unregisters this StatelessService as a subscriber for messages of type <typeparam name="T"/> with the <see cref="BrokerService"/>. /// </summary> /// <param name="brokerClient"></param> /// <param name="service"></param> /// <returns></returns> public static Task UnsubscribeAsync <T>(this IBrokerClient brokerClient, StatelessService service) where T : class { return(brokerClient.UnsubscribeAsync(CreateReferenceWrapper(service), typeof(T))); }