我在客户端使用 protobuf.js 为rabbitmq stomp 创建了一个示例。protobuf 示例链接:https ://github.com/dcodeIO/ProtoBuf.js
发送消息文件内容:-
var Game = builder.build("Game");
var Car = Game.Cars.Car;
var car = new Car("Rusty", "mayur");
var buffer = car.encode();
var mq_username = "guest",
mq_password = "guest",
mq_vhost = "/",
mq_url = 'http://192.168.0.14:15674/stomp',
mq_queue1 = '/queue/A3';
var client = Stomp.client(mq_url);
function on_connect()
{
client.send(mq_queue1, { priority: 9}, buffer);
}
window.onload = function ()
{
client.connect(
mq_username,
mq_password,
on_connect,
on_connect_error,
mq_vhost
);
}
接收文件内容:-
var Game = builder.build("Game");
var Car = Game.Cars.Car;
var car = new Car("Rusty", "mayur");
var buffer = car.encode();
var mq_username = "guest",
mq_password = "guest",
mq_vhost = "/",
mq_url = 'http://192.168.0.14:15674/stomp',
mq_queue1 = '/queue/A3';
var client = Stomp.client(mq_url);
function on_connect()
{
un = client.subscribe(mq_queue1, on_message);
}
function on_message(m)
{
console.log('message received');
console.log(m);
var buffer = m.body;
alert(buffer);
var carDec =Car.decode(buffer);
alert(carDec.model);
}
window.onload = function ()
{
client.connect(
mq_username,
mq_password,
on_connect,
on_connect_error,
mq_vhost
);
}
我无法解码 stomp(protobuf 二进制数据)发送的数据。如果问题通过"content-length"解决,请指导我将"content-length"设置为stomp header。
请帮我。没有人知道这件事吗?