@Override
  @Before
  public void setUp() throws Exception {
    super.setUp();

    setupServer2();
    setupServer1();

    jmsServer1.start();
    jmsServer1.activated();
    waitForServerToStart(jmsServer1.getActiveMQServer());

    jmsServer2.start();
    jmsServer2.activated();
    waitForServerToStart(jmsServer2.getActiveMQServer());

    waitForTopology(jmsServer1.getActiveMQServer(), 2);

    waitForTopology(jmsServer2.getActiveMQServer(), 2);

    cf1 =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF,
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(1)));
    cf2 =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(
            JMSFactoryType.CF,
            new TransportConfiguration(
                InVMConnectorFactory.class.getName(), generateInVMParams(2)));
  }
 private static ConnectionFactory createConnectionFactory() {
   Map<String, Object> params = new HashMap<>();
   params.put(TransportConstants.HOST_PROP_NAME, async_example.Connection.HOST);
   params.put(TransportConstants.PORT_PROP_NAME, async_example.Connection.PORT);
   return ActiveMQJMSClient.createConnectionFactoryWithoutHA(
       JMSFactoryType.CF,
       new TransportConfiguration(NettyConnectorFactory.class.getName(), params));
 }
  @Test
  public void testCreateDurableQueueUsingJMSAndRestartServer() throws Exception {
    String queueName = RandomUtil.randomString();
    String binding = RandomUtil.randomString();

    ActiveMQTestBase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    TransportConfiguration config =
        new TransportConfiguration(InVMConnectorFactory.class.getName());
    Connection connection =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, config)
            .createConnection();
    connection.start();
    Queue managementQueue = ActiveMQJMSClient.createQueue("activemq.management");
    QueueSession session = (QueueSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueRequestor requestor = new QueueRequestor(session, managementQueue);
    Message message = session.createMessage();
    JMSManagementHelper.putOperationInvocation(
        message, "jms.server", "createQueue", queueName, binding);
    Message reply = requestor.request(message);
    Assert.assertTrue(JMSManagementHelper.hasOperationSucceeded(reply));
    connection.close();

    Object o = ActiveMQTestBase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    Queue queue = (Queue) o;
    Assert.assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager.stop();

    ActiveMQTestBase.checkNoBinding(context, binding);
    checkNoResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));

    serverManager = createJMSServer();
    serverManager.start();

    o = ActiveMQTestBase.checkBinding(context, binding);
    Assert.assertTrue(o instanceof Queue);
    queue = (Queue) o;
    Assert.assertEquals(queueName, queue.getQueueName());
    checkResource(ObjectNameBuilder.DEFAULT.getJMSQueueObjectName(queueName));
  }
  @Test
  public void testDefaultConstructor() throws Exception {
    ActiveMQConnectionFactory cf =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF);
    assertFactoryParams(
        cf,
        null,
        null,
        null,
        ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
        ActiveMQClient.DEFAULT_CONNECTION_TTL,
        ActiveMQClient.DEFAULT_CALL_TIMEOUT,
        ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT,
        ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE,
        ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE,
        ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_AUTO_GROUP,
        ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
        ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS,
        ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
        ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
    Connection conn = null;

    try {
      conn = cf.createConnection();

      conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Assert.fail("Should throw exception");
    } catch (JMSException e) {
      // Ok
    }
    if (conn != null) {
      conn.close();
    }

    ActiveMQConnectionFactoryTest.log.info("Got here");

    testSettersThrowException(cf);
  }
