Search code examples
grailsrabbitmq

RabbitMQ writes wrong characters in my queue


I am trying to publish a message in RabbitMQ using grails 3.3.11. But I am in trouble with brazilian portuguese chars.

It seems to be a matter of charset, but I don't know how to resolve it. If anyone knows, please help me.

After proccessing a message in a queue, my code publish a status in another queue. The problem is that I publish a message, but when I go to see that in RabbitMQ, the message is modified with wrong characters. Specifically for brazilian protuguese characters like à, ç, õ, ú and others.

That is my queue publishing code, that where the problem is happening.

def publishNewStatus(String solicId, String newStatus, String message){
    rabbitMessagePublisher.send {
        exchange = "plt.cmbsolic.requests.status"
        body = [requestId:solicId,status:newStatus,message:message]
    }
}

That is the console result for the publishing. Note that it is correct.

QUEUE CONSUMING        => STARTED AT Thu May 13 17:58:49 BRT 2021
SOLICITATION ID STATUS => Status FAILED_IN_CMBID for solicitation 2419399765SOL01 
API RESPONSE           => Usuário 2419399765 não encontrado
QUEUE CONSUMING        => FINISHED AT Thu May 13 17:58:49 BRT 2021

API response is the variable message, the third argument for the method publishNewStatus.

But if I go to the queue, that is the message which is stored there.

{"requestId":"2419399765SOL01","status":"FAILED_IN_CMBID","message":"Usu\u00e1rio 2419399765 n\u00e3o encontrado"}

Note that á is replaced by \u00e1 and ã is replaced by \u00e3.

How can I resolve this?

Thanks a lot.

Alfredo Oliveira


Solution

  • I am replicating here the observation of @andrewjames. Since it is not a problem, I could notice this because of this observation. So, it is the solution.

    Not an answer - just an observation: The message is still valid JSON. The \u00e1 string is how JSON stores Unicode-escaped characters. So, for example your á is represented by that sequence. So, not only is the message valid, but it is equivalent to your original text. Any consumer of this JSON should itself use a JSON library, which should handle these escape sequences correctly - for example, if the JSON needs to be parsed and its text needs to be displayed to users. – andrewjames May 13 at 22:01