當前位置: 首頁>>代碼示例>>Java>>正文


Java TopicSession.close方法代碼示例

本文整理匯總了Java中javax.jms.TopicSession.close方法的典型用法代碼示例。如果您正苦於以下問題:Java TopicSession.close方法的具體用法?Java TopicSession.close怎麽用?Java TopicSession.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.jms.TopicSession的用法示例。


在下文中一共展示了TopicSession.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testWithSessionCloseOutsideTheLoop

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testWithSessionCloseOutsideTheLoop() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      for (int i = 0; i < 100; i++) {

         TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
         DummyMessageListener listener = new DummyMessageListener();
         subscriber.setMessageListener(listener);
         subscriber.close();
      }
      subscriberSession.close();
      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());

   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:21,代碼來源:NetworkRemovesSubscriptionsTest.java

示例2: initializeInboundDestinationBridgesOutboundSide

import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException {
    if (inboundTopicBridges != null) {
        TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        for (InboundTopicBridge bridge : inboundTopicBridges) {
            String TopicName = bridge.getInboundTopicName();
            Topic foreignTopic = createForeignTopic(outboundSession, TopicName);
            bridge.setConsumer(null);
            bridge.setConsumerTopic(foreignTopic);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        outboundSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:17,代碼來源:SimpleJmsTopicConnector.java

示例3: initializeInboundDestinationBridgesLocalSide

import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException {
    if (inboundTopicBridges != null) {
        TopicSession localSession = connection.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);

        for (InboundTopicBridge bridge : inboundTopicBridges) {
            String localTopicName = bridge.getLocalTopicName();
            Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
            bridge.setProducerTopic(activemqTopic);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getInboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        localSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:19,代碼來源:SimpleJmsTopicConnector.java

示例4: initializeOutboundDestinationBridgesOutboundSide

import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesOutboundSide(TopicConnection connection) throws JMSException {
    if (outboundTopicBridges != null) {
        TopicSession outboundSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundTopicBridge bridge : outboundTopicBridges) {
            String topicName = bridge.getOutboundTopicName();
            Topic foreignTopic = createForeignTopic(outboundSession, topicName);
            bridge.setProducerTopic(foreignTopic);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getOutboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        outboundSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:19,代碼來源:SimpleJmsTopicConnector.java

示例5: initializeOutboundDestinationBridgesLocalSide

import javax.jms.TopicSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesLocalSide(TopicConnection connection) throws JMSException {
    if (outboundTopicBridges != null) {
        TopicSession localSession =
                connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundTopicBridge bridge : outboundTopicBridges) {
            String localTopicName = bridge.getLocalTopicName();
            Topic activemqTopic = createActiveMQTopic(localSession, localTopicName);
            bridge.setConsumer(null);
            bridge.setConsumerTopic(activemqTopic);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        localSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:18,代碼來源:SimpleJmsTopicConnector.java

示例6: publishMessagesToTopic

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * To publish the messages to a topic.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void publishMessagesToTopic(String topicName) throws JMSException, InterruptedException {
    TopicConnection topicConnection = (TopicConnection) connectionFactory.createConnection();
    topicConnection.start();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = topicSession.createTopic(topicName);
    MessageProducer topicSender = topicSession.createProducer(destination);
    topicSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    for (int index = 0; index < 10; index++) {
        String topicText = "Topic Message : " + (index + 1);
        TextMessage topicMessage = topicSession.createTextMessage(topicText);
        topicSender.send(topicMessage);
        logger.info("Publishing " + topicText + " to topic " + topicName);
        Thread.sleep(1000);
    }
    topicConnection.close();
    topicSession.close();
    topicSender.close();
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:25,代碼來源:JMSServer.java

示例7: testWithSessionAndSubsciberClose

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testWithSessionAndSubsciberClose() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();

      for (int i = 0; i < 100; i++) {
         TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
         TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
         DummyMessageListener listener = new DummyMessageListener();
         subscriber.setMessageListener(listener);
         subscriber.close();
         subscriberSession.close();
      }
      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());
   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:20,代碼來源:NetworkRemovesSubscriptionsTest.java

示例8: testWithOneSubscriber

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testWithOneSubscriber() throws Exception {

      TopicConnection connection = connectionFactory.createTopicConnection();
      connection.start();
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);

      TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
      DummyMessageListener listener = new DummyMessageListener();
      subscriber.setMessageListener(listener);
      subscriber.close();
      subscriberSession.close();
      connection.close();
      Thread.sleep(1000);
      Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
      assertNotNull(dest);
      assertTrue(dest.getConsumers().isEmpty());
   }
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:18,代碼來源:NetworkRemovesSubscriptionsTest.java

示例9: testWithoutSessionAndSubsciberClosePlayAround

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Running this test you can produce a leak of only 2 ConsumerInfo on BE
 * broker, NOT 200 as in other cases!
 */
public void testWithoutSessionAndSubsciberClosePlayAround() throws Exception {

   TopicConnection connection = connectionFactory.createTopicConnection();
   connection.start();

   for (int i = 0; i < 100; i++) {
      TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      TopicSubscriber subscriber = subscriberSession.createSubscriber(topic);
      DummyMessageListener listener = new DummyMessageListener();
      subscriber.setMessageListener(listener);
      if (i != 50) {
         subscriber.close();
         subscriberSession.close();
      }
   }

   connection.close();
   Thread.sleep(1000);
   Destination dest = backEnd.getRegionBroker().getDestinationMap().get(topic);
   assertNotNull(dest);
   assertTrue(dest.getConsumers().isEmpty());
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:27,代碼來源:NetworkRemovesSubscriptionsTest.java

示例10: testSubscriberPublisher

import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({ "broker-port"})
@Test
public void testSubscriberPublisher(String port) throws Exception {
    String topicName = "MyTopic1";
    int numberOfMessages = 100;

    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .withTopic(topicName)
            .build();

    TopicConnectionFactory connectionFactory
            = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();

    // Initialize subscriber
    TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic subscriberDestination = (Topic) initialContext.lookup(topicName);
    TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination);

    // publish 100 messages
    TopicSession producerSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher producer = producerSession.createPublisher(subscriberDestination);

    for (int i = 0; i < numberOfMessages; i++) {
        producer.publish(producerSession.createTextMessage("Test message " + i));
    }

    producerSession.close();

    for (int i = 0; i < numberOfMessages; i++) {
        Message message = subscriber.receive(1000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }

    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:39,代碼來源:TopicSubscriberTest.java

示例11: closeResources

import javax.jms.TopicSession; //導入方法依賴的package包/類
private static void closeResources(TopicConnection pConn, TopicSession pSession,
        TopicPublisher pPublisher) throws JMSException {
    if (pPublisher != null) {
        pPublisher.close();
    }
    if (pSession != null) {
        pSession.close();
    }
    if (pConn != null) {
        pConn.close();
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:13,代碼來源:JMSServices.java

示例12: testTemporarySubscriptionDeleted

import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTemporarySubscriptionDeleted() throws Exception {
   Connection connection = createConnection();

   try {
      TopicSession session = (TopicSession) connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(getTopicName());
      TopicSubscriber myNonDurSub = session.createSubscriber(topic);
      assertNotNull(myNonDurSub);

      Bindings bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
      Assert.assertEquals(2, bindingsForAddress.getBindings().size());
      session.close();

      final CountDownLatch latch = new CountDownLatch(1);
      server.getRemotingService().getConnections().iterator().next().addCloseListener(new CloseListener() {
         @Override
         public void connectionClosed() {
            latch.countDown();
         }
      });

      connection.close();
      latch.await(5, TimeUnit.SECONDS);
      bindingsForAddress = server.getPostOffice().getBindingsForAddress(new SimpleString(getTopicName()));
      Assert.assertEquals(1, bindingsForAddress.getBindings().size());
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:31,代碼來源:JMSTopicConsumerTest.java

示例13: close

import javax.jms.TopicSession; //導入方法依賴的package包/類
private void close(TopicSession session) {
    if (session != null) {
        try {
            session.close();
        } catch (JMSException e) {
            LOG.error("Couldn't close TopicSession", e);
        }
    }
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:10,代碼來源:JobMessageSenderImpl.java

示例14: testPositiveJMSSelectorConsumerProducer

import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testPositiveJMSSelectorConsumerProducer(String port,
                                                    String adminUsername,
                                                    String adminPassword,
                                                    String brokerHostname) throws NamingException, JMSException {
    String queueName = "testPositiveJMSSelectorConsumerProducer";
    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withTopic(queueName)
            .build();


    TopicConnectionFactory connectionFactory
            = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();

    TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) initialContext.lookup(queueName);

    // Subscribe with a selector
    String propertyName = "MyProperty";
    String propertyValue = "propertyValue";
    String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
    TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);

    // publish messages with property
    TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
    TopicPublisher producer = producerSession.createPublisher(topic);

    int numberOfMessages = 100;
    for (int i = 0; i < numberOfMessages; i++) {
        TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
        textMessage.setStringProperty(propertyName, propertyValue);
        producer.send(textMessage);
    }

    // consume messages
    for (int i = 0; i < numberOfMessages; i++) {
        Message message = consumer.receive(1000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }

    producerSession.close();
    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:48,代碼來源:JMSSelectorTest.java

示例15: testNegativeJMSSelectorConsumerProducer

import javax.jms.TopicSession; //導入方法依賴的package包/類
@Parameters({"broker-port", "admin-username", "admin-password", "broker-hostname"})
@Test
public void testNegativeJMSSelectorConsumerProducer(String port,
                                                    String adminUsername,
                                                    String adminPassword,
                                                    String brokerHostname) throws NamingException, JMSException {
    String queueName = "testNegativeJMSSelectorConsumerProducer";
    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withTopic(queueName)
            .build();

    TopicConnectionFactory connectionFactory
            = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();

    TopicSession subscriberSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
    Topic topic = (Topic) initialContext.lookup(queueName);

    // Subscribe with a selector
    String propertyName = "MyProperty";
    String propertyValue = "propertyValue";
    String jmsPropertySelector = propertyName + " = '" + propertyValue + "'";
    TopicSubscriber consumer = subscriberSession.createSubscriber(topic, jmsPropertySelector, false);

    // publish messages with property
    TopicSession producerSession = connection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
    TopicPublisher producer = producerSession.createPublisher(topic);

    // Send messages with a different property value
    int numberOfMessages = 100;
    for (int i = 0; i < numberOfMessages; i++) {
        TextMessage textMessage = producerSession.createTextMessage("Test message " + i);
        textMessage.setStringProperty(propertyName, propertyValue + "-1");
        producer.send(textMessage);
    }

    // consume messages
    Message message = consumer.receive(100);
    Assert.assertNull(message, "Message received. Shouldn't receive any messages.");

    producerSession.close();
    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:46,代碼來源:JMSSelectorTest.java


注:本文中的javax.jms.TopicSession.close方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。