/// <summary> /// Gets the <see cref="BrokerActor"/> instance for the provided <paramref name="message"/> /// </summary> /// <param name="message"></param> /// <param name="applicationName"></param> /// <returns></returns> private static IBrokerActor GetBrokerActorForMessage(object message, string applicationName) { ActorId actorId = new ActorId(message.GetType().FullName); IBrokerActor brokerActor = ActorProxy.Create <IBrokerActor>(actorId, applicationName, nameof(IBrokerActor)); return(brokerActor); }
/// <summary> /// Unregisters this Actor as a subscriber for messages of type <paramref name="messageType"/> using a <see cref="IRelayBrokerActor"/> approach. /// </summary> /// <param name="actor">The actor 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 async Task UnregisterMessageTypeWithRelayBrokerAsync(this ActorBase actor, Type messageType, ActorId relayBrokerActorId, ActorId sourceBrokerActorId, bool flushQueue) { if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } if (actor == null) { throw new ArgumentNullException(nameof(actor)); } if (relayBrokerActorId == null) { throw new ArgumentNullException(nameof(relayBrokerActorId)); } if (sourceBrokerActorId == null) { sourceBrokerActorId = new ActorId(messageType.FullName); } IRelayBrokerActor relayBrokerActor = ActorProxy.Create <IRelayBrokerActor>(relayBrokerActorId, actor.ApplicationName, nameof(IRelayBrokerActor)); IBrokerActor brokerActor = ActorProxy.Create <IBrokerActor>(sourceBrokerActorId, actor.ApplicationName, nameof(IBrokerActor)); //unregister relay as subscriber for broker await brokerActor.UnregisterSubscriberAsync(ActorReference.Get(relayBrokerActor), flushQueue); //unregister caller as subscriber for relay broker await relayBrokerActor.UnregisterSubscriberAsync(ActorReference.Get(actor), flushQueue); }
/// <summary> /// Unregisters a service as a subscriber for messages of type <paramref name="messageType"/>. /// </summary> /// <returns></returns> private static async Task UnregisterMessageTypeAsync(ServiceContext context, ServicePartitionInformation info, Type messageType, bool flushQueue) { var serviceReference = CreateServiceReference(context, info); ActorId actorId = new ActorId(messageType.FullName); IBrokerActor brokerActor = ActorProxy.Create <IBrokerActor>(actorId, serviceReference.ApplicationName, nameof(IBrokerActor)); await brokerActor.UnregisterServiceSubscriberAsync(serviceReference, flushQueue); }
/// <summary> /// Registers this Actor as a subscriber for messages of type <paramref name="messageType"/>. /// </summary> /// <returns></returns> public static async Task RegisterMessageTypeAsync(this ActorBase actor, Type messageType) { if (messageType == null) { throw new ArgumentNullException(nameof(messageType)); } if (actor == null) { throw new ArgumentNullException(nameof(actor)); } ActorId actorId = new ActorId(messageType.FullName); IBrokerActor brokerActor = ActorProxy.Create <IBrokerActor>(actorId, actor.ApplicationName, nameof(IBrokerActor)); await brokerActor.RegisterSubscriberAsync(ActorReference.Get(actor)); }
/// <summary> /// Unregisters a service as a subscriber for messages of type <paramref name="messageType"/> using a relay broker. /// </summary> /// <returns></returns> private static async Task UnregisterMessageTypeWithRelayBrokerAsync(ServiceContext context, ServicePartitionInformation info, Type messageType, ActorId relayBrokerActorId, ActorId sourceBrokerActorId, bool flushQueue) { var serviceReference = CreateServiceReference(context, info); if (sourceBrokerActorId == null) { sourceBrokerActorId = new ActorId(messageType.FullName); } IRelayBrokerActor relayBrokerActor = ActorProxy.Create <IRelayBrokerActor>(relayBrokerActorId, serviceReference.ApplicationName, nameof(IRelayBrokerActor)); IBrokerActor brokerActor = ActorProxy.Create <IBrokerActor>(sourceBrokerActorId, serviceReference.ApplicationName, nameof(IBrokerActor)); //register relay as subscriber for broker await brokerActor.UnregisterSubscriberAsync(ActorReference.Get(relayBrokerActor), flushQueue); //register caller as subscriber for relay broker await relayBrokerActor.UnregisterServiceSubscriberAsync(serviceReference, flushQueue); }