/**
 * Copyright 2008-2009. Chongqing Communications Industry Services Co.,Ltd Information Technology Branch. All rights reserved. <a>http://www.crunii.com</a>
 */
package com.crunii.micro.gateway.limit.resolver;

import org.springframework.cloud.gateway.filter.ratelimit.KeyResolver;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;

import reactor.core.publisher.Mono;

/**
 * @author 田平 create 2018年9月11日下午2:45:19
 */
@Component(value = "remoteAddrKeyResolver")
public class RemoteAddrKeyResolver implements KeyResolver {

	@Override
	public Mono<String> resolve(ServerWebExchange exchange) {
		// getRequest().getRemoteAddress().getAddress()
		// 电信DCOS k8s环境下获取可能会发生非常缓慢的情况，取消这种获取方式,千万不要使用
		return Mono.just(exchange.getRequest().getRemoteAddress().getAddress().getHostAddress());
	}

}
