コード例 #1
0
  public void testCommitPreparedTransactions() throws Exception {
    SimpleString recQueue = new SimpleString("BasicXaTestqRec");
    SimpleString sendQueue = new SimpleString("BasicXaTestqSend");

    byte[] globalTransactionId = UUIDGenerator.getInstance().generateStringUUID().getBytes();
    Xid xid = new XidImpl("xa1".getBytes(), 1, globalTransactionId);
    Xid xid2 = new XidImpl("xa2".getBytes(), 1, globalTransactionId);
    ServerLocator locator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    ClientSessionFactory csf = locator.createSessionFactory();
    ClientSession clientSession = csf.createSession(true, false, false);
    clientSession.createQueue(recQueue, recQueue, null, true);
    clientSession.createQueue(sendQueue, sendQueue, null, true);
    ClientMessage m1 = createTextMessage(clientSession, "");
    m1.putStringProperty("m1", "m1");
    ClientProducer clientProducer = clientSession.createProducer(recQueue);
    clientProducer.send(m1);
    locator.close();

    ServerLocator receiveLocator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    ClientSessionFactory receiveCsf = receiveLocator.createSessionFactory();
    ClientSession receiveClientSession = receiveCsf.createSession(true, false, false);
    ClientConsumer consumer = receiveClientSession.createConsumer(recQueue);

    ServerLocator sendLocator =
        HornetQClient.createServerLocatorWithoutHA(
            new TransportConfiguration(UnitTestCase.INVM_CONNECTOR_FACTORY));
    ClientSessionFactory sendCsf = sendLocator.createSessionFactory();
    ClientSession sendClientSession = sendCsf.createSession(true, false, false);
    ClientProducer producer = sendClientSession.createProducer(sendQueue);

    receiveClientSession.start(xid, XAResource.TMNOFLAGS);
    receiveClientSession.start();
    sendClientSession.start(xid2, XAResource.TMNOFLAGS);

    ClientMessage m = consumer.receive(5000);
    assertNotNull(m);

    producer.send(m);

    receiveClientSession.end(xid, XAResource.TMSUCCESS);
    sendClientSession.end(xid2, XAResource.TMSUCCESS);

    receiveClientSession.prepare(xid);
    sendClientSession.prepare(xid2);

    HornetQServerControl serverControl = createManagementControl();

    sendLocator.close();
    receiveLocator.close();

    boolean success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid));

    success = serverControl.commitPreparedTransaction(XidImpl.toBase64String(xid));

    System.out.println("HornetQServerControlTest.testCommitPreparedTransactions");
  }
コード例 #2
0
ファイル: StompSession.java プロジェクト: rhusar/hornetq
  public void addSubscription(
      long consumerID,
      String subscriptionID,
      String clientID,
      String durableSubscriptionName,
      String destination,
      String selector,
      String ack)
      throws Exception {
    SimpleString queue = SimpleString.toSimpleString(destination);
    int receiveCredits = consumerCredits;
    if (ack.equals(Stomp.Headers.Subscribe.AckModeValues.AUTO)) {
      receiveCredits = -1;
    }

    if (destination.startsWith("jms.topic")) {
      // subscribes to a topic
      if (durableSubscriptionName != null) {
        if (clientID == null) {
          throw BUNDLE.missingClientID();
        }
        queue = SimpleString.toSimpleString(clientID + "." + durableSubscriptionName);
        QueueQueryResult query = session.executeQueueQuery(queue);
        if (!query.isExists()) {
          session.createQueue(
              SimpleString.toSimpleString(destination),
              queue,
              SimpleString.toSimpleString(selector),
              false,
              true);
        }
      } else {
        queue = UUIDGenerator.getInstance().generateSimpleStringUUID();
        session.createQueue(
            SimpleString.toSimpleString(destination),
            queue,
            SimpleString.toSimpleString(selector),
            true,
            false);
      }
      ((ServerSessionImpl) session)
          .createConsumer(consumerID, queue, null, false, false, receiveCredits);
    } else {
      ((ServerSessionImpl) session)
          .createConsumer(
              consumerID,
              queue,
              SimpleString.toSimpleString(selector),
              false,
              false,
              receiveCredits);
    }

    StompSubscription subscription = new StompSubscription(subscriptionID, ack);
    subscriptions.put(consumerID, subscription);

    session.start();
  }
