Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.MessageProperties


       
        return ExchangePattern.valueOf(exchangePatternName);
    }

    public Message toAMQPMessage(MessageConverter msgConverter) {
        MessageProperties properties = new MessageProperties();
        properties.setMessageId(this.getMessageId());
       
        Message amqpMessage;
        if(this.getBody() != null) {
            amqpMessage = msgConverter.toMessage(this.getBody(), properties);
           
View Full Code Here


        }
    }

    @Override
    public Object fromMessage(Message message) throws MessageConversionException {
        MessageProperties messageProperties = message.getMessageProperties();
        if(messageProperties == null)
            throw new MessageConversionException("Cannot decode a message with no properties!");

        byte[] body = message.getBody();
        if(body == null)
            return null;

        String messageEncoding = messageProperties.getContentEncoding();
        if(messageEncoding == null)
            messageEncoding = getEncoding();

        String contentType = messageProperties.getContentType();
        if(! MessageProperties.CONTENT_TYPE_JSON.equalsIgnoreCase(contentType))
            throw new MessageConversionException("Cannot understand a message of type "+contentType);

        try {
            ByteArrayInputStream inStream = new ByteArrayInputStream(body);
            StaxReader reader = new StaxReader(new QNameMap(), this.inputFactory.createXMLStreamReader(inStream, messageEncoding));
            return this.objectMapper.unmarshal(reader);
        } catch (XMLStreamException ex) {
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XMLStreamException trying to unmarshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
        } catch (XStreamException ex) {
            //For some reason messages appear to be getting eaten at this stage... very nasty when you try to troubleshoot.
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XStreamException trying to unmarshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not unmarshal message of type "+typeId, ex);
        }
    }
View Full Code Here

        return call(exchange, routingKey, params, bodyObj);
      }
    }

    private MessageProperties createProperties(Map<String, Object> headers) {
      MessageProperties msgProps = new MessageProperties();
      for (Map.Entry<String, Object> entry : headers.entrySet()) {
        String key = entry.getKey();
        String value = null != entry.getValue() ? entry.getValue().toString() : null;
        if ("contentType".equals(key)) {
          msgProps.setContentType(value);
        } else if ("correlationId".equals(key)) {
          msgProps.setCorrelationId(value.getBytes());
        } else if ("replyTo".equals(key)) {
          msgProps.setReplyTo(value);
        } else if ("contentEncoding".equals(key)) {
          msgProps.setContentEncoding(value);
        } else {
          msgProps.setHeader(key, value);
        }
      }
      return msgProps;
    }
View Full Code Here

      }
      return msgProps;
    }

    private Message createMessage(Map<String, Object> params, Object bodyObj) throws IOException {
      MessageProperties msgProps = createProperties(params);
      if (bodyObj instanceof Closure) {
        // If it's a Closure, invoke it to get the value
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        Closure cl = (Closure) bodyObj;
        Object returnFromBodyClosure = cl.call(new Object[]{out});
View Full Code Here

   * @param amqpTemplate  the template, not null
   * @param exchange  the exchange, not null
   * @param routingKey  the routing key, not null
   */
  public AmqpByteArrayMessageSender(AmqpTemplate amqpTemplate, String exchange, String routingKey) {
    this(amqpTemplate, exchange, routingKey, new MessageProperties());
  }
View Full Code Here

   * @param request  the request, not null
   * @param responseReceiver  the receiver, not null
   * @return the message, not null
   */
  private Message createMessage(final byte[] request, final ByteArrayMessageReceiver responseReceiver) {
    MessageProperties properties = new MessageProperties();
    Address replyTo = new Address(ExchangeTypes.DIRECT, getExchange(), getReplyToQueue());
    properties.setReplyToAddress(replyTo);
   
    final String correlationId = getReplyToQueue() + "-" + _correlationIdGenerator.getAndIncrement();
    byte[] correlationIdBytes = correlationId.getBytes(Charsets.UTF_8);
    properties.setCorrelationId(correlationIdBytes);
   
    Message message = new Message(request, properties);
   
    _correlationId2MessageReceiver.put(correlationId, responseReceiver);
   
View Full Code Here

    Advice retryInterceptor = fb.getObject();
    // add both advices
    container.setAdviceChain(new Advice[] {missingIdAdvice, retryInterceptor});
    container.start();

    MessageProperties messageProperties = new MessageProperties();
    messageProperties.setContentType("text/plain");
    messageProperties.setMessageId("foo");
    Message message = new Message("Hello, world!".getBytes(), messageProperties);
    template.send("retry.test.exchange", "retry.test.binding", message);
    template.send("retry.test.exchange", "retry.test.binding", message);
    assertTrue(latch.await(10, TimeUnit.SECONDS));
    Thread.sleep(2000);
View Full Code Here

  /**
   * Create a text message with the relevant content type.
   */
  public static Message createTextMessage(String body) {
    return createTextMessage(body, new MessageProperties());
  }
View Full Code Here

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    endpoint.setupListenerContainer(container);
    MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();

    MessageProperties properties = new MessageProperties();
    properties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
    Message amqpMessage = new Message("Hello".getBytes(), properties);

    try {
      listener.onMessage(amqpMessage, mock(Channel.class));
    }
View Full Code Here

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    endpoint.setupListenerContainer(container);
    MessagingMessageListenerAdapter listener = (MessagingMessageListenerAdapter) container.getMessageListener();

    MessageProperties properties = new MessageProperties();
    properties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
    Message amqpMessage = new Message("failValidation".getBytes(), properties);

    listener.onMessage(amqpMessage, mock(Channel.class));
  }
View Full Code Here

TOP

Related Classes of org.springframework.amqp.core.MessageProperties

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.