public void onMessage(ClientMessage message) {

      try {

        message.acknowledge();
        ClientMessage outmsg = session.createMessage(true);

        outmsg.putIntProperty("out_msg", message.getIntProperty("msg"));

        producer.send(outmsg);

        if (rollbackFirstMessage) {
          session.rollback();
          rollbackFirstMessage = false;
          return;
        }

        if (counter.incrementAndGet() % 200 == 0) {
          System.out.println("rollback " + message);
          session.rollback();
        } else {
          commitLatch.countDown();
          session.commit();
        }
      } catch (Exception e) {
        e.printStackTrace();
        try {
          session.rollback();
        } catch (Exception ignored) {
          ignored.printStackTrace();
        }
      }
    }
Ejemplo n.º 2
0
  protected ClientMessage createLargeClientMessage(
      final ClientSession session, final long numberOfBytes, final boolean persistent)
      throws Exception {

    ClientMessage clientMessage = session.createMessage(persistent);

    clientMessage.setBodyInputStream(UnitTestCase.createFakeLargeStream(numberOfBytes));

    return clientMessage;
  }
Ejemplo n.º 3
0
  /**
   * @param numberOfMessages
   * @param numberOfBytes
   * @param delayDelivery
   * @param session
   * @param producer
   * @throws FileNotFoundException
   * @throws IOException
   * @throws org.apache.activemq.api.core.ActiveMQException
   */
  private void sendMessages(
      final int numberOfMessages,
      final long numberOfBytes,
      final long delayDelivery,
      final ClientSession session,
      final ClientProducer producer)
      throws Exception {
    LargeMessageTestBase.log.debug("NumberOfBytes = " + numberOfBytes);
    for (int i = 0; i < numberOfMessages; i++) {
      ClientMessage message = session.createMessage(true);

      // If the test is using more than 1M, we will only use the Streaming, as it require too much
      // memory from the
      // test
      if (numberOfBytes > 1024 * 1024 || i % 2 == 0) {
        LargeMessageTestBase.log.debug("Sending message (stream)" + i);
        message.setBodyInputStream(UnitTestCase.createFakeLargeStream(numberOfBytes));
      } else {
        LargeMessageTestBase.log.debug("Sending message (array)" + i);
        byte[] bytes = new byte[(int) numberOfBytes];
        for (int j = 0; j < bytes.length; j++) {
          bytes[j] = UnitTestCase.getSamplebyte(j);
        }
        message.getBodyBuffer().writeBytes(bytes);
      }
      message.putIntProperty(new SimpleString("counter-message"), i);
      if (delayDelivery > 0) {
        long time = System.currentTimeMillis();
        message.putLongProperty(new SimpleString("original-time"), time);
        message.putLongProperty(Message.HDR_SCHEDULED_DELIVERY_TIME, time + delayDelivery);

        producer.send(message);
      } else {
        producer.send(message);
      }
    }
  }
Ejemplo n.º 4
0
 protected ClientMessage createLargeClientMessage(
     final ClientSession session, final byte[] buffer, final boolean durable) throws Exception {
   ClientMessage msgs = session.createMessage(durable);
   msgs.getBodyBuffer().writeBytes(buffer);
   return msgs;
 }