How to use the moleculer.ServiceBroker function in moleculer

To help you get started, we’ve selected a few moleculer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github moleculerjs / moleculer-db / packages / moleculer-db-adapter-sequelize / examples / simple / index.js View on Github external
"use strict";

const { ServiceBroker } = require("moleculer");
const StoreService = require("../../../moleculer-db/index");
const ModuleChecker = require("../../../moleculer-db/test/checker");
const SequelizeAdapter = require("../../index");
const Sequelize = require("sequelize");
const Op = Sequelize.Op;

process.on("warning", e => console.warn(e.stack));

// Create broker
const broker = new ServiceBroker({
	logger: console,
	logLevel: "debug"
});
let adapter;

// Load my service
broker.createService(StoreService, {
	name: "posts",
	adapter: new SequelizeAdapter("sqlite://:memory:"),
	model: {
		name: "post",
		define: {
			title: Sequelize.STRING,
			content: Sequelize.TEXT,
			votes: Sequelize.INTEGER,
			author: Sequelize.INTEGER,
github moleculerjs / moleculer-metrics / packages / moleculer-jaeger / examples / api / index.js View on Github external
"use strict";

const { ServiceBroker } 	= require("moleculer");
const { MoleculerError } 	= require("moleculer").Errors;
const JaegerService 		= require("../../index");
const ApiGateway			= require("moleculer-web");

const THROW_ERR = true;

// Create broker
const broker = new ServiceBroker({
	logger: console,
	logLevel: "debug",
	metrics: true,
	sampleCount: 1
});

broker.createService(ApiGateway);

// Load Jaeger service
broker.createService({
	mixins: [JaegerService],
	settings: {
		host: "192.168.0.181"
	}
});
github moleculerjs / moleculer-apollo-server / examples / simple / index.js View on Github external
"use strict";

const { ServiceBroker } = require("moleculer");
const { MoleculerClientError } = require("moleculer").Errors;

const ApiGateway = require("moleculer-web");
const { ApolloService } = require("../../index");

const broker = new ServiceBroker({ logLevel: "info", hotReload: true });

broker.createService({
	name: "api",

	mixins: [
		// Gateway
		ApiGateway,

		// GraphQL Apollo Server
		ApolloService({
			// API Gateway route options
			routeOptions: {
				path: "/graphql",
				cors: true,
				mappingPolicy: "restrict",
			},
github moleculerjs / moleculer-db / packages / moleculer-db-adapter-mongoose / examples / populates / index.js View on Github external
"use strict";

const { ServiceBroker } = require("moleculer");
const StoreService = require("../../../moleculer-db/index");
const MongooseAdapter = require("../../index");
const ModuleChecker = require("../../../moleculer-db/test/checker");
const Post = require("../models/posts");
const User = require("../models/users");

// Create broker
const broker = new ServiceBroker({
	logger: console,
	logLevel: "debug"
});

let posts = [];
let users = [];

// Load my service
broker.createService(StoreService, {
	name: "posts",
	adapter: new MongooseAdapter("mongodb://localhost/moleculer-db-demo"),
	//dependencies: ["users"],
	model: Post,
	settings: {
		fields: ["_id", "title", "content", "votes", "author"],
github moleculerjs / moleculer-addons / packages / moleculer-db-adapter-sequelize / examples / integration / index.js View on Github external
"use strict";

const { ServiceBroker } = require("moleculer");
const StoreService = require("../../../moleculer-db/index");
const SequelizeAdapter = require("../../index");
const ModuleChecker = require("../../../moleculer-db/test/checker");
const Promise = require("bluebird");
const Sequelize = require("sequelize");

// Create broker
const broker = new ServiceBroker({
	logger: console,
	logLevel: "debug"
});

/*
	Test environments:

		MySQL:
			Server:
				docker run --name mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=mysql -d mysql 

			CLI: 			
				docker run -it --link mysql:mysql --rm mysql sh -c 'exec mysql -h"$MYSQL_PORT_3306_TCP_ADDR" -P"$MYSQL_PORT_3306_TCP_PORT" -uroot -p"$MYSQL_ENV_MYSQL_ROOT_PASSWORD"'

				CREATE DATABASE moleculer_test;
				SHOW DATABASES;
github moleculerjs / moleculer-web / test / integration / index.spec.js View on Github external
it("should return with JSON error object", () => {
		const broker = new ServiceBroker({ logger: false });
		const service = broker.createService(ApiGateway, {
			settings: {
				routes: [{
					path: "/api"
				}]
			}
		});
		const server = service.server;

		return broker.start()
			.then(() => request(server)
				.get("/api/test/hello"))
			.then(res => {
				expect(res.statusCode).toBe(404);
				expect(res.headers["content-type"]).toBe("application/json; charset=utf-8");
				expect(res.body).toEqual({
github MerlinLabs / moleculer-graphql / tests / serviceDiscovery.spec.js View on Github external
broker.start();

    onServiceDiscovery = jest.fn();

    gateway = new GraphQLGateway({
      broker,
      onServiceDiscovery,
    });

    authorBroker = new ServiceBroker({
      nodeID: 'author',
      namespace: 'serviceDiscovery',
      transporter: new Transporters.MQTT('mqtt://localhost:1883'),
    });

    bookBroker = new ServiceBroker({
      nodeID: 'book',
      namespace: 'serviceDiscovery',
      transporter: new Transporters.MQTT('mqtt://localhost:1883'),
    });

    chapterBroker = new ServiceBroker({
      nodeID: 'chapter',
      namespace: 'serviceDiscovery',
      transporter: new Transporters.MQTT('mqtt://localhost:1883'),
    });

    authorBroker.createService(authorSvc);
    bookBroker.createService(bookSvc);
    chapterBroker.createService(chapterSvc);
  });
github MerlinLabs / moleculer-graphql / tests / schemaGeneration.spec.js View on Github external
broker = new ServiceBroker({
        nodeID: 'gatewayMultiple',
        transporter: new Transporters.MQTT('mqtt://localhost:1883')
      });

      authorBroker = new ServiceBroker({
        nodeID: 'author',
        transporter: new Transporters.MQTT('mqtt://localhost:1883')
      });

      bookBroker = new ServiceBroker({
        nodeID: 'book',
        transporter: new Transporters.MQTT('mqtt://localhost:1883')
      });

      chapterBroker = new ServiceBroker({
        nodeID: 'chapter',
        transporter: new Transporters.MQTT('mqtt://localhost:1883')
      });

      broker.start();

      gateway = new GraphQLGateway({
        broker,
      });

      gateway.start().then(() => done());

      authorBroker.createService(authorSvc);
      bookBroker.createService(bookSvc);
      chapterBroker.createService(chapterSvc);
github pankod / moleculerjs-boilerplate / test / Utils / BrokerHelper.ts View on Github external
export const setupBroker = () => {
		const broker = new ServiceBroker({ logger: false });

		broker.createService(AttackService);
		broker.createService(PlanetService);

		return broker;
	};
}
github moleculerjs / moleculer-web / test / integration / index.spec.js View on Github external
function setup(settings, brokerSettings = {}) {
	const broker = new ServiceBroker(Object.assign({}, { nodeID: undefined, logger: false }, brokerSettings));
	broker.loadService("./test/services/test.service");

	const service = broker.createService(ApiGateway, {
		settings
	});
	const server = service.server;

	return [broker, service, server];
}