Send protobuf(binary) data using rabbitmq stomp

I have create one example for rabbitmq stomp using protobuf.js on client side. protobuf example link: https://github.com/dcodeIO/ProtoBuf.js

Send message file content:-

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
      );    

}

Receive file content:-

  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
          );    

  }

I can not decode data send by stomp(protobuf binary data). Please guide me to set "content-length" into stomp header if problem solved through "content-length".

Please help me. no one knows about this?

Answers:

Answer

I know that I'm answering after 2 years ! but I thought I should share :)

I am working on a project using rabbitmq stomp to send ProtoBuf encoded data.

I faced the same problem: I could send but could not decode at the receiving end.

I got it to work simply by using another encoding:

  • Change:

    var buffer = car.encode();
    

    to:

    var buffer = car.encode64();
    
  • Change:

    var carDec =Car.decode64(buffer);
    

    to:

    var carDec =Car.decode64(buffer);
    

This solved my problem, I hope it also solves yours.

Tags

Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.