コード例 #1
0
  @Test
  public void testLargeMessageCompression2() throws Exception {
    final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createTemporaryQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);

    producer.send(clientFile);

    session.commit();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    String testDir = getTestDir();
    File testFile = new File(testDir, "async_large_message");
    FileOutputStream output = new FileOutputStream(testFile);

    msg1.setOutputStream(output);

    msg1.waitOutputStreamCompletion(0);

    msg1.acknowledge();

    output.close();

    session.commit();

    consumer.close();

    session.close();

    // verify
    FileInputStream input = new FileInputStream(testFile);
    for (int i = 0; i < messageSize; i++) {
      byte b = (byte) input.read();
      assertEquals("position = " + i, getSamplebyte(i), b);
    }
    input.close();
    testFile.delete();
    validateNoFilesOnLargeDir();
  }
コード例 #2
0
  @Test
  public void testLargeMessageCompression() throws Exception {
    final int messageSize = (int) (3.5 * HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE);

    HornetQServer server = createServer(true, isNetty());

    server.start();

    ClientSessionFactory sf = createSessionFactory(locator);

    ClientSession session = addClientSession(sf.createSession(false, false, false));

    session.createTemporaryQueue(ADDRESS, ADDRESS);

    ClientProducer producer = session.createProducer(ADDRESS);

    Message clientFile = createLargeClientMessageStreaming(session, messageSize, true);

    producer.send(clientFile);

    session.commit();

    session.start();

    ClientConsumer consumer = session.createConsumer(ADDRESS);
    ClientMessage msg1 = consumer.receive(1000);
    Assert.assertNotNull(msg1);

    for (int i = 0; i < messageSize; i++) {
      byte b = msg1.getBodyBuffer().readByte();
      assertEquals("position = " + i, getSamplebyte(i), b);
    }

    msg1.acknowledge();
    session.commit();

    consumer.close();

    session.close();

    validateNoFilesOnLargeDir();
  }
コード例 #3
0
ファイル: YamcsAckConnector.java プロジェクト: xsmarty/yamcs
  /**
   * Add a consumer for a given queue at the yamcs server. The final queue address will be composed
   * in the following manner: "instance.queueName", where the instance was provided when creating
   * this connector.
   *
   * @param queueName the name of the queue
   * @param temporaryQueue if <code>true</code>, a new temporary queue for the given address is
   *     created
   * @param handler the handler used to process receiving messages
   * @throws HornetQException if anything went wrong, e.g. the queue is not available
   */
  public void addConsumer(
      final String queueName, boolean temporaryQueue, final MessageHandler handler)
      throws HornetQException {
    SimpleString address = new SimpleString(String.format("%1$s.%2$s", instance, queueName));

    if (temporaryQueue) {
      SimpleString name = new SimpleString("tempDataQueue." + UUID.randomUUID().toString());

      // create a temporary queue with this name
      if (!session.queueQuery(name).isExists()) {
        session.createTemporaryQueue(address, name);
      }

      // use the name as new address when creating the consumer
      address = name;
    }

    ClientConsumer consumer = session.createConsumer(address, false);
    consumer.setMessageHandler(handler);
    dataConsumers.add(consumer);
  }
コード例 #4
0
  /**
   * https://jira.jboss.org/jira/browse/HORNETQ-286
   *
   * <p>the test checks that the temp queue is properly propagated to the cluster (assuming we wait
   * for the bindings)
   */
  @Test
  public void testSendToTempQueueFromAnotherClusterNode() throws Exception {
    setupCluster();

    startServers(0, 1);

    setupSessionFactory(0, isNetty());
    setupSessionFactory(1, isNetty());

    String tempAddress = "queues.tempaddress";
    String tempQueue = "tempqueue";
    // create temp queue on node #0
    ClientSession session = sfs[0].createSession(false, true, true);
    session.createTemporaryQueue(tempAddress, tempQueue);
    ClientConsumer consumer = session.createConsumer(tempQueue);

    // check the binding is created on node #1
    waitForBindings(1, tempAddress, 1, 1, false);

    // send to the temp address on node #1
    send(1, tempAddress, 10, false, null);

    session.start();

    // check consumer bound to node #0 receives from the temp queue
    for (int j = 0; j < 10; j++) {
      ClientMessage message = consumer.receive(5000);
      if (message == null) {
        Assert.assertNotNull("consumer did not receive message on temp queue " + j, message);
      }
      message.acknowledge();
    }

    consumer.close();
    session.deleteQueue(tempQueue);
    session.close();
  }
