Ikk почему, но я продолжаю получать эту ошибку ... Я закрываю соединение, приемник и сеанс, но сообщения все еще заблокированы. Есть ли способ решить эту проблему?
Вот мой индекс. js:
const express = require ("express");
const publisher = require ("./publisher");
const subscriber = require ("./subscriber");
const app = express();
const bodyParser = require("body-parser");
app.use(bodyParser.json ({ limit : '50mb'}));
app.use(bodyParser.urlencoded({ limit : '50mb', extended: true}))
app.post(
"/", publisher
)
app.get(
"/", subscriber
)
app.listen(8080);
Вот мой издатель. js:
var sender = connection.open_sender(topic);
console.log(req.body);
sender.on('sendable', function(context) {
for (var i = 0; i < req.body.length; i++) {
var m = req.body[i];
console.log('sent ' + m);
sender.send({body:m});
}
connection.close();
});
res.send("batata");
}
И вот мой подписчик. js:
module.exports = function (req, res) {
var client = 'my-client';
var subscription = 'my-subscription';
var topic = 'topic://PRICE.STOCK.NYSE.RHT';
var host = 'localhost';
var port = 5672
var connection = require('rhea').connect({ port:port, host:host, container_id:client });
connection.on('message', function (context) {
if (context.message.body === 'detach') {
context.receiver.detach();
context.connection.close();
} else if (context.message.body === 'close') {
context.receiver.close();
context.connection.close();
} else {
res.send(context.message.body);
context.receiver.close();
context.connection.close();
}
});
connection.open_receiver({name:subscription, source:{address:topic, durable:2, expiry_policy:'never'}});
}
Сразу же я выполняю следующие шаги: - Запустите сервер с ./artemis run
в каталог моего брокера
Вкл. VSCode, в каталог этих файлов: node index.js
С почтальоном я отправляю запрос POST со следующим телом:
["batata", "bla", "ой"]
И в заключение sh, я отправляю запрос GET
Вот URL : http://localhost: 8080
Затем мой вывод VsCode отображает это:
[ 'batata', 'bla', 'oi' ]
sent batata
sent bla
sent oi
events.js:187
throw er; // Unhandled 'error' event
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:485:11)
at ServerResponse.header (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/node_modules/express/lib/response.js:771:10)
at ServerResponse.send (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/node_modules/express/lib/response.js:170:12)
at Connection.<anonymous> (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/examples/durable_subscription/subscriber.js:50:13)
at Connection.emit (events.js:210:5)
at Connection.dispatch (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/connection.js:242:37)
at Session.dispatch (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/session.js:452:41)
at Receiver.link.dispatch (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/link.js:62:38)
at Incoming.on_transfer (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/session.js:361:22)
at Session.on_transfer (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/session.js:749:19)
Emitted 'error' event on Container instance at:
at Container.dispatch (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/container.js:41:33)
at Connection.dispatch (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/connection.js:245:40)
at Connection.input (/home/amq-broker/amq-javascript-2.5.0/node_modules/rhea/lib/connection.js:520:18)
at Socket.emit (events.js:210:5)
at addChunk (_stream_readable.js:309:12)
at readableAddChunk (_stream_readable.js:290:11)
at Socket.Readable.push (_stream_readable.js:224:10)
at TCP.onStreamRead (internal/stream_base_commons.js:182:23) {
code: 'ERR_HTTP_HEADERS_SENT'
}