Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Address


            } catch(Throwable t) {
                exchange.setException(t);
            }
           
            //Send a reply if one was requested
            Address replyToAddress = amqpMessage.getMessageProperties().getReplyToAddress();
            if(replyToAddress != null) {
                org.apache.camel.Message outMessage = exchange.getOut();
                SpringAMQPMessage replyMessage = new SpringAMQPMessage(outMessage);

                // Camel exchange will contain a non-null exception if an unhandled exception has occurred,
                // such as when using the DefaultErrorHandler with default configuration, or when
                // using the DeadLetterChannel error handler with an OnException handled=false override.
                // Exchange will not contain an exception (via getException()) if the exception has been handled,
                // such as when using the DeadLetterChannel error handler with default configuration, but
                // the Exchange property EXCEPTION_CAUGHT will contain the handled exception.
                if (exchange.getException() != null) {
                    replyMessage.setHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT, true);
                    replyMessage.setBody(exchange.getException());
                } else if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
                    replyMessage.setHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT, true);
                    replyMessage.setBody(exchange.getProperty(Exchange.EXCEPTION_CAUGHT));
                }

                exchange.setOut(replyMessage); //Swap out the outbound message

                try {
                    endpoint.getAmqpTemplate().send(replyToAddress.getExchangeName(), replyToAddress.getRoutingKey(), replyMessage.toAMQPMessage(msgConverter));
                } catch(AmqpConnectException e) {
                    LOG.error("AMQP Connection error, marking this connection as failed");
                    onClose(null);
                }
            }
View Full Code Here


  }
 
  public void send(TradeRequest tradeRequest) {
    getRabbitTemplate().convertAndSend(tradeRequest, new MessagePostProcessor() {
      public Message postProcessMessage(Message message) throws AmqpException {
        message.getMessageProperties().setReplyTo(new Address(defaultReplyTo));
        try {
          message.getMessageProperties().setCorrelationId(UUID.randomUUID().toString().getBytes("UTF-8"));
        }
        catch (UnsupportedEncodingException e) {
          throw new AmqpException(e);
View Full Code Here

      workMessage.setStart(i);
      workMessage.setNrOfElements(nrOfElements);
     
      rabbitTemplate.convertAndSend(workMessage, new MessagePostProcessor() {       
        public Message postProcessMessage(Message message) throws AmqpException {
          message.getMessageProperties().setReplyToAddress(new Address("direct://piExchange/" + QueueNames.RESULT_QUEUE_NAME));
          return message;
        }
      });
    }
   
View Full Code Here

   * @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);
View Full Code Here

            } catch(Throwable t) {
                exchange.setException(t);
            }
           
            //Send a reply if one was requested
            Address replyToAddress = amqpMessage.getMessageProperties().getReplyToAddress();
            if(replyToAddress != null && endpoint.isAutoReply()) {
                org.apache.camel.Message outMessage = exchange.getOut();
                SpringAMQPMessage replyMessage = new SpringAMQPMessage(outMessage);

                // Camel exchange will contain a non-null exception if an unhandled exception has occurred,
                // such as when using the DefaultErrorHandler with default configuration, or when
                // using the DeadLetterChannel error handler with an OnException handled=false override.
                // Exchange will not contain an exception (via getException()) if the exception has been handled,
                // such as when using the DeadLetterChannel error handler with default configuration, but
                // the Exchange property EXCEPTION_CAUGHT will contain the handled exception.
                if (exchange.getException() != null) {
                    replyMessage.setHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT, true);
                    replyMessage.setBody(exchange.getException());
                } else if (exchange.getProperty(Exchange.EXCEPTION_CAUGHT) != null) {
                    replyMessage.setHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT, true);
                    replyMessage.setBody(exchange.getProperty(Exchange.EXCEPTION_CAUGHT));
                }

                exchange.setOut(replyMessage); //Swap out the outbound message

                try {
                    endpoint.getAmqpTemplate().send(replyToAddress.getExchangeName(), replyToAddress.getRoutingKey(), replyMessage.toAMQPMessage(msgConverter));
                } catch(AmqpConnectException e) {
                    LOG.error("AMQP Connection error, marking this connection as failed");
                    onClose(null);
                }
            }
View Full Code Here

  @Test
  public void processAndReplyUsingReplyTo() throws Exception {
    MessagingMessageListenerAdapter listener = createDefaultInstance(String.class);
    listener.setMandatoryPublish(true);
    String body = "echo text";
    Address replyTo = new Address("replyToQueue", "myRouting");

    MessageProperties properties = new MessageProperties();
    properties.setReplyToAddress(replyTo);
    org.springframework.amqp.core.Message message = createTextMessage(body, properties);
View Full Code Here

      @Override
      public Message handle(Message message) {
        MessageProperties messageProperties = new MessageProperties();
        messageProperties.setContentType(message.getMessageProperties().getContentType());
        messageProperties.setHeader("testReplyTo", new Address("", ROUTE));
        return new Message(message.getBody(), messageProperties);
      }

    }, new ReplyToAddressCallback<Message>() {
View Full Code Here

        "Could not create message listener - MessageHandlerMethodFactory not set");
    MessagingMessageListenerAdapter messageListener = createMessageListenerInstance();
    InvocableHandlerMethod invocableHandlerMethod =
        this.messageHandlerMethodFactory.createInvocableHandlerMethod(getBean(), getMethod());
    messageListener.setHandlerMethod(invocableHandlerMethod);
    Address replyToAddress = getDefaultReplyToAddress();
    if (replyToAddress != null) {
      messageListener.setResponseExchange(replyToAddress.getExchangeName());
      messageListener.setResponseRoutingKey(replyToAddress.getRoutingKey());
    }
    MessageConverter messageConverter = container.getMessageConverter();
    if (messageConverter != null) {
      messageListener.setMessageConverter(messageConverter);
    }
View Full Code Here

      String[] destinations = ann.value();
      if (destinations.length > 1) {
        throw new IllegalStateException("Invalid @" + SendTo.class.getSimpleName() + " annotation on '"
            + getMethod() + "' one destination must be set (got " + Arrays.toString(destinations) + ")");
      }
      return destinations.length == 1 ? new Address(destinations[0]) : new Address(null);
    }
    return null;
  }
View Full Code Here

        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) {
        throw new ReplyFailureException("Failed to send reply with payload '" + result + "'", ex);
      }
View Full Code Here

TOP

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

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.