Skip to content

Add a possibility to change service name dynamically because of Consul tags #1188

@mantasaudickas

Description

@mantasaudickas

Hello,

At the moment service name is chosen based on first segment in the path.
I would like to be able to map one (or multiple) path segments to service name in Consul.

Few examples:
authorization => would mapped to authorization.service.web
authorization/api => would be mapped to authorization.service.api

Reason for this, that my routes are defined in Consul tags and I would like to use them as a key when selecting service name in Consul.
At the moment to achieve this I have to replace whole DownstreamRouteCreator class, while I would be keen to keep custom part as small as possible.

Would you mind if I make a PR for this?

So something like:

    public interface IServiceNameProvider
    {
        string GetServiceName(string upstreamUrlPath);
    }

    public class ServiceNameProvider: IServiceNameProvider
    {
        public string GetServiceName(string upstreamUrlPath)
        {
            if (upstreamUrlPath.IndexOf('/', 1) == -1)
            {
                return upstreamUrlPath
                    .Substring(1);
            }

            return upstreamUrlPath
                .Substring(1, upstreamUrlPath.IndexOf('/', 1))
                .TrimEnd('/');
        }
    }

and use this such provider in CustomDownstreamRouteCreator class.

with best regards

Metadata

Metadata

Labels

ConsulService discovery by ConsulDependency InjectionOcelot feature: Dependency InjectionService DiscoveryOcelot feature: Service DiscoveryacceptedBug or feature would be accepted as a PR or is being worked on

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions