[rabbitmq-discuss] Publishing binary data using the java client

Matthias Radestock matthias at rabbitmq.com
Sat Jan 12 23:15:57 GMT 2013


Christian,

On 12/01/13 17:44, Christian Strack wrote:
> Hello Matthias and Michael and thank you for your fast response. In
> this mail is the full code including de- and encoding:

Thanks for posting this. While it's not executable code, I think I've 
spotted the problem...

Here's a fragment of the receiver code:

>         byte[] data = new byte[4];
>
>         for(int i=0; i<count;i++){
>             t.read(data, 4);
>             System.out.println("Received Package #"+i);
>             new_value = ByteBuffer.wrap(data).getInt();

You appear to expect the 'read' invocation to modify the 'data' array 
that you pass in as an argument.

But 'read' looks like this:

>     public int read(byte[] data, int len) {
>         try {
>             Delivery delivery = consumer.nextDelivery();
>             if (delivery != null){
>                 data = delivery.getBody();
>                 System.out.println(new String(data));
>                 return len;
>             }

The delivery.getBody() call returns a reference to an array, and the 
above simply assigns a that reference to the local 'data' variable.

So the data that is being read never makes it out of that function.


Regards,

Matthias.


More information about the rabbitmq-discuss mailing list