With Spring4 + ActiveMQ
I want to receive a JMS Message from a Queue and convert to POJO automatically. I added the MappingJackson2MessageConverter
to DefaultJmsListenerContainerFactory
:
@Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory() {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
// some other config
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("???");
factory.setMessageConverter(converter);
return factory;
}
And this is my Listener Config
@JmsListener(destination = "queue.fas.flight.order", containerFactory = "jmsListenerContainerFactory")
public void processOrder(OrderRegisterDto registerParam) {
System.out.println(registerParam.toString());
}
My question is, how do I set TypeIdPropertyName
? The Queue is not under my control; others send JSON
to it.
I want a common converter so I am using String
receive message and am converting it to a POJO manually.
@JmsListener(destination = "xxxx", containerFactory = "xxxxx")
public void order(String registerParam) {
try{
OrderRegisterDto dto = objectMapper.readValue(registerParam,OrderRegisterDto.class);
}catch (IOException e){
// TODO
}
}
Are there any other better methods?