当前位置: 首页>>代码示例>>Java>>正文


Java Connection.close方法代码示例

本文整理汇总了Java中javax.jms.Connection.close方法的典型用法代码示例。如果您正苦于以下问题:Java Connection.close方法的具体用法?Java Connection.close怎么用?Java Connection.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.jms.Connection的用法示例。


在下文中一共展示了Connection.close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putTopic

import javax.jms.Connection; //导入方法依赖的package包/类
private void putTopic(List<String> events) throws Exception {
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  Connection connection = factory.createConnection();
  connection.start();

  Session session = connection.createSession(true,
      Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createTopic(DESTINATION_NAME);
  MessageProducer producer = session.createProducer(destination);

  for (String event : events) {
    TextMessage message = session.createTextMessage();
    message.setText(event);
    producer.send(message);
  }
  session.commit();
  session.close();
  connection.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestIntegrationActiveMQ.java

示例2: testFailedCreateConsumerConnectionStillWorks

import javax.jms.Connection; //导入方法依赖的package包/类
@Test
public void testFailedCreateConsumerConnectionStillWorks() throws JMSException {
    Connection connection = pooledConnFact.createConnection("guest", "password");
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(name.getMethodName());

    try {
        session.createConsumer(queue);
        fail("Should fail to create consumer");
    } catch (JMSSecurityException ex) {
        LOG.info("Caught expected security error");
    }

    queue = session.createQueue("GUESTS." + name.getMethodName());

    MessageProducer producer = session.createProducer(queue);
    producer.close();

    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:23,代码来源:PooledConnectionSecurityExceptionTest.java

示例3: receiveAndRespondWithMessageIdAsCorrelationId

import javax.jms.Connection; //导入方法依赖的package包/类
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
    final javax.jms.Message inMessage = consumer.receive();

    String requestMessageId = inMessage.getJMSMessageID();
    LOG.debug("Received message " + requestMessageId);
    final TextMessage replyMessage = session.createTextMessage("Result");
    replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
    final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
    LOG.debug("Sending reply to " + inMessage.getJMSReplyTo());
    producer.send(replyMessage);

    producer.close();
    consumer.close();
    session.close();
    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:PooledConnectionTempQueueTest.java

示例4: testSetClientIDTwiceWithSameID

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDTwiceWithSameID() throws Exception {
    LOG.debug("running testRepeatedSetClientIDCalls()");

    // test: call setClientID("newID") twice
    // this should be tolerated and not result in an exception
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    Connection conn = cf.createConnection();
    conn.setClientID("newID");

    try {
        conn.setClientID("newID");
        conn.start();
        conn.close();
    } catch (IllegalStateException ise) {
        LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
        fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
    } finally {
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:24,代码来源:PooledConnectionTest.java

示例5: testSetClientIDAfterConnectionStart

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDAfterConnectionStart() throws Exception {
    Connection connection = cf.createConnection();

    // test: try to call setClientID() after start()
    // should result in an exception
    try {
        connection.start();
        connection.setClientID("newID3");
        fail("Calling setClientID() after start() mut raise a JMSException.");
    } catch (IllegalStateException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        connection.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:JmsPoolConnectionTest.java

示例6: testFailedConnectThenSucceeds

import javax.jms.Connection; //导入方法依赖的package包/类
@Test
public void testFailedConnectThenSucceeds() throws JMSException {
    Connection connection = pooledConnFact.createConnection("invalid", "credentials");

    try {
        connection.start();
        fail("Should fail to connect");
    } catch (JMSSecurityException ex) {
        LOG.info("Caught expected security error");
    }

    connection = pooledConnFact.createConnection("system", "manager");
    connection.start();

    LOG.info("Successfully create new connection.");

    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:19,代码来源:PooledConnectionSecurityExceptionTest.java

示例7: testSetClientIDTwiceWithDifferentID

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDTwiceWithDifferentID() throws Exception {
    Connection conn = cf.createConnection();

    // test: call setClientID() twice with different IDs
    // this should result in an IllegalStateException
    conn.setClientID("newID1");
    try {
        conn.setClientID("newID2");
        fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException");
    } catch (IllegalStateException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        conn.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:PooledConnectionTest.java

示例8: testSetClientIDAfterConnectionStart

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDAfterConnectionStart() throws Exception {
    Connection conn = cf.createConnection();

    // test: try to call setClientID() after start()
    // should result in an exception
    try {
        conn.start();
        conn.setClientID("newID3");
        fail("Calling setClientID() after start() mut raise a JMSException.");
    } catch (IllegalStateException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        conn.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:PooledConnectionTest.java

示例9: testSetClientIDTwiceWithDifferentID

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDTwiceWithDifferentID() throws Exception {
    LOG.debug("running testRepeatedSetClientIDCalls()");

    JmsPoolConnectionFactory cf = createPooledConnectionFactory();
    Connection conn = cf.createConnection();

    // test: call setClientID() twice with different IDs
    // this should result in an IllegalStateException
    conn.setClientID("newID1");
    try {
        conn.setClientID("newID2");
        fail("calling Connection.setClientID() twice with different clientID must raise an IllegalStateException");
    } catch (IllegalStateException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        conn.close();
        cf.stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:23,代码来源:PooledConnectionTest.java

示例10: testConsumerProducerWithAutoAck

import javax.jms.Connection; //导入方法依赖的package包/类
@Parameters({ "broker-port"})
@Test
public void testConsumerProducerWithAutoAck(String port) throws Exception {
    String queueName = "testConsumerProducerWithAutoAck";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish 100 messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

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

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

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

    connection.close();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:38,代码来源:QueueConsumerTest.java

示例11: main

import javax.jms.Connection; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {
            // Create a ConnectionFactory
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");

            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("HELLOWORLD.TESTQ");

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            // Create a messages
            String text = "Hello world! From: " + Thread.currentThread().getName();
            TextMessage message = session.createTextMessage(text);

            // Tell the producer to send the message
            System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
            producer.send(message);

            // Clean up
            session.close();
            connection.close();
        }
        catch (Exception e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
        }
    
	}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:39,代码来源:HelloWorldProducer.java

示例12: testEvictionOfExpired

import javax.jms.Connection; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testEvictionOfExpired() throws Exception {
    pooledFactory.setExpiryTimeout(10);
    Connection connection = pooledFactory.createConnection();
    Connection amq1 = ((JmsPoolConnection) connection).getConnection();

    // let it expire while in use
    TimeUnit.MILLISECONDS.sleep(20);
    connection.close();

    Connection connection2 = pooledFactory.createConnection();
    Connection amq2 = ((JmsPoolConnection) connection2).getConnection();
    assertTrue("not equal", !amq1.equals(amq2));
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:15,代码来源:PooledConnectionExpiryEvictsFromPoolTest.java

示例13: main

import javax.jms.Connection; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {

            // Create a ConnectionFactory
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");

            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();


            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("HELLOWORLD.TESTQ");

            // Create a MessageConsumer from the Session to the Topic or Queue
            MessageConsumer consumer = session.createConsumer(destination);

            // Wait for a message
            Message message = consumer.receive(1000);

            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                String text = textMessage.getText();
                System.out.println("Received: " + text);
            } else {
                System.out.println("Received: " + message);
            }

            consumer.close();
            session.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
	}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:41,代码来源:HelloWorldConsumer.java

示例14: safeCloseConnection

import javax.jms.Connection; //导入方法依赖的package包/类
private void safeCloseConnection(Connection connection) {
	try {
		if (connection != null) {
			connection.stop();
			//only close if there isn't liveConnection
			if (!keepAlive) {
				connection.close();
			}
		}
	} catch (JMSException e) {
		LOGGER.debug("Error while disconnecting", e);
	}
}
 
开发者ID:xtf-cz,项目名称:xtf,代码行数:14,代码来源:JmsClient.java

示例15: testConsumerProducerWithSsl

import javax.jms.Connection; //导入方法依赖的package包/类
@Parameters({ "broker-ssl-port"})
@Test
public void testConsumerProducerWithSsl(String port) throws Exception {
    String queueName = "testConsumerProducerWithAutoAck";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .enableSsl()
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish 100 messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

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

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

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

    connection.close();
}
 
开发者ID:wso2,项目名称:message-broker,代码行数:39,代码来源:SslTransportTest.java


注:本文中的javax.jms.Connection.close方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。