Class CrankerRouterBuilder


  • public class CrankerRouterBuilder
    extends Object
    Use crankerRouter() to create a builder where you can configure your cranker router options. The start() method returns a CrankerRouter object which can be used to create handlers that you add to your own Mu Server instance.
    • Constructor Detail

      • CrankerRouterBuilder

        public CrankerRouterBuilder()
    • Method Detail

      • withDiscardClientForwardedHeaders

        public CrankerRouterBuilder withDiscardClientForwardedHeaders​(boolean discardClientForwardedHeaders)
        If true, then any Forwarded or X-Forwarded-* headers that are sent from the client to this reverse proxy will be dropped (defaults to false). Set this to true if you do not trust the client.
        Parameters:
        discardClientForwardedHeaders - true to ignore Forwarded headers from the client; otherwise false
        Returns:
        This builder
      • withSendLegacyForwardedHeaders

        public CrankerRouterBuilder withSendLegacyForwardedHeaders​(boolean sendLegacyForwardedHeaders)
        Mucranker always sends Forwarded headers, however by default does not send the non-standard X-Forwarded-* headers. Set this to true to enable these legacy headers for older clients that rely on them.
        Parameters:
        sendLegacyForwardedHeaders - true to forward headers such as X-Forwarded-Host; otherwise false
        Returns:
        This builder
      • withViaName

        public CrankerRouterBuilder withViaName​(String viaName)
        The name to add as the Via header, which defaults to muc.
        Parameters:
        viaName - The name to add to the Via header.
        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 Unavailable to 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 Host header to the target server.

        Reverse proxies are generally supposed to forward the original Host header 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 - If true (which is the default) the Host request header will be sent to the target; if false then 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 to IPValidator.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
      • 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