Package org.springframework.amqp.core

Examples of org.springframework.amqp.core.Message


    public Message toAMQPMessage(MessageConverter msgConverter) {
        MessageProperties properties = new MessageProperties();
        properties.setMessageId(this.getMessageId());
       
        Message amqpMessage;
        if(this.getBody() != null) {
            amqpMessage = msgConverter.toMessage(this.getBody(), properties);
           
            if(LOG.isTraceEnabled()) {
                String asText = new String(amqpMessage.getBody());
                LOG.trace("Translating To AMQP Message: "+asText);
            }
        } else {
            amqpMessage = new Message(new byte[]{}, properties);
        }
       
        return new HeadersPostProcessor(this).postProcessMessage(amqpMessage);
    }
View Full Code Here


           
            String msgContentType = this.contentType == null ? DEFAULT_CONTENT_TYPE : this.contentType;
            messageProperties.setContentType(msgContentType);
            messageProperties.setContentEncoding(this.encoding);
            messageProperties.setContentLength(body.length);
            return new Message(body, messageProperties);
        } catch (UnsupportedEncodingException ex) {
            LOG.error("Cannot encode strings as {}", this.encoding, ex);
            throw new MessageConversionException("Cannot encode strings as "+this.encoding, ex);
        }
    }
View Full Code Here

            String routingKey = routingKeyHeader != null ? routingKeyHeader : endpoint.routingKey;

            try {
                if(exchange.getPattern().isOutCapable()) {
                    LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId());
                    Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(endpoint.exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
                    SpringAMQPMessage camelResponse = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpResponse);
                    exchange.setOut(camelResponse);
                } else {
                    LOG.debug("Synchronous send for exchange {}", exchange.getExchangeId());
                    endpoint.getAmqpTemplate().send(endpoint.exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
View Full Code Here

    public Message toAMQPMessage(MessageConverter msgConverter) {
        MessageProperties properties = new MessageProperties();
        properties.setMessageId(this.getMessageId());
       
        Message amqpMessage;
        if(this.getBody() != null) {
            amqpMessage = msgConverter.toMessage(this.getBody(), properties);
           
            if(LOG.isTraceEnabled()) {
                String asText = new String(amqpMessage.getBody());
                LOG.trace("Translating To AMQP Message: "+asText);
            }
        } else {
            amqpMessage = new Message(new byte[]{}, properties);
        }
       
        return new HeadersPostProcessor(this).postProcessMessage(amqpMessage);
    }
View Full Code Here

           
            messageProperties.setContentType(MessageProperties.CONTENT_TYPE_JSON);
            messageProperties.setContentEncoding(this.encoding);
            messageProperties.setContentLength(body.length);
            classMapper.fromClass(object.getClass(), messageProperties);
            return new Message(body, messageProperties);
        } catch (XMLStreamException ex) {
            String typeId = (String) messageProperties.getHeaders().get(DefaultClassMapper.DEFAULT_CLASSID_FIELD_NAME);
            LOG.error("XMLStreamException trying to marshal message of type {}", typeId, ex);
            throw new MessageConversionException("Could not marshal message of type "+typeId, ex);
        } catch (XStreamException ex) {
View Full Code Here

      }
      return call(exchange, routingKey, params, bodyObj);
    }

    public Object call(String exchange, String routingKey, Map<String, Object> headers, Object bodyObj) throws IOException {
      Message msg = createMessage(headers, bodyObj);
      if (null == exchange && null != currentExchange) {
        exchange = currentExchange.getName();
      }
      if (null == routingKey && null != currentRoutingKey) {
        routingKey = currentRoutingKey;
View Full Code Here

        Closure cl = (Closure) bodyObj;
        Object returnFromBodyClosure = cl.call(new Object[]{out});
        if (returnFromBodyClosure instanceof Message) {
          return (Message) returnFromBodyClosure;
        } else if (returnFromBodyClosure instanceof String) {
          return new Message(((String) returnFromBodyClosure).getBytes(), msgProps);
        } else {
          out.flush();
          return new Message(out.toByteArray(), msgProps);
        }
      } else if (bodyObj instanceof String || bodyObj instanceof GString) {
        // If it's sort of a String, toString() it
        return new Message(bodyObj.toString().getBytes(), msgProps);
      } else if (bodyObj instanceof byte[]) {
        // If it's raw bytes, don't do anything
        return new Message((byte[]) bodyObj, msgProps);
      } else {
        // Otherwise, write the object out using JDK serialization
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        ObjectOutputStream oout = new ObjectOutputStream(bout);
        oout.writeObject(bodyObj);
        oout.flush();
        oout.close();
        bout.flush();

        return new Message(bout.toByteArray(), msgProps);
      }
    }
View Full Code Here

  }

  //-------------------------------------------------------------------------
  @Override
  public void send(final byte[] message) {
    Message amqpMsg = new Message(message, getMessageProperties());
    getAmqpTemplate().send(getExchange(), getRoutingKey(), amqpMsg);
  }
View Full Code Here

   
    final String correlationId = getReplyToQueue() + "-" + _correlationIdGenerator.getAndIncrement();
    byte[] correlationIdBytes = correlationId.getBytes(Charsets.UTF_8);
    properties.setCorrelationId(correlationIdBytes);
   
    Message message = new Message(request, properties);
   
    _correlationId2MessageReceiver.put(correlationId, responseReceiver);
   
    // Make sure the map stays clean if no response is received before timeout occurs.
    // It would be nice if AmqpTemplate had a receive() method with a timeout parameter.
View Full Code Here

            String exchangeName = exchangeNameHeader != null ? exchangeNameHeader : endpoint.exchangeName;

            try {
                if(exchange.getPattern().isOutCapable()) {
                    LOG.debug("Synchronous send and request for exchange {}", exchange.getExchangeId());
                    Message amqpResponse = endpoint.getAmqpTemplate().sendAndReceive(exchangeName, routingKey, inMessage.toAMQPMessage(msgConverter));
                    SpringAMQPMessage camelResponse = SpringAMQPMessage.fromAMQPMessage(msgConverter, amqpResponse);

                    Boolean isExceptionCaught = camelResponse != null && (Boolean)camelResponse.getHeader(SpringAMQPMessage.IS_EXCEPTION_CAUGHT, Boolean.FALSE);
                    if (isExceptionCaught != null && isExceptionCaught.equals(Boolean.TRUE)) {
                        Object caughtObject = camelResponse.getBody();
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.