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


Java QueueConnection.createSession方法代碼示例

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


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

示例1: testMultipleSessionsThrowsException

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testMultipleSessionsThrowsException() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   try {
      Session s2 = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      fail("should throw javax,jms.IllegalStateException: Only allowed one session per connection. See the J2EE spec, e.g. J2EE1.4 Section 6.6");
   } catch (JMSException e) {
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:17,代碼來源:OutgoingConnectionTest.java

示例2: testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:40,代碼來源:SingleConnectionFactoryTests.java

示例3: testSimpleMessageSendAndReceiveTransacted

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSimpleMessageSendAndReceiveTransacted() throws Exception {
   setDummyTX();
   setupDLQ(10);
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(true, 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);
   s.commit();
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.rollback();
   textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.commit();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:29,代碼來源:OutgoingConnectionJTATest.java

示例4: testSimpleMessageSendAndReceive

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@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");
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:15,代碼來源:OutgoingConnectionJTATest.java

示例5: testSimpleMessageSendAndReceiveSessionTransacted

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSimpleMessageSendAndReceiveSessionTransacted() throws Exception {
   setupDLQ(10);
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setAllowLocalTransactions(true);
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(true, Session.SESSION_TRANSACTED);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   s.commit();
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.rollback();
   textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.commit();
   textMessage = (TextMessage) consumer.receiveNoWait();
   assertNull(textMessage);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:31,代碼來源:OutgoingConnectionNoJTATest.java

示例6: testSimpleMessageSendAndReceiveNotTransacted

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSimpleMessageSendAndReceiveNotTransacted() throws Exception {
   setupDLQ(10);
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setAllowLocalTransactions(true);
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   s.commit();
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.rollback();
   textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.commit();
   textMessage = (TextMessage) consumer.receiveNoWait();
   assertNull(textMessage);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:31,代碼來源:OutgoingConnectionNoJTATest.java

示例7: testSimpleMessageSendAndReceiveSessionTransacted2

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSimpleMessageSendAndReceiveSessionTransacted2() throws Exception {
   setupDLQ(10);
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setAllowLocalTransactions(true);
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(Session.SESSION_TRANSACTED);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   s.commit();
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.rollback();
   textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
   s.commit();
   textMessage = (TextMessage) consumer.receiveNoWait();
   assertNull(textMessage);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:31,代碼來源:OutgoingConnectionNoJTATest.java

示例8: testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();  // should be ignored
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();  // should be ignored
	con1.start();
	con1.close();  // should be ignored
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();  // should be ignored
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:40,代碼來源:SingleConnectionFactoryTests.java

示例9: testSharedActiveMQConnectionFactory

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSharedActiveMQConnectionFactory() throws Exception {
   Session s = null;
   Session s2 = null;
   ActiveMQRAManagedConnection mc = null;
   ActiveMQRAManagedConnection mc2 = null;

   try {
      resourceAdapter = new ActiveMQResourceAdapter();

      resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
      MyBootstrapContext ctx = new MyBootstrapContext();
      resourceAdapter.start(ctx);
      ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
      ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
      mcf.setResourceAdapter(resourceAdapter);
      ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);

      QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
      s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();
      ActiveMQConnectionFactory cf1 = mc.getConnectionFactory();

      QueueConnection queueConnection2 = qraConnectionFactory.createQueueConnection();
      s2 = queueConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      mc2 = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s2).getManagedConnection();
      ActiveMQConnectionFactory cf2 = mc2.getConnectionFactory();

      // we're not testing equality so don't use equals(); we're testing if they are actually the *same* object
      assertTrue(cf1 == cf2);
   } finally {
      if (s != null) {
         s.close();
      }

      if (mc != null) {
         mc.destroy();
      }

      if (s2 != null) {
         s2.close();
      }

      if (mc2 != null) {
         mc2.destroy();
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:49,代碼來源:OutgoingConnectionTest.java

示例10: testSharedActiveMQConnectionFactoryWithClose

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testSharedActiveMQConnectionFactoryWithClose() throws Exception {
   Session s = null;
   Session s2 = null;
   ActiveMQRAManagedConnection mc = null;
   ActiveMQRAManagedConnection mc2 = null;

   try {
      server.getConfiguration().setSecurityEnabled(false);
      resourceAdapter = new ActiveMQResourceAdapter();

      resourceAdapter.setConnectorClassName(InVMConnectorFactory.class.getName());
      MyBootstrapContext ctx = new MyBootstrapContext();
      resourceAdapter.start(ctx);
      ActiveMQRAConnectionManager qraConnectionManager = new ActiveMQRAConnectionManager();
      ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
      mcf.setResourceAdapter(resourceAdapter);
      ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);

      QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
      s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      mc = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s).getManagedConnection();

      QueueConnection queueConnection2 = qraConnectionFactory.createQueueConnection();
      s2 = queueConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
      mc2 = (ActiveMQRAManagedConnection) ((ActiveMQRASession) s2).getManagedConnection();

      mc.destroy();

      MessageProducer producer = s2.createProducer(ActiveMQJMSClient.createQueue(MDBQUEUE));
      producer.send(s2.createTextMessage("x"));
   } finally {
      if (s != null) {
         s.close();
      }

      if (mc != null) {
         mc.destroy();
      }

      if (s2 != null) {
         s2.close();
      }

      if (mc2 != null) {
         mc2.destroy();
      }
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:50,代碼來源:OutgoingConnectionTest.java

示例11: testQueueSessionAckMode

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testQueueSessionAckMode() throws Exception {

   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();

   Session s = queueConnection.createSession(false, Session.SESSION_TRANSACTED);

   s.close();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:10,代碼來源:OutgoingConnectionNoJTATest.java


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