Java源码示例:org.apache.activemq.artemis.api.jms.ActiveMQJMSClient

示例1
public void StartBrokerProducer() throws JMSException {

        Connection connection = null;
        try {
            ConnectionFactory cf = new ActiveMQConnectionFactory(ioeConfiguration.getTopic().getTopicUrl());
            connection = cf.createConnection(ioeConfiguration.getTopic().getUsername(), ioeConfiguration.getTopic().getPassword());
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // TODO - Read message payload from cassandra
            String payload = "{\"data\": \"36\",\"description\": \"test\",\"sensorId\": 1, \"timestamp\": \"2015-06-19T11:07:44.526Z\", \"topic\": \"topic\"}";
            Message msg = session.createTextMessage(payload);

            //TODO Read topic value from the sensor data or publication entity
            Topic topic = ActiveMQJMSClient.createTopic("ioe");
            MessageProducer messageProducer = session.createProducer(null);
            messageProducer.send(topic,msg);
            connection.start();
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
 
示例2
public static void publish(String destination, Serializable object, String contentType) throws Exception {
   ConnectionFactory factory = ActiveMQJMSClient.createConnectionFactory("vm://0","cf");
   Connection conn = factory.createConnection();
   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Destination dest = session.createQueue(destination);

   try {
      Assert.assertNotNull("Destination was null", dest);
      MessageProducer producer = session.createProducer(dest);
      ObjectMessage message = session.createObjectMessage();

      if (contentType != null) {
         message.setStringProperty(HttpHeaderProperty.CONTENT_TYPE, contentType);
      }
      message.setObject(object);

      producer.send(message);
   } finally {
      conn.close();
   }
}
 
示例3
public static void main(final String[] args) throws Exception {
   // Step 2. Perfom a lookup on the queue
   Queue queue = ActiveMQJMSClient.createQueue("exampleQueue");

   // Step 4.Create a JMS Context using the try-with-resources statement
   try
      (
         // Even though ConnectionFactory is not closeable it would be nice to close an ActiveMQConnectionFactory
         ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
         JMSContext jmsContext = cf.createContext()
      ) {
      // Step 5. create a jms producer
      JMSProducer jmsProducer = jmsContext.createProducer();

      // Step 6. Try sending a message, we don't have the appropriate privileges to do this so this will throw an exception
      jmsProducer.send(queue, "A Message from JMS2!");

      System.out.println("Received:" + jmsContext.createConsumer(queue).receiveBody(String.class));
   }
}
 
示例4
/**
 * Ensure no blocking calls in acknowledge flow when block on acknowledge = false.
 * This is done by checking the performance compared to blocking is much improved.
 */
@Test
public void testNonBlockingAckPerf() throws Exception {
   ConnectionFactory cf1 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=false", "testsuitecf1");
   ConnectionFactory cf2 = ActiveMQJMSClient.createConnectionFactory("tcp://127.0.0.1:61616?blockOnNonDurableSend=true&blockOnAcknowledge=true", "testsuitecf2");

   int messageCount = 100;

   long sendT1 = send(cf1, queue1, messageCount);
   long sendT2 = send(cf2, queue2, messageCount);

   long time1 = consume(cf1, queue1, messageCount);
   long time2 = consume(cf2, queue2, messageCount);

   log.debug("BlockOnAcknowledge=false MessageCount=" + messageCount + " TimeToConsume=" + time1);
   log.debug("BlockOnAcknowledge=true MessageCount=" + messageCount + " TimeToConsume=" + time2);

   Assert.assertTrue(time1 < (time2 / 2));

}
 
示例5
@Test
public void testJGroupsFileURI() throws Exception {
   DiscoveryGroupConfiguration discoveryGroupConfiguration = new DiscoveryGroupConfiguration();
   JGroupsFileBroadcastEndpointFactory endpointFactory = new JGroupsFileBroadcastEndpointFactory().setChannelName("channel-name").setFile("channel-file.xml");
   discoveryGroupConfiguration.setName("foo").setRefreshTimeout(12345).setDiscoveryInitialWaitTimeout(5678).setBroadcastEndpointFactory(endpointFactory);
   ActiveMQConnectionFactory connectionFactoryWithHA = ActiveMQJMSClient.createConnectionFactoryWithHA(discoveryGroupConfiguration, JMSFactoryType.CF);
   URI tcp = parser.createSchema("jgroups", connectionFactoryWithHA);
   ActiveMQConnectionFactory factory = parser.newObject(tcp, null);
   DiscoveryGroupConfiguration dgc = factory.getDiscoveryGroupConfiguration();
   Assert.assertNotNull(dgc);
   BroadcastEndpointFactory befc = dgc.getBroadcastEndpointFactory();
   Assert.assertNotNull(befc);
   Assert.assertTrue(befc instanceof JGroupsFileBroadcastEndpointFactory);
   Assert.assertEquals(dgc.getName(), "foo");
   Assert.assertEquals(dgc.getDiscoveryInitialWaitTimeout(), 5678);
   Assert.assertEquals(dgc.getRefreshTimeout(), 12345);
   JGroupsFileBroadcastEndpointFactory fileBroadcastEndpointFactory = (JGroupsFileBroadcastEndpointFactory) befc;
   Assert.assertEquals(fileBroadcastEndpointFactory.getFile(), "channel-file.xml");
   Assert.assertEquals(fileBroadcastEndpointFactory.getChannelName(), "channel-name");

   BeanUtilsBean bean = new BeanUtilsBean();
   checkEquals(bean, connectionFactoryWithHA, factory);
}
 
示例6
private ActiveMQConnectionFactory createConnectionFactory() throws Exception {
   Map<String, Object> params = new HashMap<>();
   params.put(org.apache.activemq.artemis.core.remoting.impl.invm.TransportConstants.SERVER_ID_PROP_NAME, "1");
   final ActiveMQConnectionFactory activeMQConnectionFactory;
   if (configuration.getUrl() != null) {
      activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactory(configuration.getUrl(), null);
   } else {
      if (configuration.getHost() != null) {
         params.put(TransportConstants.HOST_PROP_NAME, configuration.getHost());
         params.put(TransportConstants.PORT_PROP_NAME, configuration.getPort());
      }
      if (configuration.isHa()) {
         activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
      } else {
         activeMQConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(configuration.getConnectorFactory(), params));
      }
   }
   if (configuration.hasAuthentication()) {
      activeMQConnectionFactory.setUser(configuration.getUsername());
      activeMQConnectionFactory.setPassword(configuration.getPassword());
   }
   // The CF will probably be GCed since it was injected, so we disable the finalize check
   return activeMQConnectionFactory.disableFinalizeChecks();
}
 
示例7
@Before
@Override
public void setUp() throws Throwable {

   FileUtil.deleteDirectory(serverFolder.getRoot());
   serverFolder.getRoot().mkdirs();

   File file = serverFolder.newFile(ActiveMQJMSClient.class.getName() + ".properties");
   FileOutputStream fileOutputStream = new FileOutputStream(file);
   PrintStream stream = new PrintStream(fileOutputStream);
   stream.println("enable1xPrefixes=true");
   stream.close();

   setVariable(serverClassloader, "persistent", Boolean.FALSE);
   startServer(serverFolder.getRoot(), serverClassloader, "live");
}
 
示例8
@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);

   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext();
   ) {
      session.start();
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      JMSProducer producer = jmsctx.createProducer();
      producer.setProperty("strvalue", "hello");
      TextMessage msgsend = jmsctx.createTextMessage("hello");
      producer.send(q, msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
示例9
@Test
public void testSimpleSendNoXAJMS1() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        Connection conn = qraConnectionFactory.createConnection();
   ) {
      Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      session.start();
      MessageProducer producer = jmsSess.createProducer(q);
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      TextMessage msgsend = jmsSess.createTextMessage("hello");
      msgsend.setStringProperty("strvalue", "hello");
      producer.send(msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
示例10
@Test
public void testSimpleSendNoXAJMSContext() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);

   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        JMSContext jmsctx = qraConnectionFactory.createContext();
   ) {
      session.start();
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      JMSProducer producer = jmsctx.createProducer();
      producer.setProperty("strvalue", "hello");
      TextMessage msgsend = jmsctx.createTextMessage("hello");
      producer.send(q, msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
示例11
@Test
public void testSimpleSendNoXAJMS1() throws Exception {
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   try (ClientSessionFactory sf = locator.createSessionFactory();
        ClientSession session = sf.createSession();
        ClientConsumer consVerify = session.createConsumer(MDBQUEUE);
        Connection conn = qraConnectionFactory.createConnection();
   ) {
      Session jmsSess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      session.start();
      MessageProducer producer = jmsSess.createProducer(q);
      // These next 4 lines could be written in a single line however it makes difficult for debugging
      TextMessage msgsend = jmsSess.createTextMessage("hello");
      msgsend.setStringProperty("strvalue", "hello");
      producer.send(msgsend);

      ClientMessage msg = consVerify.receive(1000);
      assertNotNull(msg);
      assertEquals("hello", msg.getStringProperty("strvalue"));
   }
}
 
示例12
public void sendMessageToNonExistentQueue(String queuePrefix, String queue, RoutingType routingType) throws Exception {
   conn.connect(defUser, defPass);
   send(conn, queuePrefix + queue, null, "Hello World", true, routingType);

   MessageConsumer consumer = session.createConsumer(ActiveMQJMSClient.createQueue(queue));
   TextMessage message = (TextMessage) consumer.receive(1000);
   Assert.assertNotNull(message);
   Assert.assertEquals("Hello World", message.getText());
   // Assert default priority 4 is used when priority header is not set
   Assert.assertEquals("getJMSPriority", 4, message.getJMSPriority());

   // Make sure that the timestamp is valid - should
   // be very close to the current time.
   long tnow = System.currentTimeMillis();
   long tmsg = message.getJMSTimestamp();
   Assert.assertTrue(Math.abs(tnow - tmsg) < 1500);

   // closing the consumer here should trigger auto-deletion
   assertNotNull(server.getPostOffice().getBinding(new SimpleString(queue)));
   consumer.close();
   Wait.assertTrue(() -> server.getPostOffice().getBinding(new SimpleString(queue)) == null);
}
 
示例13
@Test
public void testAutoCreateOnSendToQueueSecurity() throws Exception {
   ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addUser("guest", "guest");
   ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().setDefaultUser("guest");
   ((ActiveMQJAASSecurityManager) server.getSecurityManager()).getConfiguration().addRole("guest", "rejectAll");
   Role role = new Role("rejectAll", false, false, false, false, false, false, false, false, false, false);
   Set<Role> roles = new HashSet<>();
   roles.add(role);
   server.getSecurityRepository().addMatch("#", roles);
   Connection connection = cf.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   javax.jms.Queue queue = ActiveMQJMSClient.createQueue(QUEUE_NAME);

   try {
      session.createProducer(queue);
      Assert.fail("Sending a message here should throw a JMSSecurityException");
   } catch (Exception e) {
      Assert.assertTrue(e instanceof JMSSecurityException);
   }

   connection.close();
}
 
示例14
@Test
public void testArtemisJMSClient() throws Exception {
   // setup connection
   ConnectionFactory cf = new ActiveMQJMSConnectionFactory("tcp://localhost:61616");
   try (Connection connection = cf.createConnection()) {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      connection.start();
      Queue queue = ActiveMQJMSClient.createQueue("artemisJMSClientFeatureITQueue");
      MessageProducer producer = session.createProducer(queue);
      // send message
      String textMessage = "This is a text message";
      TextMessage message = session.createTextMessage(textMessage);
      producer.send(message);

      // receive message and assert
      MessageConsumer messageConsumer = session.createConsumer(queue);
      TextMessage messageReceived = (TextMessage) messageConsumer.receive(100);
      assertEquals(textMessage, messageReceived.getText());
   }
}
 
示例15
@Test
public void testAutoCreateOnConsumeFromFQQN() throws Exception {
   Connection connection = null;
   connection = cf.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   String queueName = RandomUtil.randomString();
   String addressName = RandomUtil.randomString();

   javax.jms.Queue queue = ActiveMQJMSClient.createQueue(CompositeAddress.toFullyQualified(addressName, queueName));

   MessageConsumer messageConsumer = session.createConsumer(queue);
   connection.start();

   Message m = messageConsumer.receive(500);
   Assert.assertNull(m);

   Queue q = (Queue) server.getPostOffice().getBinding(new SimpleString(queueName)).getBindable();
   Assert.assertEquals(0, q.getMessageCount());
   Assert.assertEquals(0, q.getMessagesAdded());
   connection.close();
}
 
示例16
@Test
public void testAutoCreateOnSubscribeToTopic() throws Exception {
   Connection connection = cf.createConnection();
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   final String topicName = "test-" + UUID.randomUUID().toString();

   javax.jms.Topic topic = ActiveMQJMSClient.createTopic(topicName);

   MessageConsumer consumer = session.createConsumer(topic);
   MessageProducer producer = session.createProducer(topic);
   producer.send(session.createTextMessage("msg"));
   connection.start();
   assertNotNull(consumer.receive(500));

   assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + topicName));

   connection.close();

   assertNull(server.getManagementService().getResource(ResourceNames.ADDRESS + topicName));
}
 
示例17
@Test
public void testAutoCreateOnDurableSubscribeToTopic() throws Exception {
   Connection connection = cf.createConnection();
   connection.setClientID("myClientID");
   Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

   javax.jms.Topic topic = ActiveMQJMSClient.createTopic(QUEUE_NAME);

   MessageConsumer consumer = session.createDurableConsumer(topic, "myDurableSub");
   MessageProducer producer = session.createProducer(topic);
   producer.send(session.createTextMessage("msg"));
   connection.start();
   assertNotNull(consumer.receive(500));

   connection.close();

   assertNotNull(server.getManagementService().getResource(ResourceNames.ADDRESS + "test"));

   assertNotNull(server.locateQueue(SimpleString.toSimpleString("myClientID.myDurableSub")));
}
 
示例18
@Test
public void testPreCommitAcks() throws Exception {
   conn = cf.createConnection();
   Session session = conn.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE);
   jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
   MessageProducer producer = session.createProducer(jBossQueue);
   MessageConsumer consumer = session.createConsumer(jBossQueue);
   int noOfMessages = 100;
   for (int i = 0; i < noOfMessages; i++) {
      producer.send(session.createTextMessage("m" + i));
   }

   conn.start();
   for (int i = 0; i < noOfMessages; i++) {
      Message m = consumer.receive(500);
      Assert.assertNotNull(m);
   }

   SimpleString queueName = new SimpleString(JmsConsumerTest.Q_NAME);
   Assert.assertEquals(0, getMessageCount((Queue) server.getPostOffice().getBinding(queueName).getBindable()));
   Assert.assertEquals(0, getMessageCount((Queue) server.getPostOffice().getBinding(queueName).getBindable()));
}
 
