コード例 #1
0
  public synchronized void handleLargeMessage(
      final ClientLargeMessageInternal clientLargeMessage, long largeMessageSize) throws Exception {
    if (closing) {
      // This is ok - we just ignore the message
      return;
    }

    // Flow control for the first packet, we will have others
    File largeMessageCache = null;

    if (session.isCacheLargeMessageClient()) {
      largeMessageCache =
          File.createTempFile(
              "tmp-large-message-" + clientLargeMessage.getMessageID() + "-", ".tmp");
      largeMessageCache.deleteOnExit();
    }

    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();

    currentLargeMessageController =
        new LargeMessageControllerImpl(this, largeMessageSize, callTimeout, largeMessageCache);

    if (clientLargeMessage.isCompressed()) {
      clientLargeMessage.setLargeMessageController(
          new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    } else {
      clientLargeMessage.setLargeMessageController(currentLargeMessageController);
    }

    handleRegularMessage(clientLargeMessage);
  }
コード例 #2
0
  /**
   * This method deals with messages arrived as regular message but its contents are compressed.
   * Such messages come from message senders who are configured to compress large messages, and if
   * some of the messages are compressed below the min-large-message-size limit, they are sent as
   * regular messages. <br>
   * However when decompressing the message, we are not sure how large the message could be.. for
   * that reason we fake a large message controller that will deal with the message as it was a
   * large message <br>
   * Say that you sent a 1G message full of spaces. That could be just bellow 100K compressed but
   * you wouldn't have enough memory to decompress it
   */
  private void handleCompressedMessage(final ClientMessageInternal clMessage) throws Exception {
    ClientLargeMessageImpl largeMessage = new ClientLargeMessageImpl();
    largeMessage.retrieveExistingData(clMessage);

    File largeMessageCache = null;

    if (session.isCacheLargeMessageClient()) {
      largeMessageCache =
          File.createTempFile("tmp-large-message-" + largeMessage.getMessageID() + "-", ".tmp");
      largeMessageCache.deleteOnExit();
    }

    ClientSessionFactory sf = session.getSessionFactory();
    ServerLocator locator = sf.getServerLocator();
    long callTimeout = locator.getCallTimeout();

    currentLargeMessageController =
        new LargeMessageControllerImpl(
            this, largeMessage.getLargeMessageSize(), callTimeout, largeMessageCache);
    currentLargeMessageController.setLocal(true);

    // sets the packet
    ActiveMQBuffer qbuff = clMessage.getBodyBuffer();
    int bytesToRead = qbuff.writerIndex() - qbuff.readerIndex();
    final byte[] body = qbuff.readBytes(bytesToRead).toByteBuffer().array();

    largeMessage.setLargeMessageController(
        new CompressedLargeMessageControllerImpl(currentLargeMessageController));
    currentLargeMessageController.addPacket(body, body.length, false);

    handleRegularMessage(largeMessage);
  }
コード例 #3
0
  @Test
  public void testLoadBalanceGroups() throws Exception {
    Assume.assumeFalse(
        "only makes sense withOUT auto-group",
        clientSessionFactory.getServerLocator().isAutoGroup());

    ClientProducer clientProducer = clientSession.createProducer(qName);
    ClientConsumer consumer1 = clientSession.createConsumer(qName);
    ClientConsumer consumer2 = clientSession.createConsumer(qName);
    ClientConsumer consumer3 = clientSession.createConsumer(qName);
    ClientConsumer[] consumers = new ClientConsumer[] {consumer1, consumer2, consumer3};
    int[] counts = new int[consumers.length];

    clientSession.start();
    try {
      // Add all messages for a particular group before moving onto the next
      for (int group = 0; group < 10; group++) {
        for (int messageId = 0; messageId < 3; messageId++) {
          ClientMessage message = clientSession.createMessage(false);
          message.putStringProperty("_AMQ_GROUP_ID", "" + group);
          clientProducer.send(message);
        }
      }

      for (int c = 0; c < consumers.length; c++) {
        while (true) {
          ClientMessage msg = consumers[c].receiveImmediate();
          if (msg == null) {
            break;
          }
          counts[c]++;
        }
      }

      for (int count : counts) {
        Assert.assertNotEquals(
            "You shouldn't have all messages bound to a single consumer", 30, count);
        Assert.assertNotEquals(
            "But you shouldn't have also a single consumer bound to none", 0, count);
      }
    } finally {
      consumer1.close();
      consumer2.close();
      consumer3.close();
    }
  }