编程语言
首页 > 编程语言> > javascript-使用rabbitmq stomp发送protobuf(二进制)数据

javascript-使用rabbitmq stomp发送protobuf(二进制)数据

作者:互联网

我已经在客户端使用protobuf.js创建了Rabbitmq踩踏的一个示例.
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标头.

请帮我.没人知道吗?

解决方法:

我知道两年后我会回答!但我认为我应该分享:)

我正在使用Rabbitmq stomp发送ProtoBuf编码数据的项目.

我遇到了同样的问题:我可以发送,但不能在接收端解码.

我通过使用另一种编码就可以使它工作:

>变更:

var buffer = car.encode();

至:

var buffer = car.encode64();

>变更:

var carDec =Car.decode64(buffer);

至:

var carDec =Car.decode64(buffer);

这解决了我的问题,希望也能解决您的问题.

标签:content-length,rabbitmq,protocol-buffers,stomp,javascript
来源: https://codeday.me/bug/20191031/1971968.html