Class CrankerRouterBuilder
- java.lang.Object
-
- com.hsbc.cranker.mucranker.CrankerRouterBuilder
-
public class CrankerRouterBuilder extends Object
UsecrankerRouter()to create a builder where you can configure your cranker router options. Thestart()method returns aCrankerRouterobject which can be used to create handlers that you add to your own Mu Server instance.
-
-
Constructor Summary
Constructors Constructor Description CrankerRouterBuilder()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static CrankerRouterBuildercrankerRouter()CrankerRouterBuilderproxyHostHeader(boolean sendHostToTarget)Specifies whether or not to send the originalHostheader to the target server.CrankerRouterstart()CrankerRouterBuilderwithConnectorMaxWaitInMillis(long maxWaitInMillis)When a request is made for a route that has no connectors connected currently, the router will wait for a period to see if a connector will connect that can service the request.CrankerRouterBuilderwithDiscardClientForwardedHeaders(boolean discardClientForwardedHeaders)If true, then anyForwardedorX-Forwarded-*headers that are sent from the client to this reverse proxy will be dropped (defaults to false).CrankerRouterBuilderwithIdleTimeout(long duration, TimeUnit unit)Sets the idle timeout.CrankerRouterBuilderwithPingSentAfterNoWritesFor(int duration, TimeUnit unit)Sets the amount of time to wait before sending a ping message if no messages having been sent.CrankerRouterBuilderwithProxyListeners(List<ProxyListener> proxyListeners)Registers proxy listeners to be called before, during and after requests are processed.CrankerRouterBuilderwithRegistrationIpValidator(IPValidator ipValidator)Sets the IP validator for service registration requests.CrankerRouterBuilderwithRouteResolver(RouteResolver routeResolver)Customized route resolver.CrankerRouterBuilderwithRoutesKeepTime(long duration, TimeUnit unit)Sets the routes keep time if no more connector registered.CrankerRouterBuilderwithSendLegacyForwardedHeaders(boolean sendLegacyForwardedHeaders)Mucranker always sendsForwardedheaders, however by default does not send the non-standardX-Forwarded-*headers.CrankerRouterBuilderwithSupportedCrankerProtocols(List<String> protocols)Set cranker protocols.CrankerRouterBuilderwithViaName(String viaName)The name to add as theViaheader, which defaults tomuc.
-
-
-
Method Detail
-
crankerRouter
public static CrankerRouterBuilder crankerRouter()
- Returns:
- A new builder
-
withDiscardClientForwardedHeaders
public CrankerRouterBuilder withDiscardClientForwardedHeaders(boolean discardClientForwardedHeaders)
If true, then anyForwardedorX-Forwarded-*headers that are sent from the client to this reverse proxy will be dropped (defaults to false). Set this totrueif you do not trust the client.- Parameters:
discardClientForwardedHeaders-trueto ignore Forwarded headers from the client; otherwisefalse- Returns:
- This builder
-
withSendLegacyForwardedHeaders
public CrankerRouterBuilder withSendLegacyForwardedHeaders(boolean sendLegacyForwardedHeaders)
Mucranker always sendsForwardedheaders, however by default does not send the non-standardX-Forwarded-*headers. Set this totrueto enable these legacy headers for older clients that rely on them.- Parameters:
sendLegacyForwardedHeaders-trueto forward headers such asX-Forwarded-Host; otherwisefalse- Returns:
- This builder
-
withViaName
public CrankerRouterBuilder withViaName(String viaName)
The name to add as theViaheader, which defaults tomuc.- Parameters:
viaName- The name to add to theViaheader.- Returns:
- This builder
-
withIdleTimeout
public CrankerRouterBuilder withIdleTimeout(long duration, TimeUnit unit)
Sets the idle timeout. If no messages are received within this time then the connection is closed.The default is 5 minutes.
- Parameters:
duration- The allowed timeout duration, or 0 to disable timeouts.unit- The unit of the duration.- Returns:
- This builder
-
withRoutesKeepTime
public CrankerRouterBuilder withRoutesKeepTime(long duration, TimeUnit unit)
Sets the routes keep time if no more connector registered. Within the time, client will receive 503 (no cranker available). After that, the route info will be cleaned up, and client will receive 404 if requesting against this route.
The default keep time is 2 hours.
- Parameters:
duration- The duration for keeping the route info, or 0 to disable cleaning.unit- The unit of the duration.- Returns:
- This builder
-
withPingSentAfterNoWritesFor
public CrankerRouterBuilder withPingSentAfterNoWritesFor(int duration, TimeUnit unit)
Sets the amount of time to wait before sending a ping message if no messages having been sent.The default is 10 seconds.
- Parameters:
duration- The allowed timeout duration, or 0 to disable timeouts.unit- The unit of the duration.- Returns:
- This builder
-
withConnectorMaxWaitInMillis
public CrankerRouterBuilder withConnectorMaxWaitInMillis(long maxWaitInMillis)
When a request is made for a route that has no connectors connected currently, the router will wait for a period to see if a connector will connect that can service the request.
This is important because if there are a burst of requests for a route, there might be just a few milliseconds gap where there is no connector available, so there is no point sending an error back to the client if it would be find after a short period.
This setting controls how long it waits before returning a
503 Service Unavailableto the client.- Parameters:
maxWaitInMillis- The maximum wait time in millis for connector availability- Returns:
- This builder
-
proxyHostHeader
public CrankerRouterBuilder proxyHostHeader(boolean sendHostToTarget)
Specifies whether or not to send the original
Hostheader to the target server.Reverse proxies are generally supposed to forward the original
Hostheader to target servers, however there are cases (particularly where you are proxying to HTTPS servers) that the Host needs to match the Host of the SSL certificate (in which case you may see SNI-related errors).- Parameters:
sendHostToTarget- Iftrue(which is the default) theHostrequest header will be sent to the target; iffalsethen the host header will be based on the target's URL.- Returns:
- This builder
-
withRegistrationIpValidator
public CrankerRouterBuilder withRegistrationIpValidator(IPValidator ipValidator)
Sets the IP validator for service registration requests. Defaults toIPValidator.AllowAll- Parameters:
ipValidator- The validator to use.- Returns:
- This builder
-
withProxyListeners
public CrankerRouterBuilder withProxyListeners(List<ProxyListener> proxyListeners)
Registers proxy listeners to be called before, during and after requests are processed.- Parameters:
proxyListeners- The listeners to add.- Returns:
- This builder
-
withRouteResolver
public CrankerRouterBuilder withRouteResolver(RouteResolver routeResolver)
Customized route resolver. If it's not specified, will use the default implementation inRouteResolver.resolve(Set, String)- Parameters:
routeResolver- The customized routeResolver.- Returns:
- This builder
-
withSupportedCrankerProtocols
public CrankerRouterBuilder withSupportedCrankerProtocols(List<String> protocols)
Set cranker protocols. Default supporting both ["cranker_1.0", "cranker_3.0"].- Parameters:
protocols- the protocols to support- Returns:
- this builder
-
start
public CrankerRouter start()
- Returns:
- A newly created CrankerRouter object
-
-