/// <summary> /// Build a <see cref="Destination" /> from a Service Fabric <see cref="ReplicaWrapper" />. /// </summary> /// <remarks> /// The address JSON of the replica is expected to have exactly one endpoint, and that one will be used. /// </remarks> internal static KeyValuePair <string, Destination> BuildDestinationFromReplica(ReplicaWrapper replica, string healthListenerName = null) { ServiceEndpointCollection.TryParseEndpointsString(replica.ReplicaAddress, out var endpoints); endpoints.TryGetFirstEndpointAddress(out var address); string healthAddressUri = null; if (healthListenerName != null) { endpoints.TryGetEndpointAddress(healthListenerName, out healthAddressUri); } return(KeyValuePair.Create( replica.Id.ToString(), new Destination { Address = address, Health = healthAddressUri, Metadata = null, })); }
/// <summary> /// Gets the endpoint from the array of endpoints using the listener name. /// </summary> /// <param name="rse">ResolvedServiceEndpoint instance.</param> /// <param name="name">Listener name.</param> /// <returns>String containing the replica address.</returns> /// <exception cref="ArgumentException">ResolvedServiceEndpoint address list coudln't be parsed.</exception> /// <exception cref="InvalidProgramException">ResolvedServiceEndpoint address list coudln't be parsed.</exception> public static string GetEndpoint(this ResolvedServiceEndpoint rse, string name) { ServiceEndpointCollection sec = null; if (ServiceEndpointCollection.TryParseEndpointsString(rse.Address, out sec)) { string replicaAddress; if (sec.TryGetEndpointAddress(name, out replicaAddress)) { return(replicaAddress); } else { throw new ArgumentException(nameof(name)); } } else { throw new InvalidProgramException("ResolvedServiceEndpoint had invalid address"); } }