Class ApiGateway
java.lang.Object
services.moleculer.service.MoleculerComponent
services.moleculer.service.Service
services.moleculer.web.ApiGateway
- All Implemented Interfaces:
services.moleculer.service.MoleculerLifecycle, RequestProcessor
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected CallProcessorCustom message post-processor.protected CallProcessorCustom message pre-processor.protected intMaximum number of cached routes.Checked services with @HttpAlias annotations.protected booleanPrint more debug messages.protected final LinkedList<Mapping> Dynamic mappings.protected ExecutorServiceCustom Action Executor (null = use the shared ExecutorService of the MessageBroker).protected Set<HttpMiddleware> Global middlewares.protected HttpMiddlewareLast middleware (custom error pages, HTTP-redirector, etc.)protected RouteLast route (for the last middleware)protected final ReentrantReadWriteLock.ReadLockprotected Route[]protected LinkedHashMap<String, Mapping> Static mappings.protected AbstractTemplateEngineHTML template engine.protected WebSocketFilterWebSocket filter (access control)services.moleculer.eventbus.ListenerSend WebSocket via broadcasted Moleculer Event.protected WebSocketRegistryWebSocket registry (Netty or J2EE)protected final ReentrantReadWriteLock.WriteLockFields inherited from class services.moleculer.service.MoleculerComponent
broker, logger, name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddRoute()addRoute(String path, String serviceList, HttpMiddleware... middlewares) Define a route for a list of Service (eg. in the "service" the service's "action" action will available on "http://host:port/path/service/action").Adds a route to the list of routes.protected voidintReturns the next RequestProcessor in the invocation chain.Route[]booleanisDebug()protected voidlogAlias(StringBuilder msg, Route route, Alias alias) protected voidvoidservice(WebRequest req, WebResponse rsp) Handles request of the HTTP client.voidsetAfterCall(CallProcessor afterCall) voidsetBeforeCall(CallProcessor beforeCall) voidsetCachedRoutes(int cacheSize) voidsetDebug(boolean debug) voidsetExecutor(ExecutorService executor) voidsetLastMiddleware(HttpMiddleware lastMiddleware) voidvoidsetTemplateEngine(AbstractTemplateEngine templateEngine) voidsetWebSocketFilter(WebSocketFilter webSocketFilter) voidsetWebSocketRegistry(WebSocketRegistry webSocketRegistry) voidstarted(services.moleculer.ServiceBroker broker) Initializes gateway instance.voidstopped()Closes gateway.voiduse(Collection<HttpMiddleware> middlewares) voiduse(HttpMiddleware... middlewares) Methods inherited from class services.moleculer.service.MoleculerComponent
getBroker, getLogger, getName
-
Field Details
-
routes
-
lastRoute
Last route (for the last middleware) -
lastMiddleware
Last middleware (custom error pages, HTTP-redirector, etc.) -
debug
protected boolean debugPrint more debug messages. -
cachedRoutes
protected int cachedRoutesMaximum number of cached routes. -
staticMappings
Static mappings. -
dynamicMappings
Dynamic mappings. -
globalMiddlewares
Global middlewares. -
checkedNames
-
templateEngine
HTML template engine. -
webSocketRegistry
WebSocket registry (Netty or J2EE) -
webSocketFilter
WebSocket filter (access control) -
beforeCall
Custom message pre-processor. -
afterCall
Custom message post-processor. -
executor
Custom Action Executor (null = use the shared ExecutorService of the MessageBroker). -
readLock
-
writeLock
-
webSocketListener
public services.moleculer.eventbus.Listener webSocketListenerSend WebSocket via broadcasted Moleculer Event.
-
-
Constructor Details
-
ApiGateway
public ApiGateway() -
ApiGateway
-
-
Method Details
-
started
Initializes gateway instance.- Specified by:
startedin interfaceservices.moleculer.service.MoleculerLifecycle- Overrides:
startedin classservices.moleculer.service.MoleculerComponent- Parameters:
broker- parent ServiceBroker- Throws:
Exception
-
logRoute
-
logAlias
-
stopped
public void stopped()Closes gateway.- Specified by:
stoppedin interfaceservices.moleculer.service.MoleculerLifecycle- Overrides:
stoppedin classservices.moleculer.service.MoleculerComponent
-
clearMappings
protected void clearMappings() -
service
Handles request of the HTTP client.- Specified by:
servicein interfaceRequestProcessor- Parameters:
req- WebRequest object that contains the request the client made of the ApiGatewayrsp- WebResponse object that contains the response the ApiGateway returns to the client- Throws:
Exception- if an input or output error occurs while the ApiGateway is handling the HTTP request
-
use
-
use
-
addRoute
-
addRoute
Define a route for a list of Service (eg. in the "service" the service's "action" action will available on "http://host:port/path/service/action").- Parameters:
path- root path to services (can be null or empty)serviceList- list of services and/or actions (eg. "service1, service2.action, service3, service4.action")middlewares- optional middlewares (eg. CorsHeaders)- Returns:
- route the new route
-
addRoute
-
getRoutes
-
setRoutes
-
getCachedRoutes
public int getCachedRoutes() -
setCachedRoutes
public void setCachedRoutes(int cacheSize) -
getLastMiddleware
-
setLastMiddleware
-
isDebug
public boolean isDebug() -
setDebug
public void setDebug(boolean debug) -
getTemplateEngine
-
setTemplateEngine
-
getBeforeCall
-
setBeforeCall
-
getAfterCall
-
setAfterCall
-
getWebSocketRegistry
-
setWebSocketRegistry
-
getWebSocketFilter
-
setWebSocketFilter
-
getExecutor
-
setExecutor
-
getParent
Description copied from interface:RequestProcessorReturns the next RequestProcessor in the invocation chain.- Specified by:
getParentin interfaceRequestProcessor- Returns:
- parent processor
-