Esempio n. 1
0
  private void sendMessages(int messageCount, boolean persistent) throws AMQException {
    for (int i = 0; i < messageCount; i++) {
      IncomingMessage currentMessage = message(false, persistent);
      ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>();
      qs.add(getQueue());
      currentMessage.enqueue(qs);

      // route header
      MessageMetaData mmd = currentMessage.headersReceived();
      currentMessage.setStoredMessage(getMessageStore().addMessage(mmd));

      // Add the body so we have somthing to test later
      currentMessage.addContentBodyFrame(
          getSession()
              .getMethodRegistry()
              .getProtocolVersionMethodConverter()
              .convertToContentChunk(
                  new ContentBody(ByteBuffer.allocate((int) MESSAGE_SIZE), MESSAGE_SIZE)));

      AMQMessage m = new AMQMessage(currentMessage.getStoredMessage());
      for (BaseQueue q : currentMessage.getDestinationQueues()) {
        q.enqueue(m);
      }
    }
  }
 /**
  * Routes content through exchanges, delivering it to 1 or more queues.
  *
  * @param payload
  * @throws AMQException if something goes wrong delivering data
  */
 public void routeContent(IncomingMessage payload) throws AMQException {
   final AMQShortString exchange = payload.getExchange();
   final Exchange exch = getExchange(exchange);
   // there is a small window of opportunity for the exchange to be deleted in between
   // the BasicPublish being received (where the exchange is validated) and the final
   // content body being received (which triggers this method)
   // TODO: check where the exchange is validated
   if (exch == null) {
     throw new AMQException("Exchange '" + exchange + "' does not exist");
   }
   payload.enqueue(exch.route(payload));
 }
Esempio n. 3
0
  public void testExceptions() throws Exception {
    try {
      _queueMBean.viewMessages(0L, 3L);
      fail();
    } catch (JMException ex) {

    }

    try {
      _queueMBean.viewMessages(2L, 1L);
      fail();
    } catch (JMException ex) {

    }

    try {
      _queueMBean.viewMessages(-1L, 1L);
      fail();
    } catch (JMException ex) {

    }

    try {
      long end = Integer.MAX_VALUE;
      end += 2;
      _queueMBean.viewMessages(1L, end);
      fail("Expected Exception due to oversized(> 2^31) message range");
    } catch (JMException ex) {

    }

    IncomingMessage msg = message(false, false);
    getQueue().clearQueue();
    ArrayList<AMQQueue> qs = new ArrayList<AMQQueue>();
    qs.add(getQueue());
    msg.enqueue(qs);
    MessageMetaData mmd = msg.headersReceived();
    msg.setStoredMessage(getMessageStore().addMessage(mmd));
    long id = msg.getMessageNumber();

    msg.addContentBodyFrame(
        new ContentChunk() {
          ByteBuffer _data = ByteBuffer.allocate((int) MESSAGE_SIZE);

          {
            _data.limit((int) MESSAGE_SIZE);
          }

          public int getSize() {
            return (int) MESSAGE_SIZE;
          }

          public ByteBuffer getData() {
            return _data;
          }

          public void reduceToFit() {}
        });

    AMQMessage m = new AMQMessage(msg.getStoredMessage());
    for (BaseQueue q : msg.getDestinationQueues()) {
      q.enqueue(m);
    }
    //        _queue.process(_storeContext, new QueueEntry(_queue, msg), false);
    _queueMBean.viewMessageContent(id);
    try {
      _queueMBean.viewMessageContent(id + 1);
      fail();
    } catch (JMException ex) {

    }
  }
Esempio n. 4
0
 public void route() {
   enqueue(_exchange.route(this));
 }