Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Message


    }
    checkShutdown();
    if (this.missingQueues.size() > 0) {
      checkMissingQueues();
    }
    Message message = handle(queue.poll(timeout, TimeUnit.MILLISECONDS));
    if (message == null && cancelReceived.get()) {
      throw new ConsumerCancelledException();
    }
    return message;
  }
View Full Code Here


    if (channel != null) {
      if (logger.isDebugEnabled()) {
        logger.debug("Listener method returned result [" + result + "] - generating response message for it");
      }
      try {
        Message response = buildMessage(channel, result);
        postProcessResponse(request, response);
        Address replyTo = getReplyToAddress(request);
        sendResponse(channel, replyTo, response);
      }
      catch (Exception ex) {
View Full Code Here

    }
    retryInterceptor.setRetryOperations(retryTemplate);

    retryInterceptor.setNewItemIdentifier(new NewMethodArgumentsIdentifier() {
      public boolean isNew(Object[] args) {
        Message message = (Message) args[1];
        if (newMessageIdentifier == null) {
          return !message.getMessageProperties().isRedelivered();
        } else {
          return newMessageIdentifier.isNew(message);
        }
      }
    });

    final MessageRecoverer messageRecoverer = getMessageRecoverer();
    retryInterceptor.setRecoverer(new MethodInvocationRecoverer<Void>() {
      public Void recover(Object[] args, Throwable cause) {
        Message message = (Message) args[1];
        if (messageRecoverer == null) {
          logger.warn("Message dropped on recovery: " + message, cause);
        } else {
          messageRecoverer.recover(message, cause);
        }
        // This is actually a normal outcome. It means the recovery was successful, but we don't want to consume
        // any more messages until the acks and commits are sent for this (problematic) message...
        throw new ImmediateAcknowledgeAmqpException("Recovered message forces ack (if ack mode requires it): "
            + message, cause);
      }
    });

    retryInterceptor.setKeyGenerator(new MethodArgumentsKeyGenerator() {
      public Object getKey(Object[] args) {
        Message message = (Message) args[1];
        if (messageKeyGenerator == null) {
          String messageId = message.getMessageProperties().getMessageId();
          if (messageId == null) {
            throw new FatalListenerExecutionException(
                "Illegal null id in message. Failed to manage retry for message: " + message);
          }
          return messageId;
View Full Code Here

    convertAndSend(exchange, routingKey, message, messagePostProcessor, null);
  }

  public void convertAndSend(String exchange, String routingKey, final Object message,
      final MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws AmqpException {
    Message messageToSend = convertMessageIfNecessary(message);
    messageToSend = messagePostProcessor.postProcessMessage(messageToSend);
    send(exchange, routingKey, messageToSend, correlationData);
  }
View Full Code Here

    return receiveAndConvert(this.getRequiredQueue());
  }

  @Override
  public Object receiveAndConvert(String queueName) throws AmqpException {
    Message response = receive(queueName);
    if (response != null) {
      return getRequiredMessageConverter().fromMessage(response);
    }
    return null;
  }
View Full Code Here

          else if (channelTransacted) {
            // Not locally transacted but it is transacted so it could be synchronized with an external transaction
            ConnectionFactoryUtils.registerDeliveryTag(RabbitTemplate.this.getConnectionFactory(), channel, deliveryTag);
          }

          Message receiveMessage = RabbitTemplate.this.buildMessageFromResponse(response);

          Object receive = receiveMessage;
          if (!(ReceiveAndReplyMessageCallback.class.isAssignableFrom(callback.getClass()))) {
            receive = RabbitTemplate.this.getRequiredMessageConverter().fromMessage(receiveMessage);
          }

          S reply;
          try {
            reply = callback.handle((R) receive);
          }
          catch (ClassCastException e) {
            StackTraceElement[] trace = e.getStackTrace();
            if (trace[0].getMethodName().equals("handle") && trace[1].getFileName().equals("RabbitTemplate.java")) {
              throw new IllegalArgumentException("ReceiveAndReplyCallback '" + callback
                  + "' can't handle received object '" + receive + "'", e);
            }
            else {
              throw e;
            }
          }

          if (reply != null) {
            Address replyTo = replyToAddressCallback.getReplyToAddress(receiveMessage, reply);

            Message replyMessage = RabbitTemplate.this.convertMessageIfNecessary(reply);

            MessageProperties receiveMessageProperties = receiveMessage.getMessageProperties();
            MessageProperties replyMessageProperties = replyMessage.getMessageProperties();

            Object correlation = RabbitTemplate.this.correlationKey == null
                ? receiveMessageProperties.getCorrelationId()
                : receiveMessageProperties.getHeaders().get(RabbitTemplate.this.correlationKey);
View Full Code Here

  }

  @Override
  public Object convertSendAndReceive(final String exchange, final String routingKey, final Object message,
      final MessagePostProcessor messagePostProcessor) throws AmqpException {
    Message requestMessage = convertMessageIfNecessary(message);
    if (messagePostProcessor != null) {
      requestMessage = messagePostProcessor.postProcessMessage(requestMessage);
    }
    Message replyMessage = this.doSendAndReceive(exchange, routingKey, requestMessage);
    if (replyMessage == null) {
      return null;
    }
    return this.getRequiredMessageConverter().fromMessage(replyMessage);
  }
View Full Code Here

          @Override
          public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties,
                         byte[] body) throws IOException {
            MessageProperties messageProperties = messagePropertiesConverter.toMessageProperties(
                properties, envelope, encoding);
            Message reply = new Message(body, messageProperties);
            if (logger.isTraceEnabled()) {
              logger.trace("Message received " + reply);
            }
            try {
              replyHandoff.put(reply);
            }
            catch (InterruptedException e) {
              Thread.currentThread().interrupt();
            }
          }
        };
        channel.basicConsume(replyTo, true, consumerTag, true, true, null, consumer);
        doSend(channel, exchange, routingKey, message, null);
        Message reply = (replyTimeout < 0) ? replyHandoff.take() : replyHandoff.poll(replyTimeout,
            TimeUnit.MILLISECONDS);
        channel.basicCancel(consumerTag);
        return reply;
      }
    }, obtainTargetConnectionFactoryIfNecessary(this.sendConnectionFactorySelectorExpression, message));
View Full Code Here

        if (logger.isDebugEnabled()) {
          logger.debug("Sending message with tag " + messageTag);
        }
        doSend(channel, exchange, routingKey, message, null);
        LinkedBlockingQueue<Message> replyHandoff = pendingReply.getQueue();
        Message reply = (replyTimeout < 0) ? replyHandoff.take() : replyHandoff.poll(replyTimeout,
            TimeUnit.MILLISECONDS);
        RabbitTemplate.this.replyHolder.remove(messageTag);
        return reply;
      }
    }, obtainTargetConnectionFactoryIfNecessary(this.sendConnectionFactorySelectorExpression, message));
View Full Code Here

  private Message buildMessageFromResponse(GetResponse response) {
    MessageProperties messageProps = this.messagePropertiesConverter.toMessageProperties(
        response.getProps(), response.getEnvelope(), this.encoding);
    messageProps.setMessageCount(response.getMessageCount());
    return new Message(response.getBody(), messageProps);
  }
View Full Code Here

TOP

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

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.