Skip to content

Move external lib deps to peer deps #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ Moleculer is a fast & powerful microservices framework for NodeJS (>= v6.x).
- load balanced requests (round-robin, random)
- every nodes are equal, no master/leader node
- auto discovery services
- parameter validation
- parameter validation with [fastest-validator](https://github.com/icebob/fastest-validator)
- distributed timeout handling with fallback response
- health monitoring, metrics & statistics
- supports versioned services (run different versions of the service)
- official [API gateway module](https://github.com/ice-services/moleculer-web)

# Installation
```
Expand Down Expand Up @@ -102,13 +103,13 @@ Use the Moleculer CLI tool to create a new Moleculer based microservices project
````
5. Open the [http://localhost:3000/math.add?a=5&b=3](http://localhost:3000/math.add?a=5&b=3) link in your browser. It will call the `add` action of `math` service with two params via [API gateway](https://github.com/ice-services/moleculer-web) and returns with the result.

:tada:**Congratulation, you created your first Moleculer based microservices project. Read our [documentation](https://moleculer.services/docs) to learn more about Moleculer.**
:tada:**Congratulations! You created your first Moleculer based microservices project. Read our [documentation](https://moleculer.services/docs) to learn more about Moleculer.**

# Official modules
We have some official modules for Moleculer. [See the list!](https://moleculer.services/docs/modules.html)

# Documentation
You can find [the documentation here](https://moleculer.services/docs).
You can find here [the documentation](https://moleculer.services/docs).

# Changelog
See [CHANGELOG.md](CHANGELOG.md).
Expand Down
20 changes: 14 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,37 +33,45 @@
"license": "MIT",
"devDependencies": {
"amqplib": "0.5.1",
"avsc": "5.0.3",
"benchmarkify": "2.1.0",
"coveralls": "2.13.1",
"eslint": "3.19.0",
"eslint-plugin-promise": "3.5.0",
"fakerator": "0.3.0",
"ioredis": "3.1.1",
"jest": "20.0.4",
"jest-cli": "20.0.4",
"lolex": "1.6.0",
"mqtt": "2.8.1",
"msgpack5": "3.4.1",
"nats": "0.7.20",
"nodemon": "1.11.0",
"npm-check": "5.4.4",
"protobufjs": "6.7.3",
"v8-natives": "1.0.0"
},
"peerDependencies": {
"avsc": "^5.0.1",
"ioredis": "^3.1.1",
"mqtt": "^2.8.1",
"msgpack5": "^3.4.1",
"nats": "^0.7.20",
"protobufjs": "^6.7.3"
},
"dependencies": {
"avsc": "5.0.3",
"bluebird": "3.5.0",
"chalk": "1.1.3",
"clui": "0.3.1",
"es6-error": "4.0.2",
"eventemitter2": "4.1.0",
"fastest-validator": "0.4.2",
"glob": "7.1.2",
"ioredis": "3.1.1",
"lodash": "4.17.4",
"mqtt": "2.8.1",
"ms": "2.0.0",
"msgpack5": "3.4.1",
"nanomatch": "1.2.0",
"nats": "0.7.20",
"node-object-hash": "1.2.0",
"pretty-bytes": "4.0.2",
"protobufjs": "6.7.3",
"table": "4.0.1",
"vorpal": "1.12.0"
},
Expand Down
204 changes: 105 additions & 99 deletions src/serializers/avro.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,106 +6,110 @@

"use strict";

const avro = require("avsc");
const BaseSerializer = require("./base");
const P = require("../packets");

const schemas = {};

schemas[P.PACKET_EVENT] = avro.Type.forSchema({
name: P.PACKET_EVENT,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "event", type: "string" },
{ name: "data", type: "string" }
]
});

schemas[P.PACKET_REQUEST] = avro.Type.forSchema({
name: P.PACKET_REQUEST,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "id", type: "string" },
{ name: "action", type: "string" },
{ name: "params", type: "string" },
{ name: "meta", type: "string" },
{ name: "timeout", type: "int" },
{ name: "level", type: "int" },
{ name: "metrics", type: "boolean" },
{ name: "parentID", type: [ "null", "string"], default: null }
]
});

schemas[P.PACKET_RESPONSE] = avro.Type.forSchema({
name: P.PACKET_RESPONSE,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "id", type: "string" },
{ name: "success", type: "boolean" },
{ name: "data", type: [ "null", "string"] },
{ name: "error", type: [ "null", {
type: "record",
fields: [
{ name: "name", type: "string" },
{ name: "message", type: "string" },
{ name: "code", type: "int" },
{ name: "type", type: "string" },
{ name: "stack", type: "string" },
{ name: "data", type: "string" },
{ name: "nodeID", type: "string" }
]
} ], default: null }
]
});

schemas[P.PACKET_DISCOVER] = avro.Type.forSchema({
name: P.PACKET_DISCOVER,
type: "record",
fields: [
{ name: "sender", type: "string" }
]
});

schemas[P.PACKET_INFO] = avro.Type.forSchema({
name: P.PACKET_INFO,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "actions", type: "string" },
{ name: "uptime", type: "double" },
{ name: "ipList", type: {
type: "array",
items: "string"
}},
{ name: "versions", type: {
type: "record",
fields: [
{ name: "node", type: "string" },
{ name: "moleculer", type: "string" }
]
}}
]
});

schemas[P.PACKET_DISCONNECT] = avro.Type.forSchema({
name: P.PACKET_DISCONNECT,
type: "record",
fields: [
{ name: "sender", type: "string" }
]
});

schemas[P.PACKET_HEARTBEAT] = avro.Type.forSchema({
name: P.PACKET_HEARTBEAT,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "uptime", type: "double" }
]
});
function createSchemas() {
const avro = require("avsc");
const schemas = {};

schemas[P.PACKET_EVENT] = avro.Type.forSchema({
name: P.PACKET_EVENT,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "event", type: "string" },
{ name: "data", type: "string" }
]
});

schemas[P.PACKET_REQUEST] = avro.Type.forSchema({
name: P.PACKET_REQUEST,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "id", type: "string" },
{ name: "action", type: "string" },
{ name: "params", type: "string" },
{ name: "meta", type: "string" },
{ name: "timeout", type: "int" },
{ name: "level", type: "int" },
{ name: "metrics", type: "boolean" },
{ name: "parentID", type: [ "null", "string"], default: null }
]
});

schemas[P.PACKET_RESPONSE] = avro.Type.forSchema({
name: P.PACKET_RESPONSE,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "id", type: "string" },
{ name: "success", type: "boolean" },
{ name: "data", type: [ "null", "string"] },
{ name: "error", type: [ "null", {
type: "record",
fields: [
{ name: "name", type: "string" },
{ name: "message", type: "string" },
{ name: "code", type: "int" },
{ name: "type", type: "string" },
{ name: "stack", type: "string" },
{ name: "data", type: "string" },
{ name: "nodeID", type: "string" }
]
} ], default: null }
]
});

schemas[P.PACKET_DISCOVER] = avro.Type.forSchema({
name: P.PACKET_DISCOVER,
type: "record",
fields: [
{ name: "sender", type: "string" }
]
});

schemas[P.PACKET_INFO] = avro.Type.forSchema({
name: P.PACKET_INFO,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "actions", type: "string" },
{ name: "uptime", type: "double" },
{ name: "ipList", type: {
type: "array",
items: "string"
}},
{ name: "versions", type: {
type: "record",
fields: [
{ name: "node", type: "string" },
{ name: "moleculer", type: "string" }
]
}}
]
});

schemas[P.PACKET_DISCONNECT] = avro.Type.forSchema({
name: P.PACKET_DISCONNECT,
type: "record",
fields: [
{ name: "sender", type: "string" }
]
});

schemas[P.PACKET_HEARTBEAT] = avro.Type.forSchema({
name: P.PACKET_HEARTBEAT,
type: "record",
fields: [
{ name: "sender", type: "string" },
{ name: "uptime", type: "double" }
]
});

return schemas;
}

/**
* Avro serializer for Moleculer
Expand All @@ -123,6 +127,8 @@ class AvroSerializer extends BaseSerializer {
*/
constructor() {
super();

this.schemas = createSchemas();
}

/**
Expand All @@ -136,7 +142,7 @@ class AvroSerializer extends BaseSerializer {
*/
serialize(obj, type) {
//const t = schemas[type].toBuffer(obj);
const t = schemas[type].toBuffer(obj).toString("binary");
const t = this.schemas[type].toBuffer(obj).toString("binary");
return t;
}

Expand All @@ -151,7 +157,7 @@ class AvroSerializer extends BaseSerializer {
*/
deserialize(str, type) {
//const res = schemas[type].fromBuffer(str);
const res = schemas[type].fromBuffer(Buffer.from(str, "binary"));
const res = this.schemas[type].fromBuffer(Buffer.from(str, "binary"));
return res;
}
}
Expand Down