Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.MessageProperties


    assertEquals("FOO", rabbitTemplate.convertSendAndReceive("test.simple", "foo"));
  }

  @Test
  public void endpointWithHeader() {
    MessageProperties properties = new MessageProperties();
    properties.setHeader("prefix", "prefix-");
    Message request = MessageTestUtils.createTextMessage("foo", properties);
    Message reply = rabbitTemplate.sendAndReceive("test.header", request);
    assertEquals("prefix-FOO", MessageTestUtils.extractText(reply));
  }
View Full Code Here


    assertEquals("prefix-FOO", MessageTestUtils.extractText(reply));
  }

  @Test
  public void endpointWithMessage() {
    MessageProperties properties = new MessageProperties();
    properties.setHeader("prefix", "prefix-");
    Message request = MessageTestUtils.createTextMessage("foo", properties);
    Message reply = rabbitTemplate.sendAndReceive("test.message", request);
    assertEquals("prefix-FOO", MessageTestUtils.extractText(reply));
  }
View Full Code Here

    assertEquals("prefix-FOO", MessageTestUtils.extractText(reply));
  }

  @Test
  public void endpointWithComplexReply() {
    MessageProperties properties = new MessageProperties();
    properties.setHeader("foo", "fooValue");
    Message request = MessageTestUtils.createTextMessage("content", properties);
    Message reply = rabbitTemplate.sendAndReceive("test.reply", request);
    assertEquals("Wrong reply", "content", MessageTestUtils.extractText(reply));
    assertEquals("Wrong foo header", "fooValue", reply.getMessageProperties().getHeaders().get("foo"));
    assertEquals("Wrong bar header", "barValue", reply.getMessageProperties().getHeaders().get("bar"));
View Full Code Here

    log.warn("This is a WARN message with properties");
    log.error("This is an ERROR message with properties", new RuntimeException("Test exception"));
    MDC.remove(propertyName);

    assertTrue(testListener.getLatch().await(5, TimeUnit.SECONDS));
    MessageProperties messageProperties = testListener.getMessageProperties();
    assertNotNull(messageProperties);
    assertNotNull(messageProperties.getHeaders().get(propertyName));
    assertEquals(propertyValue, messageProperties.getHeaders().get(propertyName));
    assertEquals("bar", messageProperties.getHeaders().get("foo"));
  }
View Full Code Here

    connectionFactory.setUsername("guest");
    connectionFactory.setPassword("guest");
    assertNotNull(connectionFactory);

    MessageConverter messageConverter = new SimpleMessageConverter();
    MessageProperties  messageProperties = new MessageProperties();
    messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);

    SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
    container.setConnectionFactory(connectionFactory);
    container.setQueueNames("foo");
    container.setPrefetchCount(1000);
View Full Code Here

  private MessageListenerAdapter adapter;

  @Before
  public void init() {
    SimpleService.called = false;
    messageProperties = new MessageProperties();
    messageProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
    adapter = new MessageListenerAdapter() {
      @Override
      protected void handleListenerException(Throwable ex) {
        if (ex instanceof RuntimeException) {
View Full Code Here

*/
public class DefaultMessagePropertiesConverter implements MessagePropertiesConverter {

  public MessageProperties toMessageProperties(final BasicProperties source, final Envelope envelope,
      final String charset) {
    MessageProperties target = new MessageProperties();
    Map<String, Object> headers = source.getHeaders();
    if (!CollectionUtils.isEmpty(headers)) {
      for (Map.Entry<String, Object> entry : headers.entrySet()) {
        target.setHeader(entry.getKey(), convertLongStringIfNecessary(entry.getValue(), charset));
      }
    }
    target.setTimestamp(source.getTimestamp());
    target.setMessageId(source.getMessageId());
    target.setUserId(source.getUserId());
    target.setAppId(source.getAppId());
    target.setClusterId(source.getClusterId());
    target.setType(source.getType());
    Integer deliverMode = source.getDeliveryMode();
    if (deliverMode != null) {
      target.setDeliveryMode(MessageDeliveryMode.fromInt(deliverMode));
    }
    target.setExpiration(source.getExpiration());
    target.setPriority(source.getPriority());
    target.setContentType(source.getContentType());
    target.setContentEncoding(source.getContentEncoding());
    String correlationId = source.getCorrelationId();
    if (correlationId != null) {
      try {
        target.setCorrelationId(source.getCorrelationId().getBytes(charset));
      } catch (UnsupportedEncodingException ex) {
        throw new AmqpUnsupportedEncodingException(ex);
      }
    }
    String replyTo = source.getReplyTo();
    if (replyTo != null) {
      target.setReplyTo(replyTo);
    }
    if (envelope != null) {
      target.setReceivedExchange(envelope.getExchange());
      target.setReceivedRoutingKey(envelope.getRoutingKey());
      target.setRedelivered(envelope.isRedeliver());
      target.setDeliveryTag(envelope.getDeliveryTag());
    }
    return target;
  }
View Full Code Here

    return createTextMessage("Hello");
  }


  private org.springframework.amqp.core.Message createAmqpTextMessage(String payload) {
    MessageProperties properties = new MessageProperties();
    properties.setHeader("foo", "bar");
    return MessageTestUtils.createTextMessage(payload, properties);

  }
View Full Code Here

  private static void sendMessages(RabbitTemplate template,
      final String exchange, final String routingKey, int numMessages) {
    for (int i = 1; i <= numMessages; i++) {
      byte[] bytes = "testing".getBytes();
      MessageProperties properties = new MessageProperties();
      properties.getHeaders().put("float", new Float(3.14));
      Message message = new Message(bytes, properties);
      template.send(exchange, routingKey, message);
      System.out.println("sending " + i + "...");
    }
  }
View Full Code Here

      return null;
    }
    byte[] body = delivery.getBody();
    Envelope envelope = delivery.getEnvelope();

    MessageProperties messageProperties = this.messagePropertiesConverter.toMessageProperties(
        delivery.getProperties(), envelope, "UTF-8");
    messageProperties.setMessageCount(0);
    Message message = new Message(body, messageProperties);
    if (logger.isDebugEnabled()) {
      logger.debug("Received message: " + message);
    }
    deliveryTags.add(messageProperties.getDeliveryTag());
    return message;
  }
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.