use of services.moleculer.internal.NodeService in project moleculer-java by moleculer-java.
the class ServiceBroker method start.
// --- START BROKER INSTANCE ---
/**
* Start broker. If has a Transporter, transporter.connect() will be called.
*/
public void start() throws Exception {
// Check state
if (serviceRegistry != null) {
throw new IllegalStateException("Moleculer Service Broker has already been started!");
}
try {
// Start internal components, services, middlewares...
logger.info("Starting Moleculer Service Broker (version " + SOFTWARE_VERSION + ")...");
// Set internal components
uidGenerator = start(config.getUidGenerator());
strategyFactory = start(config.getStrategyFactory());
contextFactory = start(config.getContextFactory());
circuitBreaker = start(config.getCircuitBreaker());
eventbus = start(config.getEventbus());
serviceRegistry = start(config.getServiceRegistry());
transporter = start(config.getTransporter());
// Register enqued middlewares
Cacher cacher = config.getCacher();
if (cacher != null) {
logger.info(nameOf(cacher, true) + " started.");
middlewares.add(cacher);
}
serviceRegistry.use(middlewares);
// Install internal services
if (config.isInternalServices()) {
services.put("$node", new NodeService());
}
// Register and start enqued services and listeners
for (Map.Entry<String, Service> entry : services.entrySet()) {
Service service = entry.getValue();
String serviceName = entry.getKey();
eventbus.addListeners(serviceName, service);
serviceRegistry.addActions(serviceName, service);
}
// Start transporter's connection loop
if (transporter != null) {
transporter.connect();
}
// Ok, services, transporter and gateway started
logger.info("Node \"" + config.getNodeID() + "\" started successfully.");
} catch (Throwable cause) {
logger.error("Moleculer Service Broker could not be started!", cause);
stop();
} finally {
middlewares.clear();
services.clear();
}
}
Aggregations