3

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?

1 Answer 1

5

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.

Sign up to request clarification or add additional context in comments.

1 Comment

@Fouad are you encoding using base64?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.