I'm getting an error when trying to receive messages from within a browser. The
same code runs fine when run from the command line using "node".
The error message is:
Module.MessengerError {name: "MessengerError", message: "listen: Not
supported", constructor: function, toString: function}
The error happens when calling messenger.subscribe(address);
Is it the case that subscribing is actually not supported from within a
browser, or am I possibly doing something wrong?
I basically just took the code from recv.js and put it in a HTML page.
Here is the code:
<!DOCTYPE html> <!-- HTML5 doctype -->
<html>
<head>
<title>Simple Proton Messenger Send Example</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<script type="text/javascript"
src="../../../node_modules/qpid-proton/lib/proton.js"></script>
<script type="text/javascript">
var address = "amqp://~0.0.0.0";
var message = new proton.Message();
var messenger = new proton.Messenger();
var pumpData = function() {
while (messenger.incoming()) {
var t = messenger.get(message);
console.log("Address: " + message.getAddress());
console.log("Subject: " + message.getSubject());
// body is the body as a native JavaScript Object, useful for most real
cases.
//console.log("Content: " + message.body);
// data is the body as a proton.Data Object, used in this case because
// format() returns exactly the same representation as recv.c
console.log("Content: " + message.data.format());
messenger.accept(t);
}
};
console.log("address = '" + address + "'");
messenger.setIncomingWindow(1024);
messenger.on('error', function(error) {console.log(error);});
messenger.on('work', pumpData);
messenger.start();
messenger.subscribe(address);
messenger.recv(); // Receive as many messages as messenger can buffer.
</script>
</head>
<body>
</body>
</html>
Regards,
-Ernie