Example usage for org.springframework.amqp AmqpException AmqpException

List of usage examples for org.springframework.amqp AmqpException AmqpException

Introduction

In this page you can find the example usage for org.springframework.amqp AmqpException AmqpException.

Prototype

public AmqpException(Throwable cause) 

Source Link

Usage

From source file:com.ushahidi.swiftriver.core.dropqueue.DropHandler.java

/**
 * Receive drops placed on the DROPLET_QUEUE by channel apps.
 * // ww  w  .j a va2  s .  c o  m
 * Caches the drop in the dropsMap for metadata updates and then publishes
 * the drop to the metadata exchange for metadata extraction to be
 * performed.
 * 
 * @param message
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonParseException
 */
public synchronized void onMessage(Message message, Channel channel)
        throws JsonParseException, JsonMappingException, IOException {

    RawDrop drop = objectMapper.readValue(new String(message.getBody()), RawDrop.class);

    final String correlationId = UUID.randomUUID().toString();
    final String replyTo = callbackQueue.getName();
    long deliveryTag = message.getMessageProperties().getDeliveryTag();

    dropsMap.put(correlationId, drop);
    DeliveryFrame deliveryFrame = new DeliveryFrame(deliveryTag, channel);
    deliveryFramesMap.put(correlationId, deliveryFrame);

    logger.debug("Sending drop with correlation ID {} to {}", correlationId, replyTo);
    amqpTemplate.convertAndSend(drop, new MessagePostProcessor() {
        public Message postProcessMessage(Message message) throws AmqpException {
            message.getMessageProperties().setReplyTo(replyTo);
            try {
                message.getMessageProperties().setCorrelationId(correlationId.getBytes("UTF-8"));
            } catch (UnsupportedEncodingException e) {
                throw new AmqpException(e);
            }
            return message;
        }
    });

    logger.debug("Drop sent for metadata extraction with correlation id '{}'", correlationId);
}

From source file:org.kurento.rabbitmq.RabbitTemplate.java

/**
 * Determine a reply-to Address for the given message.
 * <p>/*from  www .j a  v  a  2s .  c  om*/
 * The default implementation first checks the Rabbit Reply-To Address of
 * the supplied request; if that is not <code>null</code> it is returned; if
 * it is <code>null</code>, then the configured default Exchange and routing
 * key are used to construct a reply-to Address. If the exchange property is
 * also <code>null</code>, then an {@link AmqpException} is thrown.
 * 
 * @param request
 *            the original incoming Rabbit message
 * @return the reply-to Address (never <code>null</code>)
 * @throws AmqpException
 *             if no {@link Address} can be determined
 * @see org.springframework.amqp.core.Message#getMessageProperties()
 * @see org.springframework.amqp.core.MessageProperties#getReplyTo()
 */
private Address getReplyToAddress(Message request) throws AmqpException {
    Address replyTo = request.getMessageProperties().getReplyToAddress();
    if (replyTo == null) {
        if (this.exchange == null) {
            throw new AmqpException("Cannot determine ReplyTo message property value: "
                    + "Request message does not contain reply-to property, and no default Exchange was set.");
        }
        replyTo = new Address(null, this.exchange, this.routingKey);
    }
    return replyTo;
}

From source file:org.springframework.amqp.rabbit.connection.LocalizedQueueConnectionFactory.java

