public static async Task PublishMessageToBrokerServiceAsync(this 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( 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 PublisherActorExtensions.GetBrokerServiceForMessageAsync(message, brokerServiceName); var wrapper = MessageWrapper.CreateMessageWrapper(message); await brokerService.PublishMessageAsync(wrapper); }
/// <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(StatefulServiceBase 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); }
/// <summary> /// Publish a message. /// </summary> /// <param name="service"></param> /// <param name="message"></param> /// <param name="applicationName">The name of the SF application that hosts the <see cref="BrokerActor"/>. If not provided, ServiceInitializationParameters.CodePackageActivationContext.ApplicationName will be used.</param> /// <returns></returns> public static async Task PublishMessageAsync(this StatefulServiceBase 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 = MessageWrapper.CreateMessageWrapper(message); await brokerActor.PublishMessageAsync(wrapper); }