Example #5
0
 @Override
 protected ActiveMQConnectionFactory internalNewObject(
     URI uri, Map<String, String> query, String name) throws Exception {
   JMSConnectionOptions options = newConectionOptions(uri, query);
   ActiveMQConnectionFactory factory =
       ActiveMQJMSClient.createConnectionFactoryWithoutHA(
           options.getFactoryTypeEnum(),
           InVMTransportConfigurationSchema.createTransportConfiguration(
               uri,
               query,
               name,
               "org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory"));
   return setData(uri, factory, query);
 }
  @Test
  public void testDiscoveryConstructor() throws Exception {
    DiscoveryGroupConfiguration groupConfiguration =
        new DiscoveryGroupConfiguration()
            .setBroadcastEndpointFactory(
                new UDPBroadcastEndpointFactory()
                    .setGroupAddress(groupAddress)
                    .setGroupPort(groupPort));
    ActiveMQConnectionFactory cf =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(groupConfiguration, JMSFactoryType.CF);
    assertFactoryParams(
        cf,
        null,
        groupConfiguration,
        null,
        ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
        ActiveMQClient.DEFAULT_CONNECTION_TTL,
        ActiveMQClient.DEFAULT_CALL_TIMEOUT,
        ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT,
        ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE,
        ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE,
        ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_AUTO_GROUP,
        ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
        ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS,
        ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
        ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
    Connection conn = cf.createConnection();

    conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    testSettersThrowException(cf);

    conn.close();
  }
  @Test
  public void testStaticConnectorLiveConstructor() throws Exception {
    ActiveMQConnectionFactory cf =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);
    assertFactoryParams(
        cf,
        new TransportConfiguration[] {liveTC},
        null,
        null,
        ActiveMQClient.DEFAULT_CLIENT_FAILURE_CHECK_PERIOD,
        ActiveMQClient.DEFAULT_CONNECTION_TTL,
        ActiveMQClient.DEFAULT_CALL_TIMEOUT,
        ActiveMQClient.DEFAULT_CALL_FAILOVER_TIMEOUT,
        ActiveMQClient.DEFAULT_MIN_LARGE_MESSAGE_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_CONSUMER_MAX_RATE,
        ActiveMQClient.DEFAULT_CONFIRMATION_WINDOW_SIZE,
        ActiveMQClient.DEFAULT_PRODUCER_MAX_RATE,
        ActiveMQClient.DEFAULT_BLOCK_ON_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_BLOCK_ON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_BLOCK_ON_NON_DURABLE_SEND,
        ActiveMQClient.DEFAULT_AUTO_GROUP,
        ActiveMQClient.DEFAULT_PRE_ACKNOWLEDGE,
        ActiveMQClient.DEFAULT_CONNECTION_LOAD_BALANCING_POLICY_CLASS_NAME,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_ACK_BATCH_SIZE,
        ActiveMQClient.DEFAULT_DISCOVERY_INITIAL_WAIT_TIMEOUT,
        ActiveMQClient.DEFAULT_USE_GLOBAL_POOLS,
        ActiveMQClient.DEFAULT_SCHEDULED_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_THREAD_POOL_MAX_SIZE,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL,
        ActiveMQClient.DEFAULT_RETRY_INTERVAL_MULTIPLIER,
        ActiveMQClient.DEFAULT_RECONNECT_ATTEMPTS);
    Connection conn = cf.createConnection();

    conn.createSession(false, Session.AUTO_ACKNOWLEDGE);

    testSettersThrowException(cf);

    cf.close();

    conn.close();
  }
  public void send(ExampleCommand command, String queueName, String filter)
      throws JMSException, IOException {
    try (Session session = connection.createSession()) {

      Message message;
      if (binaryMode) {
        message = session.createBytesMessage();
        ((BytesMessage) message).writeBytes(command.toBytes());
      } else {
        message = session.createTextMessage(command.toXml());
      }

      if (filter != null && !blank(filter)) {
        String[] parts = filter.split("\\s*=\\s*");
        message.setStringProperty(parts[0], parts[1]);
      }
      try (MessageProducer p = session.createProducer(ActiveMQJMSClient.createQueue(queueName))) {
        p.send(message, DeliveryMode.PERSISTENT, 4, 0);
      }
    }
  }
  @Test
  public void testGettersAndSetters() {
    ActiveMQConnectionFactory cf =
        ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, liveTC);

    long clientFailureCheckPeriod = RandomUtil.randomPositiveLong();
    long connectionTTL = RandomUtil.randomPositiveLong();
    long callTimeout = RandomUtil.randomPositiveLong();
    int minLargeMessageSize = RandomUtil.randomPositiveInt();
    int consumerWindowSize = RandomUtil.randomPositiveInt();
    int consumerMaxRate = RandomUtil.randomPositiveInt();
    int confirmationWindowSize = RandomUtil.randomPositiveInt();
    int producerMaxRate = RandomUtil.randomPositiveInt();
    boolean blockOnAcknowledge = RandomUtil.randomBoolean();
    boolean blockOnDurableSend = RandomUtil.randomBoolean();
    boolean blockOnNonDurableSend = RandomUtil.randomBoolean();
    boolean autoGroup = RandomUtil.randomBoolean();
    boolean preAcknowledge = RandomUtil.randomBoolean();
    String loadBalancingPolicyClassName = RandomUtil.randomString();
    boolean useGlobalPools = RandomUtil.randomBoolean();
    int scheduledThreadPoolMaxSize = RandomUtil.randomPositiveInt();
    int threadPoolMaxSize = RandomUtil.randomPositiveInt();
    long retryInterval = RandomUtil.randomPositiveLong();
    double retryIntervalMultiplier = RandomUtil.randomDouble();
    int reconnectAttempts = RandomUtil.randomPositiveInt();
    cf.setClientFailureCheckPeriod(clientFailureCheckPeriod);
    cf.setConnectionTTL(connectionTTL);
    cf.setCallTimeout(callTimeout);
    cf.setMinLargeMessageSize(minLargeMessageSize);
    cf.setConsumerWindowSize(consumerWindowSize);
    cf.setConsumerMaxRate(consumerMaxRate);
    cf.setConfirmationWindowSize(confirmationWindowSize);
    cf.setProducerMaxRate(producerMaxRate);
    cf.setBlockOnAcknowledge(blockOnAcknowledge);
    cf.setBlockOnDurableSend(blockOnDurableSend);
    cf.setBlockOnNonDurableSend(blockOnNonDurableSend);
    cf.setAutoGroup(autoGroup);
    cf.setPreAcknowledge(preAcknowledge);
    cf.setConnectionLoadBalancingPolicyClassName(loadBalancingPolicyClassName);
    cf.setUseGlobalPools(useGlobalPools);
    cf.setScheduledThreadPoolMaxSize(scheduledThreadPoolMaxSize);
    cf.setThreadPoolMaxSize(threadPoolMaxSize);
    cf.setRetryInterval(retryInterval);
    cf.setRetryIntervalMultiplier(retryIntervalMultiplier);
    cf.setReconnectAttempts(reconnectAttempts);
    Assert.assertEquals(clientFailureCheckPeriod, cf.getClientFailureCheckPeriod());
    Assert.assertEquals(connectionTTL, cf.getConnectionTTL());
    Assert.assertEquals(callTimeout, cf.getCallTimeout());
    Assert.assertEquals(minLargeMessageSize, cf.getMinLargeMessageSize());
    Assert.assertEquals(consumerWindowSize, cf.getConsumerWindowSize());
    Assert.assertEquals(consumerMaxRate, cf.getConsumerMaxRate());
    Assert.assertEquals(confirmationWindowSize, cf.getConfirmationWindowSize());
    Assert.assertEquals(producerMaxRate, cf.getProducerMaxRate());
    Assert.assertEquals(blockOnAcknowledge, cf.isBlockOnAcknowledge());
    Assert.assertEquals(blockOnDurableSend, cf.isBlockOnDurableSend());
    Assert.assertEquals(blockOnNonDurableSend, cf.isBlockOnNonDurableSend());
    Assert.assertEquals(autoGroup, cf.isAutoGroup());
    Assert.assertEquals(preAcknowledge, cf.isPreAcknowledge());
    Assert.assertEquals(
        loadBalancingPolicyClassName, cf.getConnectionLoadBalancingPolicyClassName());
    Assert.assertEquals(useGlobalPools, cf.isUseGlobalPools());
    Assert.assertEquals(scheduledThreadPoolMaxSize, cf.getScheduledThreadPoolMaxSize());
    Assert.assertEquals(threadPoolMaxSize, cf.getThreadPoolMaxSize());
    Assert.assertEquals(retryInterval, cf.getRetryInterval());
    Assert.assertEquals(retryIntervalMultiplier, cf.getRetryIntervalMultiplier(), 0.0001);
    Assert.assertEquals(reconnectAttempts, cf.getReconnectAttempts());

    cf.close();
  }
  public static void main(final String[] args) throws Exception {
    Connection connection0 = null;

    Connection connection1 = null;

    Connection connection2 = null;

    Connection connection3 = null;

    Connection connection4 = null;

    Connection connection5 = null;

    try {
      // Step 1 - We instantiate a connection factory directly, specifying the UDP address and port
      // for discovering
      // the list of servers in the cluster.
      // We could use JNDI to look-up a connection factory, but we'd need to know the JNDI server
      // host and port for
      // the
      // specific server to do that, and that server might not be available at the time. By creating
      // the
      // connection factory directly we avoid having to worry about a JNDI look-up.
      // In an app server environment you could use HA-JNDI to lookup from the clustered JNDI
      // servers without
      // having to know about a specific one.
      UDPBroadcastEndpointFactory udpCfg = new UDPBroadcastEndpointFactory();
      udpCfg.setGroupAddress("231.7.7.7").setGroupPort(9876);
      DiscoveryGroupConfiguration groupConfiguration = new DiscoveryGroupConfiguration();
      groupConfiguration.setBroadcastEndpointFactory(udpCfg);

      ConnectionFactory cf =
          ActiveMQJMSClient.createConnectionFactoryWithHA(groupConfiguration, JMSFactoryType.CF);

      // We give a little while for each server to broadcast its whereabouts to the client
      Thread.sleep(2000);

      // Step 2. Directly instantiate JMS Queue and Topic objects
      Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");

      Topic topic = ActiveMQJMSClient.createTopic("exampleTopic");

      // Step 3. We create six connections, they should be to different nodes of the cluster in a
      // round-robin fashion
      // and start them
      connection0 = cf.createConnection();

      connection1 = cf.createConnection();

      connection2 = cf.createConnection();

      connection3 = cf.createConnection();

      connection4 = cf.createConnection();

      connection5 = cf.createConnection();

      connection0.start();

      connection1.start();

      connection2.start();

      connection3.start();

      connection4.start();

      connection5.start();

      // Step 4. We create a session on each connection

      Session session0 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session3 = connection0.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session4 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session5 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);

      // Step 5. We create a topic subscriber on each server

      MessageConsumer subscriber0 = session0.createConsumer(topic);

      MessageConsumer subscriber1 = session1.createConsumer(topic);

      MessageConsumer subscriber2 = session2.createConsumer(topic);

      MessageConsumer subscriber3 = session3.createConsumer(topic);

      MessageConsumer subscriber4 = session4.createConsumer(topic);

      MessageConsumer subscriber5 = session5.createConsumer(topic);

      // Step 6. We create a queue consumer on server 0

      MessageConsumer consumer0 = session0.createConsumer(queue);

      // Step 7. We create an anonymous message producer on just one server 2

      MessageProducer producer2 = session2.createProducer(null);

      // Step 8. We send 500 messages each to the queue and topic

      final int numMessages = 500;

      for (int i = 0; i < numMessages; i++) {
        TextMessage message1 = session2.createTextMessage("Topic message " + i);

        producer2.send(topic, message1);

        TextMessage message2 = session2.createTextMessage("Queue message " + i);

        producer2.send(queue, message2);
      }

      // Step 9. Verify all subscribers and the consumer receive the messages

      for (int i = 0; i < numMessages; i++) {
        TextMessage received0 = (TextMessage) subscriber0.receive(5000);

        if (received0 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received1 = (TextMessage) subscriber1.receive(5000);

        if (received1 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received2 = (TextMessage) subscriber2.receive(5000);

        if (received2 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received3 = (TextMessage) subscriber3.receive(5000);

        if (received3 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received4 = (TextMessage) subscriber4.receive(5000);

        if (received4 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received5 = (TextMessage) subscriber5.receive(5000);

        if (received5 == null) {
          throw new IllegalStateException("Message is null!");
        }

        TextMessage received6 = (TextMessage) consumer0.receive(5000);

        if (received6 == null) {
          throw new IllegalStateException("Message is null!");
        }
      }
    } finally {
      // Step 15. Be sure to close our resources!

      connection0.close();
      connection1.close();
      connection2.close();
      connection3.close();
      connection4.close();
      connection5.close();
    }
  }
  @Test
  public void testSendToSingleDisconnectedBinding() throws Exception {
    Connection conn1 = cf1.createConnection();

    conn1.setClientID("someClient1");

    Connection conn2 = cf2.createConnection();

    conn2.setClientID("someClient2");

    conn1.start();

    conn2.start();

    try {

      Topic topic1 = createTopic("t1", true);

      Topic topic2 = (Topic) context1.lookup("topic/t1");

      Session session1 = conn1.createSession(false, Session.AUTO_ACKNOWLEDGE);

      Session session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

      MessageConsumer cons2 = session2.createDurableSubscriber(topic2, "sub2");

      cons2.close();

      session2.close();

      conn2.close();

      Thread.sleep(500);

      MessageProducer prod1 = session1.createProducer(topic1);

      prod1.setDeliveryMode(DeliveryMode.PERSISTENT);

      prod1.send(session1.createTextMessage("m1"));

      printBindings(jmsServer1.getActiveMQServer(), "jms.topic.t1");
      printBindings(jmsServer2.getActiveMQServer(), "jms.topic.t1");

      crash();

      printBindings(jmsServer1.getActiveMQServer(), "jms.topic.t1");

      prod1.send(session1.createTextMessage("m2"));

      restart();

      Thread.sleep(2000);

      printBindings(jmsServer1.getActiveMQServer(), "jms.topic.t1");
      printBindings(jmsServer2.getActiveMQServer(), "jms.topic.t1");

      prod1.send(session1.createTextMessage("m3"));

      cf2 =
          ActiveMQJMSClient.createConnectionFactoryWithoutHA(
              JMSFactoryType.CF,
              new TransportConfiguration(
                  InVMConnectorFactory.class.getName(), generateInVMParams(2)));

      conn2 = cf2.createConnection();

      conn2.setClientID("someClient2");

      session2 = conn2.createSession(false, Session.AUTO_ACKNOWLEDGE);

      cons2 = session2.createDurableSubscriber(topic2, "sub2");

      conn2.start();

      TextMessage received = (TextMessage) cons2.receive(5000);

      assertNotNull(received);

      assertEquals("m1", received.getText());

      received = (TextMessage) cons2.receive(5000);

      assertNotNull(received);

      assertEquals("m2", received.getText());

      received = (TextMessage) cons2.receive(5000);

      assertNotNull(received);

      assertEquals("m3", received.getText());

      cons2.close();
    } finally {
      conn1.close();
      conn2.close();
    }

    jmsServer1.destroyTopic("t1");
    jmsServer2.destroyTopic("t1");
  }