コード例 #3
0
ファイル: DiscoveryTest.java プロジェクト: bobfields/hornetq
 private TransportConfiguration generateTC(String debug) {
   String className =
       "org.foo.bar." + debug + "|" + UUIDGenerator.getInstance().generateStringUUID() + "";
   String name = UUIDGenerator.getInstance().generateStringUUID();
   Map<String, Object> params = new HashMap<String, Object>();
   params.put(UUIDGenerator.getInstance().generateStringUUID(), 123);
   params.put(
       UUIDGenerator.getInstance().generateStringUUID(),
       UUIDGenerator.getInstance().generateStringUUID());
   params.put(UUIDGenerator.getInstance().generateStringUUID(), true);
   TransportConfiguration tc = new TransportConfiguration(className, params, name);
   return tc;
 }
コード例 #4
0
ファイル: ClientAbstract.java プロジェクト: nebnagrom/hornetq
 /** @return */
 private XidImpl newXID() {
   return new XidImpl(
       "tst".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
 }
コード例 #5
0
ファイル: UnitTestCase.java プロジェクト: igorhvr/hornetq
 protected XidImpl newXID() {
   return new XidImpl(
       "xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
 }
コード例 #6
0
ファイル: DiscoveryTest.java プロジェクト: bobfields/hornetq
  public void testMultipleGroups() throws Exception {
    final int groupPort1 = getUDPDiscoveryPort();

    final int groupPort2 = getUDPDiscoveryPort(1);

    final int groupPort3 = getUDPDiscoveryPort(2);

    final InetAddress groupAddress1 = InetAddress.getByName(address1);

    final InetAddress groupAddress2 = InetAddress.getByName(address2);

    final InetAddress groupAddress3 = InetAddress.getByName(address3);

    final int timeout = 5000;

    String node1 = UUIDGenerator.getInstance().generateStringUUID();

    String node2 = UUIDGenerator.getInstance().generateStringUUID();

    String node3 = UUIDGenerator.getInstance().generateStringUUID();

    bg1 = newBroadcast(node1, RandomUtil.randomString(), null, -1, groupAddress1, groupPort1);

    bg2 = newBroadcast(node2, RandomUtil.randomString(), null, -1, groupAddress2, groupPort2);

    bg3 = newBroadcast(node3, RandomUtil.randomString(), null, -1, groupAddress3, groupPort3);

    bg2.start();
    bg1.start();
    bg3.start();

    TransportConfiguration live1 = generateTC("live1");

    TransportConfiguration live2 = generateTC("live2");

    TransportConfiguration live3 = generateTC("live3");

    bg1.addConnector(live1);
    bg2.addConnector(live2);
    bg3.addConnector(live3);

    dg1 =
        newDiscoveryGroup(
            "group-1::" + RandomUtil.randomString(),
            "group-1::" + RandomUtil.randomString(),
            null,
            groupAddress1,
            groupPort1,
            timeout);
    dg1.start();

    dg2 =
        newDiscoveryGroup(
            "group-2::" + RandomUtil.randomString(),
            "group-2::" + RandomUtil.randomString(),
            null,
            groupAddress2,
            groupPort2,
            timeout);
    dg2.start();

    dg3 =
        newDiscoveryGroup(
            "group-3::" + RandomUtil.randomString(),
            "group-3::" + RandomUtil.randomString(),
            null,
            groupAddress3,
            groupPort3,
            timeout);
    dg3.start();

    bg1.broadcastConnectors();

    bg2.broadcastConnectors();

    bg3.broadcastConnectors();

    boolean ok = dg1.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    List<DiscoveryEntry> entries = dg1.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live1), entries);

    ok = dg2.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    entries = dg2.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live2), entries);

    ok = dg3.waitForBroadcast(timeout);
    Assert.assertTrue(ok);
    entries = dg3.getDiscoveryEntries();
    assertEqualsDiscoveryEntries(Arrays.asList(live3), entries);
  }