示例19
@Test
public void testPreCommitAcksWithMessageExpiry() throws Exception {
   conn = cf.createConnection();
   Session session = conn.createSession(false, ActiveMQJMSConstants.PRE_ACKNOWLEDGE);
   jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
   MessageProducer producer = session.createProducer(jBossQueue);
   MessageConsumer consumer = session.createConsumer(jBossQueue);
   int noOfMessages = 1000;
   for (int i = 0; i < noOfMessages; i++) {
      TextMessage textMessage = session.createTextMessage("m" + i);
      producer.setTimeToLive(1);
      producer.send(textMessage);
   }

   Thread.sleep(2);

   conn.start();

   Message m = consumer.receiveNoWait();
   Assert.assertNull(m);

   // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
   // point
   // which can cause delivering count to flip to 1

}
 
示例20
@Test
public void testPreCommitAcksWithMessageExpirySetOnConnectionFactory() throws Exception {
   ((ActiveMQConnectionFactory) cf).setPreAcknowledge(true);
   conn = cf.createConnection();
   Session session = conn.createSession(false, Session.CLIENT_ACKNOWLEDGE);
   jBossQueue = ActiveMQJMSClient.createQueue(JmsConsumerTest.Q_NAME);
   MessageProducer producer = session.createProducer(jBossQueue);
   MessageConsumer consumer = session.createConsumer(jBossQueue);
   int noOfMessages = 1000;
   for (int i = 0; i < noOfMessages; i++) {
      TextMessage textMessage = session.createTextMessage("m" + i);
      producer.setTimeToLive(1);
      producer.send(textMessage);
   }

   Thread.sleep(2);

   conn.start();
   Message m = consumer.receiveNoWait();
   Assert.assertNull(m);

   // Asserting delivering count is zero is bogus since messages might still be being delivered and expired at this
   // point
   // which can cause delivering count to flip to 1
}
 
