0

I have got device simulator written in python which sent Protobuff messages using mqtt paho client. Problem occurs when I consume those messages by another client written in Java(also eclipse paho). Payload that I receive seems to be corrupted. I am guessing that broker (mosquitto) is trying to decode message and it fails because it is protobuff message. I have also tried to use rabbitMq with mqtt plugin and it works, but I cannot use rabbit because of other reasons. Anyone had similar problem or know how to make it work?

Sent payload:

b'\n>\n\x0c\x08\xed\xd8\xb8\x8d\x06\x10\xb8\x80\x98\xb7\x03\x12\x0cxxxxx\x82?\x1f\n\x06329.00\x12\x06135.00\x1a\x06242.00"\x0530.70\n0\n\x0c\x08\xed\xd8\xb8\x8d\x06\x10\xb8\xf7\x9a\xb7\x03\x12\x0cxxxxx\xca>\x11\x08,\x12\x071875.44\x1a\x040.00\n<\n\x0c\x08\xed\xd8\xb8\x8d\x06\x10\xd8\x90\x9d\xb7\x03\x12\x0cxxxxx\xf2>\x1d\n\x0538.00\x12\x0515.00\x1a\x06242.00"\x0560.00\n,\n\x0c\x08\xed\xd8\xb8\x8d\x06\x10\xc0\x9b\x9c\xb7\x03\x12\x0xxxxx\xfa>\r\n\x0539.00\x12\x040.00\n(\n\x0c\x08\xed\xd8\xb8\x8d\x06\x10\xd8\x8d\x9e\xb7\x03\x12\x0cxxxxx\x8a?\t\n\x072614.00'
en

Received payload:

>
�ظ��ž�xxxxx�?
329.00135.00242.00"30.70
0
�ظ�����xxxxx�>,1875.440.00
<
�ظ�Є��xxxxx�>
42.0017.00242.00"59.90
,
�ظ�����xxxxx�>
42.000.00
(
�ظ��ꣲxxxxx�?    
2610.00

I am using spring messaging to receive message:

   @Bean
    @ServiceActivator(inputChannel = "mqttInputChannel")
    public MessageHandler messageHandler() {
        var converter = new TelemetryConverter();
        return new MessageHandler() {
            @Override
            public void handleMessage(Message<?> message) throws MessagingException {
                SmartMessageConverter messageConverter = new ByteArrayMessageConverter();
                messageConverter.fromMessage(message,String.class);
                log.info(String.format("Received message: %s",message.getPayload()));
                try {
                    MeasurementProto.Measurement.parseFrom((ByteBuffer) message.getPayload());
                } catch (InvalidProtocolBufferException e) {
                    e.printStackTrace();
                }
                process.handle(converter.fromMessage(message));
            }
        };
    }
morgenz
  • 3
  • 1
  • 3
    If I were asking strangers for help with this problem, I think I would share the sending code as well as the receiving code. Also, MQTT is agnostic as to the payload it carries. It's not going to try to decode it - the payload is just an array of bytes. Perhaps you need to serialize and deserialize whatever you're trying to transmit? – romkey Dec 06 '21 at 16:13
  • 3
    Also what you posted - you output the sent payload as hex. You're outputting the received payload as binary. Of course they look different. – romkey Dec 06 '21 at 16:13
  • The RabbitMQ MQTT plugin supports only MQTT v3. Be sure that your Mosquitto is configured properly. – Artem Bilan Dec 06 '21 at 16:37

0 Answers0