コード例 #7
0
  private ServerLocatorImpl(
      final Topology topology,
      final boolean useHA,
      final DiscoveryGroupConfiguration discoveryGroupConfiguration,
      final TransportConfiguration[] transportConfigs) {
    e.fillInStackTrace();

    this.topology = topology == null ? new Topology(this) : topology;

    this.ha = useHA;

    this.discoveryGroupConfiguration = discoveryGroupConfiguration;

    this.initialConnectors = transportConfigs;

    this.nodeID = UUIDGenerator.getInstance().generateStringUUID();

    clientFailureCheckPeriod = HornetQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD;

    connectionTTL = HornetQClient.DEFAULT_CONNECTION_TTL;

    callTimeout = HornetQClient.DEFAULT_CALL_TIMEOUT;

    callFailoverTimeout = HornetQClient.DEFAULT_CALL_FAILOVER_TIMEOUT;

    minLargeMessageSize = HornetQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE;

    consumerWindowSize = HornetQClient.DEFAULT_CONSUMER_WINDOW_SIZE;

    consumerMaxRate = HornetQClient.DEFAULT_CONSUMER_MAX_RATE;

    confirmationWindowSize = HornetQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE;

    producerWindowSize = HornetQClient.DEFAULT_PRODUCER_WINDOW_SIZE;

    producerMaxRate = HornetQClient.DEFAULT_PRODUCER_MAX_RATE;

    blockOnAcknowledge = HornetQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE;

    blockOnDurableSend = HornetQClient.DEFAULT_BLOCK_ON_DURABLE_SEND;

    blockOnNonDurableSend = HornetQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND;

    autoGroup = HornetQClient.DEFAULT_AUTO_GROUP;

    preAcknowledge = HornetQClient.DEFAULT_PRE_ACKNOWLEDGE;

    ackBatchSize = HornetQClient.DEFAULT_ACK_BATCH_SIZE;

    connectionLoadBalancingPolicyClassName =
        HornetQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME;

    useGlobalPools = HornetQClient.DEFAULT_USE_GLOBAL_POOLS;

    scheduledThreadPoolMaxSize = HornetQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE;

    threadPoolMaxSize = HornetQClient.DEFAULT_THREAD_POOL_MAX_SIZE;

    retryInterval = HornetQClient.DEFAULT_RETRY_INTERVAL;

    retryIntervalMultiplier = HornetQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER;

    maxRetryInterval = HornetQClient.DEFAULT_MAX_RETRY_INTERVAL;

    reconnectAttempts = HornetQClient.DEFAULT_RECONNECT_ATTEMPTS;

    initialConnectAttempts = HornetQClient.INITIAL_CONNECT_ATTEMPTS;

    failoverOnInitialConnection = HornetQClient.DEFAULT_FAILOVER_ON_INITIAL_CONNECTION;

    cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;

    initialMessagePacketSize = HornetQClient.DEFAULT_INITIAL_MESSAGE_PACKET_SIZE;

    cacheLargeMessagesClient = HornetQClient.DEFAULT_CACHE_LARGE_MESSAGE_CLIENT;

    compressLargeMessage = HornetQClient.DEFAULT_COMPRESS_LARGE_MESSAGES;

    clusterConnection = false;
  }