示例21
@Test
public void testSharedConsumer() throws Exception {
   conn = cf.createConnection();
   conn.start();
   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   topic = ActiveMQJMSClient.createTopic(T_NAME);

   MessageConsumer cons = session.createSharedConsumer(topic, "test1");

   MessageProducer producer = session.createProducer(topic);

   producer.send(session.createTextMessage("test"));

   TextMessage txt = (TextMessage) cons.receive(5000);

   Assert.assertNotNull(txt);
}
 
示例22
@Test
public void testSharedDurableConsumer() throws Exception {
   conn = cf.createConnection();
   conn.start();
   Session session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
   topic = ActiveMQJMSClient.createTopic(T_NAME);

   MessageConsumer cons = session.createSharedDurableConsumer(topic, "test1");

   MessageProducer producer = session.createProducer(topic);

   producer.send(session.createTextMessage("test"));

   TextMessage txt = (TextMessage) cons.receive(5000);

   Assert.assertNotNull(txt);
}
 
示例23
@Override
protected ConnectionFactory getCF() throws Exception {
   ActiveMQJMSConnectionFactory cf1 = (ActiveMQJMSConnectionFactory) ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));

   cf1.setAutoGroup(true);

   return cf1;
}
 
示例24
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   cf = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, new TransportConfiguration(INVM_CONNECTOR_FACTORY));
}
 
