Package org.springframework.amqp.support.converter

Examples of org.springframework.amqp.support.converter.MessageConverter


        public void run() {
            org.apache.camel.Message message = exchange.getIn();
            SpringAMQPMessage inMessage = new SpringAMQPMessage(message);
            exchange.setIn(inMessage); //Swap out the old message format

            MessageConverter msgConverter;
            if(endpoint.getAmqpTemplate() instanceof RabbitTemplate) {
                RabbitTemplate rabbitTemplate = (RabbitTemplate) endpoint.getAmqpTemplate();
                msgConverter = rabbitTemplate.getMessageConverter();
            } else {
                LOG.warn("Cannot find RabbitMQ AMQP Template, falling back to simple message converter");
View Full Code Here


    }

    @Override
    protected Message createMessage(Object object, MessageProperties messageProperties) {
        String contentType = messageProperties.getContentType();
        MessageConverter converter = converters.get(contentType);
        if(converter == null) //Try to fall back
            converter = this.fallbackConverter;
        if(converter == null) //Can't even fall back, punt
            throw new MessageConversionException("Cannot find converter for content type of "+contentType);
       
        return converter.toMessage(object, messageProperties);
    }
View Full Code Here

        MessageProperties messageProperties = message.getMessageProperties();
        String contentType = messageProperties.getContentType();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");
       
        MessageConverter converter = converters.get(contentType);
        if(converter == null) //Try to fall back
            converter = this.fallbackConverter;
        if(converter == null) //Can't even fall back, punt
            throw new MessageConversionException("Cannot find converter for content type of "+contentType);
       
        return converter.fromMessage(message);
    }
View Full Code Here

        public void run() {
            org.apache.camel.Message message = exchange.getIn();
            SpringAMQPMessage inMessage = new SpringAMQPMessage(message);
            exchange.setIn(inMessage); //Swap out the old message format

            MessageConverter msgConverter;
            if(endpoint.getAmqpTemplate() instanceof RabbitTemplate) {
                RabbitTemplate rabbitTemplate = (RabbitTemplate) endpoint.getAmqpTemplate();
                msgConverter = rabbitTemplate.getMessageConverter();
            } else {
                LOG.warn("Cannot find RabbitMQ AMQP Template, falling back to simple message converter");
View Full Code Here

    public void process(Exchange exchange) throws Exception {
        org.apache.camel.Message message = exchange.getIn();
        SpringAMQPMessage inMessage = new SpringAMQPMessage(message);
        exchange.setIn(inMessage); //Swap out the old message format
       
        MessageConverter msgConverter;
        if(this.endpoint.getAmqpTemplate() instanceof RabbitTemplate) {
            RabbitTemplate rabbitTemplate = (RabbitTemplate) this.endpoint.getAmqpTemplate();
            msgConverter = rabbitTemplate.getMessageConverter();
        } else {
            LOG.warn("Cannot find RabbitMQ AMQP Template, falling back to simple message converter");
View Full Code Here

    return new Message(response.getBody(), messageProps);
  }

  private MessageConverter getRequiredMessageConverter()
      throws IllegalStateException {
    MessageConverter converter = this.getMessageConverter();
    if (converter == null) {
      throw new AmqpIllegalStateException(
          "No 'messageConverter' specified. Check configuration of RabbitTemplate.");
    }
    return converter;
View Full Code Here

    }
   
    @Test
    public void fromAMQP() throws Exception {
        String body = "Test Message";
        MessageConverter msgConverter = new StringMessageConverter();
        MessageProperties properties = new MessageProperties();
        properties.setHeader("NotSecret", "Popcorn");
        org.springframework.amqp.core.Message message = new org.springframework.amqp.core.Message(body.getBytes(), properties);
       
        SpringAMQPMessage camelMessage = SpringAMQPMessage.fromAMQPMessage(msgConverter, message);
View Full Code Here

        Assert.assertEquals("Popcorn", camelMessage.getHeader("NotSecret"));
    }
   
    @Test
    public void toAMQP() throws Exception {
        MessageConverter msgConverter = new StringMessageConverter();
       
        SpringAMQPMessage camelMessage = new SpringAMQPMessage();
        camelMessage.setBody("Test Message 2");
        camelMessage.setHeader("Secret", "My Secret");
       
View Full Code Here

        TestObject testObject = new TestObject();
        testObject.setValue("TESTING");
       
        MessageProperties messageProperties = new MessageProperties();
       
        MessageConverter converter = new XStreamConverter();
        ((XStreamConverter) converter).setEncoding("UTF-8");
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Assert.assertEquals("{\"amqp.spring.converter.XStreamConverterTest_-TestObject\":{\"value\":\"TESTING\"}}", new String(amqpMessage.getBody()));

        Object newObject = converter.fromMessage(amqpMessage);
        Assert.assertEquals(testObject, newObject);
        Assert.assertEquals("UTF-8", ((XStreamConverter) converter).getEncoding());
    }
View Full Code Here

        TestObject testObject = new TestObject();
        testObject.setValue("TESTING");
       
        MessageProperties messageProperties = new MessageProperties();
       
        MessageConverter converter = new StringConverter();
        Message amqpMessage = converter.toMessage(testObject, messageProperties);
        Object newObject = converter.fromMessage(amqpMessage);
       
        Assert.assertEquals("TESTING", newObject);
    }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.support.converter.MessageConverter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.