@tactfulai/common
v2.0.0
Published
Tactful features
Readme
Tactful Utils
Core Library that include Core Models, Functions and Communication way between micro services
Table Of Content:
Installation
npm install @tactful/utils --saveConsiderations:
- Minimal Node.js version is >= 14 (RedisSMQ is tested under current active LTS and maintenance LTS Node.js releases).
- Minimal Redis server version is 2.6.12 (RedisSMQ is tested under Redis v2.6, v3, v4, v5, and v6).
Tactful Bus
1. Architecture
2. Configration
you can configure TactfulBus by using Iconfig Interface that you pass in getTactfulBus Method to get a tactfulBus Instance
**IConfig < Interface> **:
broker: Broker;
namespace: string;
messageExpiration: number;
client?: any;
username?: string;
password?: string;
/**
* IP address of the server.
* @default 127.0.0.1
*/
host?: string | undefined;
/**
* Port of the server.
* @default 6379
*/
port?: number | undefined;
/**
* The UNIX socket string of the server.
* @default null
*/
path?: string | undefined;
/**
* The URL of the server.\
* Format:
* [redis[s]:]//[[user][:password@]][host][:port][/db-number][?db=db-number[&password=bar[&option=value]]]\
* More info avaliable at [IANA](http://www.iana.org/assignments/uri-schemes/prov/redis).
* @default null
*/
url?: string | undefined;Paramters
- Broker:
redis|kafka- namespace:
The Env Name : development if local and qa if QA Env and so ondefault : development
3. Topics
Tactful Bus based on Topic Message Exchange
The pattern of a topic exchange is a string which is composed of alphanumeric characters, including - and _ characters, that are separated by a .. The a.b.c.d topic pattern matches the following queues a.b.c.d, a.b.c.d.e, and a.b.c.d.e.f, but it does not match the a.b, a.b.c, or a.b.c.z queues.
Note: use lowercase names for all topics..no camelCase or PascalCase
Topic Nameing convension
- use essential event and add ServiceName at the end :
tactful.[event].[topic].[service]
- topic is optional
Example:
Channels Service Publish to channel_msg so Automation Service Listen on Topic channel_msg.automation and LivechatServer Service listen on Topic channel_msg.livechat ...etc
Tactful essential Events
- tactful.channel_msg
- tactful.msg_reply
- tactful.event
- tactful.parsed_msg
4. Usage
import { getTactfulBus } from "@tactful/utils";
//Setup configuration to connect with redis
let configuration = {};
configuration.broker = "redis";
configuration.password = "123456"
configuration.messageExpiration = 3600000;
configuration.namespace = "development"
const bus = getTactfulBus(configuration); // get tactful bus Instance
//Message Handler Call back .. it'll be called when listen on Topic
const messageHandler = (msg, cb) => {
const payload = msg.getBody();
console.log('Consume >>> Message payload', payload);
cb(); // acknowledging the message
};
bus.on('tactful.test.service1', messageHandler); // Subscribe Listining to topic
bus.startConsuming(); // start to consume from subscribed topics
bus.publish("tactfull.test", {hello:"world"}); //publish message to TopicCustomer manager
const valid = MessageLimit.mediaLimits(message);
// message reject
if(!valid){
console.log(valid.message)
}5. Advanced Details
to get more details See Tactful Bus Refrence
Tactful Models
Tactful Message Message Message
Tactful Reply reply: text reply: text