private ConnectionFactory determineConnectionFactory(String queue) {
    for (int i = 0; i < this.adminUris.length; i++) {
        String adminUri = this.adminUris[i];
        if (!adminUri.endsWith("/api/")) {
            adminUri += "/api/";
        }/*  ww  w.j  av  a2s . com*/
        try {
            Client client = createClient(adminUri, this.username, this.password);
            QueueInfo queueInfo = client.getQueue(this.vhost, queue);
            if (queueInfo != null) {
                String node = queueInfo.getNode();
                if (node != null) {
                    String uri = this.nodeToAddress.get(node);
                    if (uri != null) {
                        return nodeConnectionFactory(queue, node, uri);
                    }
                    if (this.logger.isDebugEnabled()) {
                        this.logger.debug("No match for node: " + node);
                    }
                }
            } else {
                throw new AmqpException("Admin returned null QueueInfo");
            }
        } catch (Exception e) {
            this.logger.warn("Failed to determine queue location for: " + queue + " at: " + adminUri + ": "
                    + e.getMessage());
        }
    }
    this.logger.warn("Failed to determine queue location for: " + queue + ", using default connection factory");
    return null;
}

From source file:org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.java

/**
 * Determine a reply-to Address for the given message.
 * <p>//from   w w w  .  j  av  a 2  s  . c o  m
 * The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not
 * <code>null</code> it is returned; if it is <code>null</code>, then the configured default response Exchange and
 * routing key are used to construct a reply-to Address. If the responseExchange property is also <code>null</code>,
 * then an {@link org.springframework.amqp.AmqpException} is thrown.
 * @param request the original incoming Rabbit message.
 * @param source the source data (e.g. {@code o.s.messaging.Message<?>}).
 * @param result the result.
 * @return the reply-to Address (never <code>null</code>)
 * @throws Exception if thrown by Rabbit API methods
 * @throws org.springframework.amqp.AmqpException if no {@link Address} can be determined
 * @see #setResponseAddress(String)
 * @see #setResponseRoutingKey(String)
 * @see org.springframework.amqp.core.Message#getMessageProperties()
 * @see org.springframework.amqp.core.MessageProperties#getReplyTo()
 */
protected Address getReplyToAddress(Message request, Object source, Object result) throws Exception {
    Address replyTo = request.getMessageProperties().getReplyToAddress();
    if (replyTo == null) {
        if (this.responseAddress == null && this.responseExchange != null) {
            this.responseAddress = new Address(this.responseExchange, this.responseRoutingKey);
        }
        if (result instanceof ResultHolder) {
            replyTo = evaluateReplyTo(request, source, result, ((ResultHolder) result).sendTo);
        } else if (this.responseExpression != null) {
            replyTo = evaluateReplyTo(request, source, result, this.responseExpression);
        } else if (this.responseAddress == null) {
            throw new AmqpException("Cannot determine ReplyTo message property value: "
                    + "Request message does not contain reply-to property, "
                    + "and no default response Exchange was set.");
        } else {
            replyTo = this.responseAddress;
        }
    }
    return replyTo;
}

From source file:org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter.java

/**
 * Determine a reply-to Address for the given message.
 * <p>//from w  w w  . j a va 2  s. c o m
 * The default implementation first checks the Rabbit Reply-To Address of the supplied request; if that is not
 * <code>null</code> it is returned; if it is <code>null</code>, then the configured default response Exchange and
 * routing key are used to construct a reply-to Address. If the responseExchange property is also <code>null</code>,
 * then an {@link AmqpException} is thrown.
 * @param request the original incoming Rabbit message
 * @return the reply-to Address (never <code>null</code>)
 * @throws Exception if thrown by Rabbit API methods
 * @throws AmqpException if no {@link Address} can be determined
 * @see #setResponseExchange(String)
 * @see #setResponseRoutingKey(String)
 * @see org.springframework.amqp.core.Message#getMessageProperties()
 * @see org.springframework.amqp.core.MessageProperties#getReplyTo()
 */
protected Address getReplyToAddress(Message request) throws Exception {
    Address replyTo = request.getMessageProperties().getReplyToAddress();
    if (replyTo == null) {
        if (this.responseExchange == null) {
            throw new AmqpException("Cannot determine ReplyTo message property value: "
                    + "Request message does not contain reply-to property, and no default response Exchange was set.");
        }
        replyTo = new Address(null, this.responseExchange, this.responseRoutingKey);
    }
    return replyTo;
}