0

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

D Nunes
  • 83
  • 6
  • 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](https://www.fileformat.info/info/unicode/char/00e1/index.htm). 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 '21 at 22:01
  • Related: [JSON and escaping characters](https://stackoverflow.com/questions/4901133/json-and-escaping-characters), [How To Convert JSON String That Contains Encoded Unicode](https://stackoverflow.com/questions/7460645/how-to-convert-json-string-that-contains-encoded-unicode) – andrewJames May 13 '21 at 22:01
  • "How can I resolve this?" - What would you consider a resolution? – Jeff Scott Brown May 17 '21 at 18:14
  • I thought that it was a charset mistake. But I saw the explanation from andrewjames and it made sense for me. So, I consider this as a solution. – D Nunes May 18 '21 at 14:25

1 Answers1

0

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

D Nunes
  • 83
  • 6