コード例 #8
0
ファイル: XASendExample.java プロジェクト: hhovsepy/hornetq
  @Override
  public boolean runExample() throws Exception {
    XAConnection connection = null;
    InitialContext initialContext = null;
    try {
      // Step 1. Create an initial context to perform the JNDI lookup.
      initialContext = getContext(0);

      // Step 2. Lookup on the queue
      Queue queue = (Queue) initialContext.lookup("/queue/exampleQueue");

      // Step 3. Perform a lookup on the XA Connection Factory
      XAConnectionFactory cf = (XAConnectionFactory) initialContext.lookup("/XAConnectionFactory");

      // Step 4.Create a JMS XAConnection
      connection = cf.createXAConnection();

      // Step 5. Start the connection
      connection.start();

      // Step 6. Create a JMS XASession
      XASession xaSession = connection.createXASession();

      // Step 7. Create a normal session
      Session normalSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // Step 8. Create a normal Message Consumer
      MessageConsumer normalConsumer = normalSession.createConsumer(queue);
      normalConsumer.setMessageListener(new SimpleMessageListener());

      // Step 9. Get the JMS Session
      Session session = xaSession.getSession();

      // Step 10. Create a message producer
      MessageProducer producer = session.createProducer(queue);

      // Step 11. Create two Text Messages
      TextMessage helloMessage = session.createTextMessage("hello");
      TextMessage worldMessage = session.createTextMessage("world");

      // Step 12. create a transaction
      Xid xid1 =
          new DummyXid(
              "xa-example1".getBytes(CharsetUtil.UTF_8),
              1,
              UUIDGenerator.getInstance().generateStringUUID().getBytes());

      // Step 13. Get the JMS XAResource
      XAResource xaRes = xaSession.getXAResource();

      // Step 14. Begin the Transaction work
      xaRes.start(xid1, XAResource.TMNOFLAGS);

      // Step 15. do work, sending two messages.
      producer.send(helloMessage);
      producer.send(worldMessage);

      Thread.sleep(2000);

      // Step 16. Check the result, it should receive none!
      checkNoMessageReceived();

      // Step 17. Stop the work
      xaRes.end(xid1, XAResource.TMSUCCESS);

      // Step 18. Prepare
      xaRes.prepare(xid1);

      // Step 19. Roll back the transaction
      xaRes.rollback(xid1);

      // Step 20. No messages should be received!
      checkNoMessageReceived();

      // Step 21. Create another transaction
      Xid xid2 =
          new DummyXid(
              "xa-example2".getBytes(),
              1,
              UUIDGenerator.getInstance().generateStringUUID().getBytes());

      // Step 22. Start the transaction
      xaRes.start(xid2, XAResource.TMNOFLAGS);

      // Step 23. Re-send those messages
      producer.send(helloMessage);
      producer.send(worldMessage);

      // Step 24. Stop the work
      xaRes.end(xid2, XAResource.TMSUCCESS);

      // Step 25. Prepare
      xaRes.prepare(xid2);

      // Step 26. No messages should be received at this moment
      checkNoMessageReceived();

      // Step 27. Commit!
      xaRes.commit(xid2, false);

      Thread.sleep(2000);

      // Step 28. Check the result, all message received
      checkAllMessageReceived();

      return result;
    } finally {
      // Step 29. Be sure to close our JMS resources!
      if (initialContext != null) {
        initialContext.close();
      }
      if (connection != null) {
        connection.close();
      }
    }
  }
コード例 #9
0
 public XADummyEndpoint(CountDownLatch latch) {
   super(latch);
   xid =
       new XidImpl(
           "xa1".getBytes(), 1, UUIDGenerator.getInstance().generateStringUUID().getBytes());
 }
コード例 #10
0
ファイル: InVMNodeManager.java プロジェクト: kabuky/hornetq
 public InVMNodeManager(boolean replicatedBackup, String directory) {
   super(replicatedBackup, directory);
   liveLock = new Semaphore(1);
   backupLock = new Semaphore(1);
   setUUID(UUIDGenerator.getInstance().generateUUID());
 }