jms.js 1.08 KB
Newer Older
Spencer Chang's avatar
Spencer Chang committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
/*
    var jms = new JMS();
    jms.sendMessage('topic', 'message', [{
        key: 'key1',
        value: 'value1'
    }, {
        key: 'key2',
        value: 'value2'
    }]);

 */

function JMS() {

}
/*
 * [{key:'kkkkey',value:'vvvalue'}]
 * 
 */
JMS.prototype.sendMessage = function(topic, message, properties, trx) {
	var context = $ctx.getData();
	var pps = new CompositeMap('property').getData();
	properties = properties || [];
	for ( var i = 0; i < properties.length; i++) {
		var p = this.createProperty(properties[i]);
		p.putToMap(context, pps, true);
	}
	var msg = new Packages.leaf.application.features.msg.Message(message, pps);
	var dispatcher = null;
	if (trx) {
		dispatcher = $ctx['_instance.leaf.application.features.msg.IMessageDispatcher'];
	} else {
		var messageStub = $instance('leaf.application.features.msg.IMessageStub');
		dispatcher = messageStub.getDispatcher();
	}
	dispatcher.send(topic, msg, context);
};

JMS.prototype.createProperty = function(obj) {
	var p = new Packages.leaf.application.features.msg.Property();
	p.setKey(obj.key);
	p.setValue(obj.value);
	return p;
};