コード例 #5
0
  @POST
  public Response createSubscription(
      @FormParam("durable") @DefaultValue("false") boolean durable,
      @FormParam("autoAck") @DefaultValue("true") boolean autoAck,
      @FormParam("name") String subscriptionName,
      @FormParam("selector") String selector,
      @FormParam("delete-when-idle") Boolean destroyWhenIdle,
      @FormParam("idle-timeout") Long timeout,
      @Context UriInfo uriInfo) {
    HornetQRestLogger.LOGGER.debug("Handling POST request for \"" + uriInfo.getPath() + "\"");

    if (timeout == null) timeout = Long.valueOf(consumerTimeoutSeconds * 1000);
    boolean deleteWhenIdle = !durable; // default is true if non-durable
    if (destroyWhenIdle != null) deleteWhenIdle = destroyWhenIdle.booleanValue();

    if (subscriptionName != null) {
      // see if this is a reconnect
      QueueConsumer consumer = queueConsumers.get(subscriptionName);
      if (consumer != null) {
        boolean acked = consumer instanceof AcknowledgedSubscriptionResource;
        acked = !acked;
        if (acked != autoAck) {
          throw new WebApplicationException(
              Response.status(412)
                  .entity("Consumer already exists and ack-modes don't match.")
                  .type("text/plain")
                  .build());
        }
        Subscription sub = (Subscription) consumer;
        if (sub.isDurable() != durable) {
          throw new WebApplicationException(
              Response.status(412)
                  .entity("Consumer already exists and durability doesn't match.")
                  .type("text/plain")
                  .build());
        }
        Response.ResponseBuilder builder = Response.noContent();
        if (autoAck) {
          headAutoAckSubscriptionResponse(uriInfo, consumer, builder);
          consumer.setSessionLink(
              builder, uriInfo, uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId());
        } else {
          headAcknowledgedConsumerResponse(uriInfo, (AcknowledgedQueueConsumer) consumer, builder);
          consumer.setSessionLink(
              builder,
              uriInfo,
              uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId());
        }
        return builder.build();
      }
    } else {
      subscriptionName = generateSubscriptionName();
    }
    ClientSession session = null;
    try {
      // if this is not a reconnect, create the subscription queue
      if (!subscriptionExists(subscriptionName)) {
        session = sessionFactory.createSession();

        if (durable) {
          session.createQueue(destination, subscriptionName, true);
        } else {
          session.createTemporaryQueue(destination, subscriptionName);
        }
      }
      QueueConsumer consumer =
          createConsumer(durable, autoAck, subscriptionName, selector, timeout, deleteWhenIdle);
      queueConsumers.put(consumer.getId(), consumer);
      serviceManager.getTimeoutTask().add(this, consumer.getId());

      UriBuilder location = uriInfo.getAbsolutePathBuilder();
      if (autoAck) location.path("auto-ack");
      else location.path("acknowledged");
      location.path(consumer.getId());
      Response.ResponseBuilder builder = Response.created(location.build());
      if (autoAck) {
        QueueConsumer.setConsumeNextLink(
            serviceManager.getLinkStrategy(),
            builder,
            uriInfo,
            uriInfo.getMatchedURIs().get(1) + "/auto-ack/" + consumer.getId(),
            "-1");
      } else {
        AcknowledgedQueueConsumer.setAcknowledgeNextLink(
            serviceManager.getLinkStrategy(),
            builder,
            uriInfo,
            uriInfo.getMatchedURIs().get(1) + "/acknowledged/" + consumer.getId(),
            "-1");
      }
      return builder.build();

    } catch (HornetQException e) {
      throw new RuntimeException(e);
    } finally {
      if (session != null) {
        try {
          session.close();
        } catch (HornetQException e) {
        }
      }
    }
  }