/// <summary>
        /// Unregisters a service as a subscriber for messages.
        /// </summary>
        /// <param name="messageTypeName">Full type name of message object.</param>
        /// <param name="service">Reference to the actor to unsubscribe.</param>
        /// <param name="flushQueue">Publish any remaining messages.</param>
        public async Task UnregisterServiceSubscriberAsync(ServiceReference service, string messageTypeName,
                                                           bool flushQueue)
        {
            var serviceReference = new ServiceReferenceWrapper(service);

            await UnregisterSubscriberAsync(serviceReference, messageTypeName);
        }
Esempio n. 2
0
        public void WhenDeserializing_ThenNameIsPreserved()
        {
            var serviceRef = new ServiceReferenceWrapper(new ServiceReference(), "A=B");
            var serializer = new DataContractSerializer(typeof(ServiceReferenceWrapper));

            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, serviceRef);
                stream.Position = 0;

                var cloneServiceRef = (ServiceReferenceWrapper)serializer.ReadObject(stream);
                Assert.AreEqual(serviceRef.Name, cloneServiceRef.Name);
            }
        }
Esempio n. 3
0
        public void WhenDeterminingShouldDeliverMessageToServiceWithUnmatchingPayload_ThenReturnsFalse()
        {
            var serviceRef     = new ServiceReferenceWrapper(new ServiceReference(), "Customer.Name=Customer1");
            var messageWrapper = new
            {
                Customer = new
                {
                    Name = "Customer2"
                }
            }.CreateMessageWrapper();

            bool shouldDeliver = serviceRef.ShouldDeliverMessage(messageWrapper);

            Assert.IsFalse(shouldDeliver);
        }
        /// <summary>
        /// Registers a service as a subscriber for messages.
        /// </summary>
        /// <param name="service">Reference to the service to register.</param>
        public async Task RegisterServiceSubscriberAsync(ServiceReference service)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            ActorEventSourceMessage($"Registering Subscriber '{service.ServiceUri}' for messages of type '{_messageType}'");

            var serviceReference = new ServiceReferenceWrapper(service);
            var state            = await StateManager.GetStateAsync <BrokerActorState>(StateKey);

            if (!state.SubscriberMessages.ContainsKey(serviceReference))
            {
                state.SubscriberMessages.Add(serviceReference, new Queue <MessageWrapper>());
            }
        }
Esempio n. 5
0
        public void WhenDeserializing_ThenHashingHelperIsNotNull()
        {
            var serviceRef = new ServiceReferenceWrapper(new ServiceReference(), "A=B");
            var serializer = new DataContractSerializer(typeof(ServiceReferenceWrapper));

            using (var stream = new MemoryStream())
            {
                serializer.WriteObject(stream, serviceRef);
                stream.Position = 0;

                var cloneServiceRef = (ServiceReferenceWrapper)serializer.ReadObject(stream);
                var hashingHelper   = typeof(ServiceReferenceWrapper)
                                      .GetProperty("HashingHelper", BindingFlags.Instance | BindingFlags.NonPublic)
                                      .GetValue(cloneServiceRef);

                Assert.IsInstanceOfType(hashingHelper, typeof(IHashingHelper));
            }
        }
        /// <summary>
        /// Unregisters a service as a subscriber for messages.
        /// </summary>
        /// <param name="service">Reference to the actor to unsubscribe.</param>
        /// <param name="flushQueue">Publish any remaining messages.</param>
        public async Task UnregisterServiceSubscriberAsync(ServiceReference service, bool flushQueue)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }

            ActorEventSourceMessage($"Unregistering Subscriber '{service.ServiceUri}' for messages of type '{_messageType}'");

            var serviceReference = new ServiceReferenceWrapper(service);
            Queue <MessageWrapper> queue;
            var state = await StateManager.GetStateAsync <BrokerActorState>(StateKey);

            if (flushQueue && state.SubscriberMessages.TryGetValue(serviceReference, out queue))
            {
                await ProcessQueueAsync(new KeyValuePair <ReferenceWrapper, Queue <MessageWrapper> >(serviceReference, queue));
            }
            state.SubscriberMessages.Remove(serviceReference);
        }
        /// <summary>
        /// Registers a service as a subscriber for messages.
        /// </summary>
        /// <param name="messageTypeName">Full type name of message object.</param>
        /// <param name="service">Reference to the service to register.</param>
        public async Task RegisterServiceSubscriberAsync(ServiceReference service, string messageTypeName)
        {
            var serviceReference = new ServiceReferenceWrapper(service);

            await RegisterSubscriberAsync(serviceReference, messageTypeName);
        }