/// <inheritdoc /> public async Task <IBrokerService> GetBrokerServiceForMessageAsync(object message, Uri brokerServiceName) { var resolvedPartition = await GetPartitionForMessageAsync(message, brokerServiceName); var brokerService = _serviceProxyFactory.CreateServiceProxy <IBrokerService>(brokerServiceName, resolvedPartition, listenerName: BrokerServiceBase.ListenerName); return(brokerService); }
/// <inheritdoc /> public async Task <IBrokerService> GetBrokerServiceForMessageAsync(object message) { if (message == null) { throw new ArgumentNullException(nameof(message)); } var resolvedPartition = await GetPartitionForMessageAsync(message); return(_serviceProxyFactory.CreateServiceProxy <IBrokerService>( await LocateAsync(), resolvedPartition, listenerName: BrokerServiceBase.ListenerName)); }
/// <summary> /// Attempts to publish the message to a listener. /// </summary> /// <param name="message"></param> /// <returns></returns> public override Task PublishAsync(MessageWrapper message) { ServicePartitionKey partitionKey; switch (ServiceReference.PartitionKind) { case ServicePartitionKind.Singleton: partitionKey = ServicePartitionKey.Singleton; break; case ServicePartitionKind.Int64Range: partitionKey = new ServicePartitionKey(ServiceReference.PartitionKey); break; case ServicePartitionKind.Named: partitionKey = new ServicePartitionKey(ServiceReference.PartitionName); break; default: throw new ArgumentOutOfRangeException(); } var client = _serviceProxyFactory.CreateServiceProxy <ISubscriberService>(ServiceReference.ServiceUri, partitionKey); return(client.ReceiveMessageAsync(message)); }
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))); }
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>()); }
public async Task Handle(T message, IMessageHandlerContext context) { try { var hashedJobId = GetHashJobId(message.JobId); //TO ensure jobs aren't placed into the same partition Logger.LogVerbose($"Getting actor for job: {message.JobId}"); var service = proxyFactory.CreateServiceProxy <IJobService>(new Uri(ServiceUris.JobService), new ServicePartitionKey(hashedJobId)); await HandleMessage(message, context, service, CancellationToken.None).ConfigureAwait(false); } catch (Exception ex) { Logger.LogWarning($"Failed to record earnings job. Job id: {message.JobId}, Error: {ex.Message}. {ex}"); throw; } }
// GET / public async Task <IEnumerable <string> > Get() { var results = new List <string>(); foreach (var servicePartition in _speakerActorServicePartitions) { var speakerActorService = _serviceProxyFactory.CreateServiceProxy <ISpeakerActorService>( _speakerActorServiceUri, new ServicePartitionKey(servicePartition)); var foundResults = await speakerActorService.GetAllSpeakersAsync(CancellationToken.None); foreach (var foundResult in foundResults) { results.Add(foundResult.Name); } } return(results); }
private async Task ExecuteOrderAsync() { await SetOrderStatusAsync(OrderStatusTypeDto.InProcess); var orderedItems = await StateManager.GetStateAsync <List <OrderDto> >(OrdersKey); ActorEventSource.Current.ActorMessage(this, "Executing customer order. ID: {0}. Items: {1}", Id.GetGuidId(), orderedItems.Count); foreach (var item in orderedItems) { ActorEventSource.Current.Message("Order contains:{0}", item); } // Throught all ordered items foreach (var item in orderedItems.Where(x => x.Remaining > 0)) { var inventoryService = _serviceProxyFactory.CreateServiceProxy <IInventoryService>(_builder.ToUri()); // Check the item is listed in inventory if (await inventoryService.IsItemInInventoryAsync(item.Item.Id, _tokenSource.Token) == false) { await SetOrderStatusAsync(OrderStatusTypeDto.Canceled); return; } var numberItemsRemoved = await inventoryService.RemoveStockAsync( item.Item.Id, item.Quantity, new OrderActorMessageId( new ActorId(Id.GetGuidId()), await StateManager.GetStateAsync <long>(RequestIdPropertyKey))); item.Remaining -= numberItemsRemoved; } var items = await StateManager.GetStateAsync <IList <OrderDto> >(OrdersKey); bool backordered = false; // Set proper status foreach (var item in items) { if (item.Remaining > 0) { backordered = true; break; } } if (backordered) { await SetOrderStatusAsync(OrderStatusTypeDto.Backordered); } else { await SetOrderStatusAsync(OrderStatusTypeDto.Shipped); } ActorEventSource.Current.ActorMessage( this, "{0}; Executed: {1}. Backordered: {2}", await GetOrderStatusAsStringAsync(), items.Count(x => x.Remaining == 0), items.Count(x => x.Remaining > 0)); long messageRequestId = await StateManager.GetStateAsync <long>(RequestIdPropertyKey); await StateManager.SetStateAsync(RequestIdPropertyKey, ++messageRequestId); }
public Task OccupyAsync(Uri serviceUri, Guid instanceId, string instanceName) => services.CreateServiceProxy <IServiceInstance>(serviceUri).OccupyAsync(instanceId.ToString(), instanceName);
/// <summary> /// Initializes a new instance of the <see cref="DealerController" /> class. /// </summary> /// <param name="serviceProxyFactory">The service proxy factory.</param> public StoreController(IServiceProxyFactory serviceProxyFactory) { this.client = serviceProxyFactory.CreateServiceProxy <IStoreRemotingListener>(new Uri("fabric:/StorageToService/StoreService"), new ServicePartitionKey(1)); }