Compare commits
12 Commits
Author | SHA1 | Date | |
---|---|---|---|
904a48d414 | |||
e2acb28756 | |||
92e4379bd2 | |||
e0ce732ee1 | |||
98be0f036c | |||
54fca17142 | |||
1a7634e8db | |||
8830b825ac | |||
123324bf43 | |||
4761ff31cf | |||
430c3ea13a | |||
6dd3782b0d |
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.30",
|
"version": "1.0.37",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@pushrocks/smartuniverse",
|
"name": "@pushrocks/smartuniverse",
|
||||||
"version": "1.0.30",
|
"version": "1.0.37",
|
||||||
"private": false,
|
"private": false,
|
||||||
"description": "messaging service for your micro services",
|
"description": "messaging service for your micro services",
|
||||||
"main": "dist/index.js",
|
"main": "dist/index.js",
|
||||||
|
38
readme.md
38
readme.md
@ -1,13 +1,16 @@
|
|||||||
# @pushrocks/smartuniverse
|
# @pushrocks/smartuniverse
|
||||||
|
|
||||||
messaging service for micro services
|
messaging service for micro services
|
||||||
|
|
||||||
## Availabililty and Links
|
## Availabililty and Links
|
||||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
|
||||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
- [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
* [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
- [gitlab.com (source)](https://gitlab.com/pushrocks/smartuniverse)
|
||||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
- [github.com (source mirror)](https://github.com/pushrocks/smartuniverse)
|
||||||
|
- [docs (typedoc)](https://pushrocks.gitlab.io/smartuniverse/)
|
||||||
|
|
||||||
## Status for master
|
## Status for master
|
||||||
|
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
[](https://gitlab.com/pushrocks/smartuniverse/commits/master)
|
||||||
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
[](https://www.npmjs.com/package/@pushrocks/smartuniverse)
|
||||||
@ -20,9 +23,34 @@ messaging service for micro services
|
|||||||
|
|
||||||
Use TypeScript for best in class instellisense.
|
Use TypeScript for best in class instellisense.
|
||||||
|
|
||||||
|
### What is smartuniverse all about?
|
||||||
|
|
||||||
|
Think WhatsApp, but for your microservices architecture. It allows your services to securely talk to each other in **private, shielded channels** without having to expose anything to the outside world. This allows the use of **reactive programming across your entire stack**.
|
||||||
|
|
||||||
|
### Server side
|
||||||
|
every universe has a server that manages messages.
|
||||||
|
Think Kafka, but without Kafka.
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import * as smartuniverse from '@pushrocks/smartuniverse';
|
||||||
|
|
||||||
|
const myUniverse = new smartuniverse.Universe({
|
||||||
|
messageExpiryInMilliseconds: 60000 // the standard time in milliseconds until a message expires
|
||||||
|
});
|
||||||
|
|
||||||
|
// create as many channels as you like
|
||||||
|
myUniverse.addChannel('awesomeChannel', 'awesomeChannelPass');
|
||||||
|
myUniverse.addChannel('awesomeChannel2', 'jhkjhfsdf87eerkjslkfja9');
|
||||||
|
|
||||||
|
myUniverse.start(8765); // start the server and provide the port on which to listen on
|
||||||
|
```
|
||||||
|
|
||||||
|
### Client side
|
||||||
|
All your microservices represents clients in the universe that may talk to each other using the universe server.
|
||||||
|
|
||||||
For further information read the linked docs at the top of this readme.
|
For further information read the linked docs at the top of this readme.
|
||||||
|
|
||||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
> | By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy.html)
|
||||||
|
|
||||||
[](https://maintainedby.lossless.com)
|
[](https://maintainedby.lossless.com)
|
||||||
|
@ -8,6 +8,11 @@ let testUniverse: smartuniverse.Universe;
|
|||||||
let testUniverseClient: smartuniverse.ClientUniverse;
|
let testUniverseClient: smartuniverse.ClientUniverse;
|
||||||
let testClientChannel: smartuniverse.ClientUniverseChannel;
|
let testClientChannel: smartuniverse.ClientUniverseChannel;
|
||||||
|
|
||||||
|
const testChannelData = {
|
||||||
|
channelName: 'awesomeTestChannel',
|
||||||
|
channelPass: 'awesomeChannelPAss'
|
||||||
|
}
|
||||||
|
|
||||||
tap.test('first test', async () => {
|
tap.test('first test', async () => {
|
||||||
testUniverse = new smartuniverse.Universe({
|
testUniverse = new smartuniverse.Universe({
|
||||||
messageExpiryInMilliseconds: 1000
|
messageExpiryInMilliseconds: 1000
|
||||||
@ -15,7 +20,7 @@ tap.test('first test', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('add a message to the SmartUniverse', async () => {
|
tap.test('add a message to the SmartUniverse', async () => {
|
||||||
await testUniverse.initServer(8765);
|
await testUniverse.start(8765);
|
||||||
});
|
});
|
||||||
|
|
||||||
// testing message handling
|
// testing message handling
|
||||||
@ -31,7 +36,7 @@ tap.test('should add a channel to the universe', async () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
tap.test('should get a observable correctly', async () => {
|
tap.test('should get a observable correctly', async () => {
|
||||||
testClientChannel = await testUniverseClient.getChannel('testChannel');
|
testClientChannel = await testUniverseClient.getChannel(testChannelData.channelName, testChannelData.channelPass);
|
||||||
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
|
expect(testClientChannel).to.be.instanceof(smartuniverse.ClientUniverseChannel);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1 +1,7 @@
|
|||||||
export interface IUniverseMessage {}
|
export interface IUniverseMessage {
|
||||||
|
messageText: string;
|
||||||
|
targetChannelName: string;
|
||||||
|
passphrase: string;
|
||||||
|
payload?: string | number | any;
|
||||||
|
payloadStringType?: 'Buffer' | 'string' | 'object';
|
||||||
|
}
|
||||||
|
@ -31,18 +31,16 @@ export class ClientUniverse {
|
|||||||
this.options = optionsArg;
|
this.options = optionsArg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async sendMessage(messageArg, payloadArg) {
|
public async sendMessage(messageArg: interfaces.IUniverseMessage) {
|
||||||
const requestBody = {
|
const requestBody: interfaces.IUniverseMessage = messageArg;
|
||||||
message: messageArg,
|
const requestBodyString = JSON.stringify(requestBody);
|
||||||
payload: payloadArg
|
|
||||||
};
|
|
||||||
// TODO: User websocket connection if available
|
// TODO: User websocket connection if available
|
||||||
await plugins.smartrequest.postJson(this.options.serverAddress, {
|
const response = await plugins.smartrequest.postJson(`${this.options.serverAddress}/sendmessage` , {
|
||||||
requestBody
|
requestBody: requestBodyString
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public async getChannel(channelName: string): Promise<ClientUniverseChannel> {
|
public async getChannel(channelName: string, passphrase): Promise<ClientUniverseChannel> {
|
||||||
await this.checkConnection();
|
await this.checkConnection();
|
||||||
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
const clientUniverseChannel = await ClientUniverseChannel.createClientUniverseChannel(
|
||||||
this,
|
this,
|
||||||
|
@ -67,7 +67,7 @@ export class Universe {
|
|||||||
/**
|
/**
|
||||||
* initiates a server
|
* initiates a server
|
||||||
*/
|
*/
|
||||||
public async initServer(portArg: number | string) {
|
public async start(portArg: number | string) {
|
||||||
// lets create the base smartexpress server
|
// lets create the base smartexpress server
|
||||||
this.smartexpressServer = new plugins.smartexpress.Server({
|
this.smartexpressServer = new plugins.smartexpress.Server({
|
||||||
cors: true,
|
cors: true,
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smartuniverse.plugins';
|
import * as plugins from './smartuniverse.plugins';
|
||||||
|
import * as interfaces from './interfaces';
|
||||||
|
|
||||||
import { Objectmap } from '@pushrocks/lik';
|
import { Objectmap } from '@pushrocks/lik';
|
||||||
|
|
||||||
@ -11,12 +12,15 @@ import { UniverseCache } from './smartuniverse.classes.universecache';
|
|||||||
* represents a message within a universe
|
* represents a message within a universe
|
||||||
* acts as a container to save message states like authentication status
|
* acts as a container to save message states like authentication status
|
||||||
*/
|
*/
|
||||||
export class UniverseMessage {
|
export class UniverseMessage implements interfaces.IUniverseMessage {
|
||||||
/**
|
/**
|
||||||
* public and unique id
|
* public and unique id
|
||||||
* numeric ascending
|
* numeric ascending
|
||||||
* adheres to time in milliseconds
|
* adheres to time in milliseconds
|
||||||
* avoids duplications though
|
* -> meaning it describes the time of arrival
|
||||||
|
* -> two messages received at the same time will count up the second one
|
||||||
|
* -> avoids duplications of messages
|
||||||
|
* -> may be changed to nanoseconds to ensure higher throughput
|
||||||
*/
|
*/
|
||||||
public id: number;
|
public id: number;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user