示例25
public ConnectionFactoryFactory getConnectionFactoryFactory() {
   ConnectionFactoryFactory cff = new ConnectionFactoryFactory() {
      @Override
      public ConnectionFactory createConnectionFactory() throws Exception {
         ActiveMQConnectionFactory cf = ActiveMQJMSClient.createConnectionFactoryWithHA(JMSFactoryType.XA_CF, liveConnector);
         cf.getServerLocator().setReconnectAttempts(15);
         return cf;
      }
   };

   return cff;
}
 
示例26
public SimpleMessageListener start() throws Exception {
   Queue requestQueue = ActiveMQJMSClient.createQueue("exampleQueue");
   ConnectionFactory cf = new ActiveMQConnectionFactory("tcp://localhost:61617");
   connection = cf.createConnection("guest", "guest");
   session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   connection.start();
   replyProducer = session.createProducer(null);
   requestConsumer = session.createConsumer(requestQueue);
   requestConsumer.setMessageListener(this);
   return this;
}
 
示例27
@Test
public void testSimpleMessageSendAndReceive() throws Exception {
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
}
 
示例28
@Test
public void testConnectionFactoryPropertiesApplyToRecoveryConfig() throws Exception {
   ServerLocator locator = createInVMNonHALocator();
   ClientSessionFactory factory = locator.createSessionFactory();
   ClientSession session = factory.createSession(false, false, false);
   ActiveMQDestination queue = (ActiveMQDestination) ActiveMQJMSClient.createQueue("test");
   session.createQueue(new QueueConfiguration(queue.getSimpleAddress()));
   session.close();

   ActiveMQResourceAdapter ra = new ActiveMQResourceAdapter();

   ra.setConnectorClassName(INVM_CONNECTOR_FACTORY);
   ra.setUserName("userGlobal");
   ra.setPassword("passwordGlobal");
   ra.setConnectionTTL(100L);
   ra.setCallFailoverTimeout(100L);
   ra.start(new BootstrapContext());

   Set<XARecoveryConfig> resources = ra.getRecoveryManager().getResources();
   assertEquals(100L, ra.getDefaultActiveMQConnectionFactory().getServerLocator().getConnectionTTL());
   assertEquals(100L, ra.getDefaultActiveMQConnectionFactory().getServerLocator().getCallFailoverTimeout());


   for (XARecoveryConfig resource : resources) {
      assertEquals(100L, resource.createServerLocator().getConnectionTTL());
      assertEquals(100L, resource.createServerLocator().getCallFailoverTimeout());
   }

   ra.stop();
   assertEquals(0, resources.size());
   locator.close();

}
 
示例29
@Test
public void testSimpleMessageSendAndReceive() throws Exception {
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
}
 
示例30
@Test
public void testAcceptJMSException() throws Exception {
   ActiveMQConnectionFactory connectionFactory = ActiveMQJMSClient.createConnectionFactory("vm://0", "0");
   Connection connection = connectionFactory.createConnection();
   Session session = connection.createSession();
   Queue queue = session.createQueue(ADDRESS.toString());
   MessageProducer producer = session.createProducer(queue);
   Message message = session.createMessage();
   message.setStringProperty("JMSXUserID", "testuser");
   producer.send(message);
}