Thursday 15 March 2012

Should image be base64 encoded in a JSON message or returned as BytesMessage in Spring AMQP? -


The

I use the Reply to the message through the setup basic request / Spring POJOs AMQP and in a JSON message converter Exchanges are exchanged over RabbitMQ.

My feedback pojo's payload has been simple yet, but now I need to reply in the form of an image over time too.

Q1) What would be the best way to handle this? Should the image be encoded base 64 as the payload string for the JSON message?

Q2) Is it possible to just go back to the image instead of as a BytesMessage?

Q2.a) spring would -mapeepi is capable of two-handle different audience, one that gives Piooo and secondly that that byte message? I do not think what I'm asking, but here's some pseudo code:

  & lt; Audience Container & gt; & Lt; Audience Rif = "Request Handler A" method = "Handmuffed" queue-name = "# {requestQueue.name}" /> & Lt; Audience Rif = "Request Handlerby" method = "Handlame" queue-name = "# {requestQueue.name}" /> & lt; / Listener-container & gt; Public class RequestHandlerA {public ResponseDelegatePojo handleMessage (RequestDelegatePojo requestDelegate) {...}} public class RequestHandlerB {public BytesMessage handleMessage (RequestDelegatePojo requestDelegate) {...}}   

Q2.b) or ... MessageListener an object, then (sometimes can be a POJO, can be a BytesMessage at other times) ... spring AMQP framework and to send it back as POJO sometimes json serialized runtime Would be able to adjust accordingly but at other times the bytes message is as ?

Two listeners, such as Live 'T' - it will create two solutions on one line only to two competing consumers To use different queues (and different listeners).

If you want to use the same line to the requests of both, perhaps your listener POJO return object (POJO or bytes for simple solutions [ ] ) (Q2b) and use a custom MessageConverter

Custom messageConverter will be very simple; Assuming that you always get JSON on the inside, it is always a representative JsonMessageConverter code> fromMessage () and outbound side ( toMessage ) Should either be representative for a JsonMessageConverter or SimpleMessageConverter :

  (if the example byte byte []) {This return. SimpleMessageConverter.toMessage (Object, Message Properties); Else {return.jsonMessageConverter.toMessage (Object, Message Properties); }   

SimpleMessageConverter will set contentType property to application / octet-stream but you can change That if you want to call your toMessage method ( messages.getmessageproperties ()) after calling. SetContentType (...); .

No comments:

Post a Comment