Example usage for com.rabbitmq.client BasicProperties getType

List of usage examples for com.rabbitmq.client BasicProperties getType

Introduction

In this page you can find the example usage for com.rabbitmq.client BasicProperties getType.

Prototype

public abstract String getType();

Source Link

Document

Retrieve the value in the type field.

Usage

From source file:org.mule.transport.amqp.AmqpMuleMessageFactoryTestCase.java

License:Open Source License

public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) {
    assertEquals(amqpMessage.getConsumerTag(),
            muleMessage.getProperty(AmqpConstants.CONSUMER_TAG, PropertyScope.INBOUND));

    final Envelope envelope = amqpMessage.getEnvelope();
    assertEquals(envelope.getDeliveryTag(),
            muleMessage.getProperty(AmqpConstants.DELIVERY_TAG, PropertyScope.INBOUND));
    assertEquals(envelope.isRedeliver(),
            muleMessage.getProperty(AmqpConstants.REDELIVER, PropertyScope.INBOUND));
    assertEquals(envelope.getExchange(),
            muleMessage.getProperty(AmqpConstants.EXCHANGE, PropertyScope.INBOUND));
    assertEquals(envelope.getRoutingKey(),
            muleMessage.getProperty(AmqpConstants.ROUTING_KEY, PropertyScope.INBOUND));

    final BasicProperties amqpProperties = amqpMessage.getProperties();
    assertEquals(amqpProperties.getAppId(),
            muleMessage.getProperty(AmqpConstants.APP_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentEncoding(),
            muleMessage.getProperty(AmqpConstants.CONTENT_ENCODING, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentType(),
            muleMessage.getProperty(AmqpConstants.CONTENT_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(),
            muleMessage.getProperty(AmqpConstants.CORRELATION_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId());
    assertEquals(amqpProperties.getDeliveryMode(),
            muleMessage.getProperty(AmqpConstants.DELIVERY_MODE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getExpiration(),
            muleMessage.getProperty(AmqpConstants.EXPIRATION, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(),
            muleMessage.getProperty(AmqpConstants.MESSAGE_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId());
    assertEquals(amqpProperties.getPriority(),
            muleMessage.getProperty(AmqpConstants.PRIORITY, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(),
            muleMessage.getProperty(AmqpConstants.REPLY_TO, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo());
    assertEquals(amqpProperties.getTimestamp(),
            muleMessage.getProperty(AmqpConstants.TIMESTAMP, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getType(), muleMessage.getProperty(AmqpConstants.TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getUserId(),
            muleMessage.getProperty(AmqpConstants.USER_ID, PropertyScope.INBOUND));

    for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) {
        assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND));
    }/* w w w .  j ava 2 s.co m*/
}

From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactory.java

License:Open Source License

private void addBasicProperties(final BasicProperties amqpProperties, final DefaultMuleMessage muleMessage,
        final Map<String, Object> messageProperties) {
    if (amqpProperties == null)
        return;/*from  www  .  ja v  a2s . co m*/

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_APP_ID, amqpProperties.getAppId(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, amqpProperties.getContentEncoding(),
            messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, amqpProperties.getContentType(),
            messageProperties);

    final String correlationId = amqpProperties.getCorrelationId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, correlationId, messageProperties);
    putIfNonNull(MuleProperties.MULE_CORRELATION_ID_PROPERTY, correlationId, messageProperties);
    muleMessage.setCorrelationId(correlationId);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, amqpProperties.getDeliveryMode(),
            messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, amqpProperties.getExpiration(), messageProperties);

    final String messageId = amqpProperties.getMessageId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, messageId, messageProperties);
    putIfNonNull(MuleProperties.MULE_MESSAGE_ID_PROPERTY, messageId, messageProperties);
    muleMessage.setUniqueId(messageId == null ? UUID.getUUID() : messageId);

    final String clusterId = amqpProperties.getClusterId();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, clusterId, messageProperties);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, amqpProperties.getPriority(), messageProperties);

    final String replyTo = amqpProperties.getReplyTo();
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, replyTo, messageProperties);
    muleMessage.setReplyTo(replyTo);

    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, amqpProperties.getTimestamp(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_TYPE, amqpProperties.getType(), messageProperties);
    putIfNonNull(AmqpConnector.MESSAGE_PROPERTY_USER_ID, amqpProperties.getUserId(), messageProperties);
}

From source file:org.mule.transport.amqp.internal.domain.AmqpMuleMessageFactoryTestCase.java

License:Open Source License

public static void checkInboundProperties(final AmqpMessage amqpMessage, final MuleMessage muleMessage) {
    assertEquals(amqpMessage.getConsumerTag(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONSUMER_TAG, PropertyScope.INBOUND));

    final Envelope envelope = amqpMessage.getEnvelope();
    assertEquals(envelope.getDeliveryTag(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_TAG, PropertyScope.INBOUND));
    assertEquals(envelope.isRedeliver(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REDELIVER, PropertyScope.INBOUND));
    assertEquals(envelope.getExchange(),
            muleMessage.getProperty(AmqpConnector.EXCHANGE, PropertyScope.INBOUND));
    assertEquals(envelope.getRoutingKey(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_ROUTING_KEY, PropertyScope.INBOUND));

    final BasicProperties amqpProperties = amqpMessage.getProperties();
    assertEquals(amqpProperties.getAppId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_APP_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentEncoding(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_ENCODING, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getContentType(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CONTENT_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getClusterId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CLUSTER_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_CORRELATION_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getCorrelationId(), muleMessage.getCorrelationId());
    assertEquals(amqpProperties.getDeliveryMode(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_DELIVERY_MODE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getExpiration(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_EXPIRATION, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_MESSAGE_ID, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getMessageId(), muleMessage.getUniqueId());
    assertEquals(amqpProperties.getPriority(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_PRIORITY, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_REPLY_TO, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getReplyTo(), muleMessage.getReplyTo());
    assertEquals(amqpProperties.getTimestamp(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TIMESTAMP, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getType(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_TYPE, PropertyScope.INBOUND));
    assertEquals(amqpProperties.getUserId(),
            muleMessage.getProperty(AmqpConnector.MESSAGE_PROPERTY_USER_ID, PropertyScope.INBOUND));

    for (final Entry<String, Object> header : amqpProperties.getHeaders().entrySet()) {
        assertEquals(header.getValue(), muleMessage.getProperty(header.getKey(), PropertyScope.INBOUND));
    }//from w w  w  .  j  a va  2  s  . c  o m
}

From source file:org.objectweb.proactive.extensions.amqp.federation.AMQPFederationRemoteObjectServer.java

License:Open Source License

@Override
protected byte[] handleMessage(Channel channel, BasicProperties props, byte[] body) throws IOException {
    if (DELETE_QUEUE_MESSAGE_TYPE.equals(props.getType())) {
        channel.queueDelete(queueName);//from   w  w  w  .j  a va 2 s.  c  o m
        return null;
    } else if (PING_MESSAGE_TYPE.equals(props.getType())) {
        return new byte[] {};
    } else {
        return null;
    }
}

From source file:org.springframework.amqp.rabbit.support.DefaultMessagePropertiesConverter.java

License:Apache License

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()) {
            Object value = entry.getValue();
            if (value instanceof LongString) {
                value = this.convertLongString((LongString) value, charset);
            }//from   ww  w .ja v a  2  s  . c o m
            target.setHeader(entry.getKey(), value);
        }
    }
    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;
}

From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java

License:Apache License

public static MessageProperties createMessageProperties(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(), entry.getValue());
        }//from  w  ww  .ja v  a  2 s. co  m
    }
    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(new Address(replyTo));
    }
    if (envelope != null) {
        target.setReceivedExchange(envelope.getExchange());
        target.setReceivedRoutingKey(envelope.getRoutingKey());
        target.setRedelivered(envelope.isRedeliver());
        target.setDeliveryTag(envelope.getDeliveryTag());
    }
    // TODO: what about messageCount?
    return target;
}

From source file:pl.nask.hsn2.bus.rabbitmq.endpoint.RbtDefaultConsumer.java

License:Open Source License

@Override
public final void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body)
        throws IOException {

    super.handleDelivery(consumerTag, envelope, properties, body);

    Message message = new Message(properties.getType(), body, properties.getCorrelationId(),
            new RbtDestination(RABBITMQ_DEFAULT_EXCHANGE_NAME, properties.getReplyTo()));

    message.setDestination(new RbtDestination(RABBITMQ_DEFAULT_EXCHANGE_NAME, envelope.getRoutingKey()));

    message.setContentType(properties.getContentType());

    // take retries count
    try {//  ww w . j  a v a  2s. com
        if (properties.getHeaders() != null) {
            Object xretriesObject = properties.getHeaders().get("x-retries");
            if (xretriesObject != null) {
                int xretries = 0;
                if (xretriesObject instanceof Integer) {
                    xretries = (Integer) xretriesObject;
                } else if (xretriesObject instanceof String) {
                    xretries = Integer.parseInt((String) xretriesObject);
                } else {
                    LOGGER.error("Unknown object type of x-retries property.");
                }
                message.setRetries(xretries);
            }
        }
    } catch (NumberFormatException ex) {
        // not important
    }

    try {
        responseHandler.handleMessage(message);
        if (!autoack) {
            getChannel().basicAck(envelope.getDeliveryTag(), false);
        }
    } catch (ConsumeHandlerException ex) {
        if (!autoack) {
            getChannel().basicReject(envelope.getDeliveryTag(), true);
        }
        // nothing can do :(
    } catch (Throwable t) {
        if (!autoack) {
            getChannel().basicReject(envelope.getDeliveryTag(), true);
        }
        LOGGER.error("Error handling message.", t);
    }
}

From source file:pl.nask.hsn2.unicorn.connector.ConnectorImpl.java

License:Open Source License

public Response receive() throws ConnectionException {
    try {//from   w w w. j a  v  a 2 s .  com
        Delivery delivery = consumer.nextDelivery();
        BasicProperties properties = delivery.getProperties();
        return new Response(properties.getType(), properties.getContentType(), delivery.getBody());
    } catch (ShutdownSignalException e) {
        throw new ConnectionException("Receiving error!", e);
    } catch (InterruptedException e) {
        throw new ConnectionException("Receiving error!", e);
    }
}