Ejemplo n.º 1
0
        /// <summary>
        /// Publish a message.
        /// </summary>
        /// <param name="service"></param>
        /// <param name="message"></param>
        /// <param name="brokerServiceName">The name of a SF Service of type <see cref="BrokerService"/>.</param>
        /// <returns></returns>
        public async Task PublishMessageAsync(StatelessService service, object message,
                                              Uri brokerServiceName = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (message == null)
            {
                throw new ArgumentNullException(nameof(message));
            }
            if (brokerServiceName == null)
            {
                brokerServiceName = await DiscoverBrokerServiceNameAsync();

                if (brokerServiceName == null)
                {
                    throw new InvalidOperationException(
                              "No brokerServiceName was provided or discovered in the current application.");
                }
            }

            var brokerService = await _brokerServiceLocator.GetBrokerServiceForMessageAsync(message, brokerServiceName);

            var wrapper = MessageWrapper.CreateMessageWrapper(message);
            await brokerService.PublishMessageAsync(wrapper);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers this Actor as a subscriber for messages of type <paramref name="messageType"/> with the <see cref="BrokerService"/>.
        /// </summary>
        /// <returns></returns>
        public async Task RegisterMessageTypeAsync(StatelessService service, Type messageType,
                                                   Uri brokerServiceName = null, string listenerName = null)
        {
            if (service == null)
            {
                throw new ArgumentNullException(nameof(service));
            }
            if (messageType == null)
            {
                throw new ArgumentNullException(nameof(messageType));
            }
            if (brokerServiceName == null)
            {
                brokerServiceName = await PublisherServiceHelper.DiscoverBrokerServiceNameAsync();

                if (brokerServiceName == null)
                {
                    throw new InvalidOperationException(
                              "No brokerServiceName was provided or discovered in the current application.");
                }
            }
            var brokerService =
                await _brokerServiceLocator.GetBrokerServiceForMessageAsync(messageType.Name, brokerServiceName);

            var serviceReference = CreateServiceReference(service.Context, GetServicePartition(service).PartitionInfo, listenerName);
            await brokerService.RegisterServiceSubscriberAsync(serviceReference, messageType.FullName);
        }
        private async Task RegisterMessageTypeAsync(ServiceReference serviceReference, Type messageType, Uri brokerServiceName = null)
        {
            if (messageType == null)
            {
                throw new ArgumentNullException(nameof(messageType));
            }
            if (brokerServiceName == null)
            {
                brokerServiceName = await PublisherServiceHelper.DiscoverBrokerServiceNameAsync();

                if (brokerServiceName == null)
                {
                    throw new InvalidOperationException("No brokerServiceName was provided or discovered in the current application.");
                }
            }
            var brokerService = await _brokerServiceLocator.GetBrokerServiceForMessageAsync(messageType.Name, brokerServiceName);

            await brokerService.RegisterServiceSubscriberAsync(serviceReference, messageType.FullName);
        }
        /// <inheritdoc />
        public async Task PublishMessageAsync <T>(T message) where T : class
        {
            var brokerService = await _brokerServiceLocator.GetBrokerServiceForMessageAsync(message);

            await brokerService.PublishMessageAsync(message.CreateMessageWrapper());
        }