<commit_before>/**
 * Created by bournewang on 16/8/10.
 */
'use strict';

const stomp = require('webstomp-client'),
    config = require('../config'),
    logger = require('./logger'),
    WebSocket = require('ws'),
    url = config.stomp.url;
const path = require('path');
const JSONUtils = require(path.resolve('./modules/core/server/JSONUtils'));

exports.publish = function (mqName, obj, callback) {
    let ws = new WebSocket(url);
    let client = stomp.over(ws, {debug: false});
    ws.on('close', function close() {
        console.error('disconnected', arguments);
    });
    client.connect(config.stomp.connectHeader, function () {
        obj.MQName = mqName;
        client.send(config.stomp.defaultQueue, JSONUtils.stringify(obj));
        client.disconnect();
        callback();
    }, function (err) {
        logger.error(err);
        client.disconnect();
        callback(err);
    });
};

exports.subscribe = function (msgDealers) {
    let client = stomp.over(new WebSocket(url), {debug: false});
    client.connect(config.stomp.connectHeader, function () {
        client.subscribe(config.stomp.defaultQueue, function (message) {
            if (message.body) {
                if (msgDealers && msgDealers instanceof Array) {
                    let canDeal = false;
                    let msgObject = JSONUtils.parse(message.body);
                    for (let i = 0; i < msgDealers.length; i++) {
                        let msgDealer = msgDealers[i];
                        if (msgObject.MQName === msgDealer.MQName) {
                            canDeal = true;
                            msgDealer.dealMessage(msgObject);
                            break;
                        }
                    }
                    if (!canDeal) {
                        logger.error('No receiver for ' + msgObject.MQName);
                    }
                }
            } else {
                logger.error('Empty message');
            }
        });
    });
};
<commit_msg>替换原有JSON 增加对Date反序列化<commit_after>/**
 * Created by bournewang on 16/8/10.
 */
'use strict';

const stomp = require('webstomp-client'),
    config = require('../config'),
    logger = require('./logger'),
    WebSocket = require('ws'),
    url = config.stomp.url;
const path = require('path');
const JSONUtils = require(path.resolve('./modules/core/server/common/JSONUtils'));

exports.publish = function (mqName, obj, callback) {
    let ws = new WebSocket(url);
    let client = stomp.over(ws, {debug: false});
    ws.on('close', function close() {
        console.error('disconnected', arguments);
    });
    client.connect(config.stomp.connectHeader, function () {
        obj.MQName = mqName;
        client.send(config.stomp.defaultQueue, JSONUtils.stringify(obj));
        client.disconnect();
        callback();
    }, function (err) {
        logger.error(err);
        client.disconnect();
        callback(err);
    });
};

exports.subscribe = function (msgDealers) {
    let client = stomp.over(new WebSocket(url), {debug: false});
    client.connect(config.stomp.connectHeader, function () {
        client.subscribe(config.stomp.defaultQueue, function (message) {
            if (message.body) {
                if (msgDealers && msgDealers instanceof Array) {
                    let canDeal = false;
                    let msgObject = JSONUtils.parse(message.body);
                    for (let i = 0; i < msgDealers.length; i++) {
                        let msgDealer = msgDealers[i];
                        if (msgObject.MQName === msgDealer.MQName) {
                            canDeal = true;
                            msgDealer.dealMessage(msgObject);
                            break;
                        }
                    }
                    if (!canDeal) {
                        logger.error('No receiver for ' + msgObject.MQName);
                    }
                }
            } else {
                logger.error('Empty message');
            }
        });
    });
};

{'fraction_non_alphanumeric': 0.1327543424317618, 'fraction_numerical': 0.002977667493796526, 'mean_word_length': 1.7181389076196898, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2804916', 'n_tokens_mistral': 1140, 'n_tokens_neox': 1095, 'n_words': 221}