public static void RegisterPartitionsForThisEndpoint(this EndpointConfiguration endpointConfiguration, string localPartitionKey, string[] allPartitionKeys)
    {
        endpointConfiguration.MakeInstanceUniquelyAddressable(localPartitionKey);

        var settings = endpointConfiguration.GetSettings();

        var endpointName         = settings.EndpointName();
        var distributionStrategy = new PartitionAwareDistributionStrategy(endpointName, _ => localPartitionKey, DistributionStrategyScope.Send);

        var distributionPolicy = settings.GetOrCreate <DistributionPolicy>();

        distributionPolicy.SetDistributionStrategy(distributionStrategy);

        var destinationEndpointInstances = allPartitionKeys.Select(key => new EndpointInstance(endpointName, key)).ToList();

        var endpointInstances = settings.GetOrCreate <EndpointInstances>();

        endpointInstances.AddOrReplaceInstances(endpointName, destinationEndpointInstances);

        endpointConfiguration.EnableFeature <HardcodeReplyToAddressToLogicalAddressFeature>();

        var augmentedEndpointName = $"{endpointName}-{localPartitionKey}";

        endpointConfiguration.Pipeline.Register(new HackEndpointNameBehavior.Registration(augmentedEndpointName));
        endpointConfiguration.Pipeline.Register(new HackHostInfoHeadersBehavior.Registration(augmentedEndpointName));
    }
    public static PartitionAwareSenderSideDistributionConfiguration RegisterPartitionedDestinationEndpoint <T>(this RoutingSettings <T> routingSettings, string destinationEndpoint, string[] partitions) where T : TransportDefinition
    {
        var settings = routingSettings.GetSettings();

        var distributionConfiguration = new PartitionAwareSenderSideDistributionConfiguration(routingSettings, destinationEndpoint, partitions);

        var sendDistributionStrategy = new PartitionAwareDistributionStrategy(destinationEndpoint, distributionConfiguration.MapMessageToPartitionKey, DistributionStrategyScope.Send);
        var distributionPolicy       = settings.GetOrCreate <DistributionPolicy>();

        distributionPolicy.SetDistributionStrategy(sendDistributionStrategy);

        var destinationEndpointInstances = partitions.Select(key => new EndpointInstance(destinationEndpoint, key)).ToList();

        var endpointInstances = settings.GetOrCreate <EndpointInstances>();

        endpointInstances.AddOrReplaceInstances(destinationEndpoint, destinationEndpointInstances);

        return(distributionConfiguration);
    }
    public static void RegisterPartitionsForThisEndpoint(this EndpointConfiguration endpointConfiguration, string localPartitionKey, string[] allPartitionKeys)
    {
        endpointConfiguration.MakeInstanceUniquelyAddressable(localPartitionKey);

        var settings = endpointConfiguration.GetSettings();

        var endpointName         = settings.EndpointName();
        var distributionStrategy = new PartitionAwareDistributionStrategy(endpointName, _ => localPartitionKey, DistributionStrategyScope.Send);

        var distributionPolicy = settings.GetOrCreate <DistributionPolicy>();

        distributionPolicy.SetDistributionStrategy(distributionStrategy);

        var destinationEndpointInstances = allPartitionKeys.Select(key => new EndpointInstance(endpointName, key)).ToList();

        var endpointInstances = settings.GetOrCreate <EndpointInstances>();

        endpointInstances.AddOrReplaceInstances(endpointName, destinationEndpointInstances);

        var pipeline = endpointConfiguration.Pipeline;
        var addressToLogicalAddress = new HardcodeReplyToAddressToLogicalAddress(settings.InstanceSpecificQueue());

        pipeline.Register(addressToLogicalAddress, "Hardcodes the ReplyToAddress to the instance specific address of this endpoint.");
    }