Java Code Examples for org.springframework.jms.support.converter.MessagingMessageConverter

Following code examples demonstrate how to use org.springframework.jms.support.converter.MessagingMessageConverterfrom spring-framework. These examples are extracted from various highly rated open source projects. You can directly use these code snippets or view their entire linked source code. These snippets are extracted to provide contextual information about how to use this class in the real world. These samples also let you understand some good practices on how to use org.springframework.jms.support.converter.MessagingMessageConverterand various code implementation of this class.

  public MessageConverter messageConverter() {
    MappingJackson2MessageConverter payloadConverter =
        new MappingJackson2MessageConverter();
    payloadConverter.setTargetType(MessageType.TEXT);
    payloadConverter.setTypeIdPropertyName("__type");

    MessagingMessageConverter messageConverter =
        new MessagingMessageConverter();
    messageConverter.setPayloadConverter(payloadConverter);
    return messageConverter;
  } 


    public void onMessage(Message message) {

        Assert.isTrue(message instanceof TextMessage, "TextMessage only");
        MessageConverter converter = new MessagingMessageConverter();

        try {

            @SuppressWarnings("unchecked")
            org.springframework.messaging.Message<String> msg =
                    (org.springframework.messaging.Message<String>) converter.fromMessage(message);

            logMessage(msg);
            onMessage(msg);

        } catch (JMSException ex) {
            throw new ApplicationException(ex);
        }
    } 

	public void onMessage(Message message) {
		
		try {
			MessagingMessageConverter convert = new MessagingMessageConverter();
			Object object = convert.fromMessage(message);
			System.out.println(object+":");
		} catch (JMSException e) {
			e.printStackTrace();
		}
		
		
	} 

        JmsMessagingTemplate jmsMessagingTemplate(ConnectionFactory connectionFactory, MappingJackson2MessageConverter mappingJackson2MessageConverter) {
            JmsMessagingTemplate template = new JmsMessagingTemplate(connectionFactory);
            template.setJmsMessageConverter(
                    new MessagingMessageConverter(mappingJackson2MessageConverter, new SimpleJmsHeaderMapper()));
            return template;
        } 

    public JmsTemplate template(ConnectionFactory connectionFactory) {

        JmsTemplate template = new JmsTemplate(connectionFactory);
        template.setMessageConverter(new MessagingMessageConverter());

        if (receiveTimeout != null) {
            template.setReceiveTimeout(receiveTimeout);
        }
        return template;
    } 

Advertisement
Javadoc
Convert a Message from the messaging abstraction to and from a javax.jms.Message using an underlying

MessageConverter for the payload and a org.springframework.jms.support.JmsHeaderMapper to map the JMS headers to and from standard message headers. @author Stephane Nicoll @since 4.1

Read More
Advertisement