spring-cloud-gateway icon indicating copy to clipboard operation
spring-cloud-gateway copied to clipboard

Versioning of Custom Filters

Open mn-ar opened this issue 3 years ago • 1 comments

Please share if there an inbuilt way to run multiple versions of a custom filter allowing a gradual upgrade path.

For Example: If a filter, say, CustomFilter is being used by several routes requires a change that could have a large impact, we would prefer a gradual upgrade process with only selective routes going first. Of-course, we can make multiple copies of the filter, like CustomFilterV1, CustomFilterV2 etc. but that leads to a maintenance overhead.

Is there anything inbuilt to make it easier.

mn-ar avatar Aug 19 '22 05:08 mn-ar

Please share if there an inbuilt way to run multiple versions of a custom filter allowing a gradual upgrade path

not yet

Of-course, we can make multiple copies of the filter, like CustomFilterV1, CustomFilterV2 etc. but that leads to a maintenance overhead. Is there anything inbuilt to make it easier. yes. You may do like this.

example:

public class VersioningGatewayFilterFactory extends AbstractGatewayFilterFactory<VersioningGatewayFilterFactory.Config> {
	
	public VersioningGatewayFilterFactory() {
		super(VersioningGatewayFilterFactory.Config.class);
	}
	
	@Override
	public GatewayFilter apply(Config config) {
		return (exchange, chain) -> {
			String version = config.version;
			// your spec code
			return chain.filter(exchange);
		};
	}
	
	static class Config {
		protected String version;
                public String getVersion() {
			return version;
		}
		
		public void setVersion(String version) {
			this.version = version;
		}
	}
}

and the config like:

routes:
  - id: version1
    uri: 
    predicates:
    - Path=/**
    filters:
    - name: Versioning
      args:
        version: 1
  - id: version2
    uri: 
    predicates:
    - Path=/**
    filters:
    - name: Versioning
      args:
        version: 2

xinkeng0 avatar Sep 02 '22 06:09 xinkeng0

There is nothing to do this.

spencergibb avatar Jan 06 '23 23:01 spencergibb