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 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
| var stompit = require('stompit');
/** * 获取MQ监听 * @param agent */ function startCloudPrintService() { console.log('startCloudPrintService'); const connectOptions = { host: '172.19.71.120', 'client-id': 'shop-bff', port: 61613, timeout: 30000, connectHeaders: { host: '172.19.71.120', login: '', passcode: '', 'heart-beat': '5000,5000', }, }; stompit.connect( connectOptions, function(error, client) { if (error) { console.log('connect error ' + error.message); return; }
// let sendHeaders = { // destination: '/queue/test', // 'content-type': 'text/plain', // };
// let frame = client.send(sendHeaders); // frame.write('hello'); // frame.end(); let subscribeHeaders = { subscription: 'd2cTradeOperateTopic', destination: 't.d2c.tc.TradeOperate', ack: 'client-individual', };
client.subscribe(subscribeHeaders, function(error, message) { if (error) { console.log('subscribe error ' + error.message); return; }
message.readString('utf-8', function(error, body) { if (error) { console.log('read message error ' + error.message); return; }
console.log('received message: ' + body);
client.ack(message);
client.disconnect(); }); }); }, ); }
startCloudPrintService();
|