private async Task BroadcastCommandMessageToPartition(BrokeredMessage bm, Partition partition, int[] relativeIds) { TopicClient forwardClient = null; var connectionString = ServiceBusConnection.FromIssuer(partition.Namespace, partition.Owner, partition.OwnerSecret); var controlMessage = bm.GetBody <ControlMessage>(); var commandMessage = new CommandMessage { Command = controlMessage.Command, Parameters = controlMessage.Parameters }; foreach (var topicName in relativeIds.Select(id => string.Format(PARTITION_COMMAND_TOPIC, id))) { try { forwardClient = TopicClient.CreateFromConnectionString(connectionString, topicName); using (var forwardMessage = new BrokeredMessage(commandMessage) { ContentType = CommandMessage.CONTENT_TYPE }) { forwardMessage.Properties[MessageProperty.BROADCAST] = 0; forwardMessage.ReplyTo = bm.ReplyTo; await _messagingPolicy.ExecuteAsync(() => forwardClient.SendAsync(forwardMessage)); } } finally { if (forwardClient != null) { _catchAllPolicy.Execute(() => { forwardClient.Close(); }); } } } }
private void CloseClients() { if (_subscriptionClient != null) { _catchAllPolicy.Execute(() => { _subscriptionClient.Close(); }); } if (_topicClient != null) { _catchAllPolicy.Execute(() => { _topicClient.Close(); }); } _subscriptionClient = null; _topicClient = null; }