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


Java TopicSession.commit方法代碼示例

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


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

示例1: testPersistentMessagesForTopicDropped

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Topics shouldn't hold on to messages if there are no subscribers
 */
@Test
public void testPersistentMessagesForTopicDropped() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   pub.setDeliveryMode(DeliveryMode.PERSISTENT);

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   topicConn.close();

   checkEmpty(ActiveMQServerTestCase.topic1);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:19,代碼來源:AcknowledgementTest.java

示例2: testPersistentMessagesForTopicDropped2

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Topics shouldn't hold on to messages when the non-durable subscribers close
 */
@Test
public void testPersistentMessagesForTopicDropped2() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   topicConn.start();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   TopicSubscriber sub = sess.createSubscriber(ActiveMQServerTestCase.topic1);
   pub.setDeliveryMode(DeliveryMode.PERSISTENT);

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   // receive but rollback
   TextMessage m2 = (TextMessage) sub.receive(3000);

   ProxyAssertSupport.assertNotNull(m2);
   ProxyAssertSupport.assertEquals("testing123", m2.getText());

   sess.rollback();

   topicConn.close();

   checkEmpty(ActiveMQServerTestCase.topic1);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:29,代碼來源:AcknowledgementTest.java

示例3: testSendingSameMessage

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testSendingSameMessage() throws Exception
{
    AMQConnection conn = (AMQConnection) getConnection("guest", "guest");
    TopicSession session = conn.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic topic = session.createTemporaryTopic();
    assertNotNull(topic);
    TopicPublisher producer = session.createPublisher(topic);
    MessageConsumer consumer = session.createConsumer(topic);
    conn.start();
    TextMessage sentMessage = session.createTextMessage("Test Message");
    producer.send(sentMessage);
    session.commit();
    TextMessage receivedMessage = (TextMessage) consumer.receive(2000);
    assertNotNull(receivedMessage);
    assertEquals(sentMessage.getText(), receivedMessage.getText());
    producer.send(sentMessage);
    session.commit();
    receivedMessage = (TextMessage) consumer.receive(2000);
    assertNotNull(receivedMessage);
    assertEquals(sentMessage.getText(), receivedMessage.getText());
    session.commit();
    conn.close();

}
 
開發者ID:wso2,項目名稱:andes,代碼行數:25,代碼來源:TopicSessionTest.java

示例4: createTopic

import javax.jms.TopicSession; //導入方法依賴的package包/類
public static Topic createTopic(String uri, String topicName) throws JMSException {
	TopicConnectionFactory connectionFactory = null;
	TopicConnection connection = null;
	TopicSession session = null;
	Topic topic = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createTopicConnection();
		connection.start();
		session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		topic = session.createTopic(topicName);
		session.commit();
	} finally {
		closeQuietly(session);
		closeQuietly(connection);
	}
	return topic;
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:19,代碼來源:MsgUtils.java

示例5: publishTextMsg2Topic

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * Product message for assigned topic.
 * 
 * @param uri
 *            e.g.: tcp://3CNL12096:61616
 * @param queueName
 *            name of queue
 * @throws JMSException
 */
public static void publishTextMsg2Topic(String uri, String topicName, String text) throws JMSException {
	TopicConnectionFactory connectionFactory = null;
	TopicConnection connection = null;
	TopicSession session = null;
	TopicPublisher tp = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createTopicConnection();
		connection.start();
		session = connection.createTopicSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		tp = session.createPublisher(session.createTopic(topicName));
		tp.setDeliveryMode(DeliveryMode.PERSISTENT);
		tp.publish(session.createTextMessage(text));
		session.commit();
	} finally {
		closeQuietly(tp);
		closeQuietly(session);
		closeQuietly(connection);
	}
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:30,代碼來源:MsgUtils.java

示例6: testUnsubscriptionAfterConnectionClose

import javax.jms.TopicSession; //導入方法依賴的package包/類
public void testUnsubscriptionAfterConnectionClose() throws Exception
{
    AMQConnection con1 = (AMQConnection) getClientConnection("guest", "guest", "clientid");
    AMQTopic topic = new AMQTopic(con1, "MyTopic3");

    TopicSession session1 = con1.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
    TopicPublisher publisher = session1.createPublisher(topic);

    AMQConnection con2 = (AMQConnection) getClientConnection("guest", "guest", "clientid");
    TopicSession session2 = con2.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = session2.createDurableSubscriber(topic, "subscription0");

    con2.start();

    publisher.publish(session1.createTextMessage("Hello"));
    session1.commit();
    TextMessage tm = (TextMessage) sub.receive(2000);
    session2.commit();
    assertNotNull(tm);
    con2.close();
    publisher.publish(session1.createTextMessage("Hello2"));
    session1.commit();
    con2 =  (AMQConnection) getClientConnection("guest", "guest", "clientid");
    session2 = con2.createTopicSession(true, AMQSession.NO_ACKNOWLEDGE);
    sub = session2.createDurableSubscriber(topic, "subscription0");
    con2.start();
    tm = (TextMessage) sub.receive(2000);
    session2.commit();
    assertNotNull(tm);
    assertEquals("Hello2", tm.getText());
    session2.unsubscribe("subscription0");
    con1.close();
    con2.close();
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:35,代碼來源:TopicSessionTest.java

示例7: subscribeTopic

import javax.jms.TopicSession; //導入方法依賴的package包/類
public static TopicSubscriber subscribeTopic(TopicSession session, String topicName, String subscriberName, boolean durable, MessageListener listener)
		throws JMSException {
	TopicSubscriber ts = null;
	if (durable)
		ts = session.createDurableSubscriber(session.createTopic(topicName), subscriberName);
	else
		ts = session.createSubscriber(session.createTopic(topicName));
	ts.setMessageListener(listener);
	session.commit();
	return ts;
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:12,代碼來源:MsgUtils.java

示例8: testRollbackRecover

import javax.jms.TopicSession; //導入方法依賴的package包/類
@Test
public void testRollbackRecover() throws Exception {
   TopicConnection topicConn = createTopicConnection();
   TopicSession sess = topicConn.createTopicSession(true, 0);
   TopicPublisher pub = sess.createPublisher(ActiveMQServerTestCase.topic1);
   TopicSubscriber cons = sess.createSubscriber(ActiveMQServerTestCase.topic1);
   topicConn.start();

   Message m = sess.createTextMessage("testing123");
   pub.publish(m);
   sess.commit();

   TextMessage m2 = (TextMessage) cons.receive(3000);
   ProxyAssertSupport.assertNotNull(m2);
   ProxyAssertSupport.assertEquals("testing123", m2.getText());

   sess.rollback();

   m2 = (TextMessage) cons.receive(3000);
   ProxyAssertSupport.assertNotNull(m2);
   ProxyAssertSupport.assertEquals("testing123", m2.getText());

   topicConn.close();

   topicConn = createTopicConnection();
   topicConn.start();

   // test 2

   TopicSession newsess = topicConn.createTopicSession(true, 0);
   TopicPublisher newpub = newsess.createPublisher(ActiveMQServerTestCase.topic1);
   TopicSubscriber newcons = newsess.createSubscriber(ActiveMQServerTestCase.topic1);

   Message m3 = newsess.createTextMessage("testing456");
   newpub.publish(m3);
   newsess.commit();

   TextMessage m4 = (TextMessage) newcons.receive(3000);
   ProxyAssertSupport.assertNotNull(m4);
   ProxyAssertSupport.assertEquals("testing456", m4.getText());

   newsess.commit();

   newpub.publish(m3);
   newsess.commit();

   TextMessage m5 = (TextMessage) newcons.receive(3000);
   ProxyAssertSupport.assertNotNull(m5);
   ProxyAssertSupport.assertEquals("testing456", m5.getText());

   newsess.rollback();

   TextMessage m6 = (TextMessage) newcons.receive(3000);
   ProxyAssertSupport.assertNotNull(m6);
   ProxyAssertSupport.assertEquals("testing456", m6.getText());

   newsess.commit();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:59,代碼來源:AcknowledgementTest.java

示例9: subscriptionNameReuseForDifferentTopic

import javax.jms.TopicSession; //導入方法依賴的package包/類
private void subscriptionNameReuseForDifferentTopic(boolean shutdown) throws Exception
{
    AMQConnection con = (AMQConnection) getConnection("guest", "guest");
    AMQTopic topic = new AMQTopic(con, "MyTopic1" + String.valueOf(shutdown));
    AMQTopic topic2 = new AMQTopic(con, "MyOtherTopic1" + String.valueOf(shutdown));

    TopicSession session1 = con.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = session1.createDurableSubscriber(topic, "subscription0");
    TopicPublisher publisher = session1.createPublisher(null);

    con.start();

    publisher.publish(topic, session1.createTextMessage("hello"));
    session1.commit();
    TextMessage m = (TextMessage) sub.receive(2000);
    assertNotNull(m);
    session1.commit();

    if (shutdown)
    {
        session1.close();
        con.close();
        con =  (AMQConnection) getConnection("guest", "guest");
        con.start();
        session1 = con.createTopicSession(true, AMQSession.NO_ACKNOWLEDGE);
        publisher = session1.createPublisher(null);
    }
    sub.close();
    TopicSubscriber sub2 = session1.createDurableSubscriber(topic2, "subscription0");
    publisher.publish(topic, session1.createTextMessage("hello"));
    session1.commit();
    if (!shutdown)
    {
        m = (TextMessage) sub2.receive(2000);
        assertNull(m);
        session1.commit();
    }
    publisher.publish(topic2, session1.createTextMessage("goodbye"));
    session1.commit();
    m = (TextMessage) sub2.receive(2000);
    assertNotNull(m);
    assertEquals("goodbye", m.getText());
    session1.unsubscribe("subscription0");
    con.close();
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:46,代碼來源:TopicSessionTest.java

示例10: testTextMessageCreation

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

    AMQConnection con = (AMQConnection) getConnection("guest", "guest");
    AMQTopic topic = new AMQTopic(con, "MyTopic4");
    TopicSession session1 = con.createTopicSession(true, AMQSession.AUTO_ACKNOWLEDGE);
    TopicPublisher publisher = session1.createPublisher(topic);
    MessageConsumer consumer1 = session1.createConsumer(topic);
    con.start();
    TextMessage tm = session1.createTextMessage("Hello");
    publisher.publish(tm);
    session1.commit();
    tm = (TextMessage) consumer1.receive(10000L);
    assertNotNull(tm);
    String msgText = tm.getText();
    assertEquals("Hello", msgText);
    tm = session1.createTextMessage();
    msgText = tm.getText();
    assertNull(msgText);
    publisher.publish(tm);
    session1.commit();
    tm = (TextMessage) consumer1.receive(10000L);
    assertNotNull(tm);
    session1.commit();
    msgText = tm.getText();
    assertNull(msgText);
    tm.clearBody();
    tm.setText("Now we are not null");
    publisher.publish(tm);
    session1.commit();
    tm = (TextMessage) consumer1.receive(2000);
    assertNotNull(tm);
    session1.commit();
    msgText = tm.getText();
    assertEquals("Now we are not null", msgText);

    tm = session1.createTextMessage("");
    msgText = tm.getText();
    assertEquals("Empty string not returned", "", msgText);
    publisher.publish(tm);
    session1.commit();
    tm = (TextMessage) consumer1.receive(2000);
    session1.commit();
    assertNotNull(tm);
    assertEquals("Empty string not returned", "", msgText);
    con.close();
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:48,代碼來源:TopicSessionTest.java

示例11: testNonMatchingMessagesDoNotFillQueue

import javax.jms.TopicSession; //導入方法依賴的package包/類
/**
 * This tests QPID-1191, where messages which are sent to a topic but are not consumed by a subscriber
 * due to a selector can be leaked.
 * @throws Exception
 */
public void testNonMatchingMessagesDoNotFillQueue() throws Exception
{
    AMQConnection con = (AMQConnection) getConnection("guest", "guest");

    // Setup Topic
    AMQTopic topic = new AMQTopic(con, "testNoLocal");

    TopicSession session = con.createTopicSession(true, AMQSession.NO_ACKNOWLEDGE);

    // Setup subscriber with selector
    TopicSubscriber selector = session.createSubscriber(topic,  "Selector = 'select'", false);
    TopicPublisher publisher = session.createPublisher(topic);

    con.start();
    TextMessage m;
    TextMessage message;

    // Send non-matching message
    message = session.createTextMessage("non-matching 1");
    publisher.publish(message);
    session.commit();

    // Send and consume matching message
    message = session.createTextMessage("hello");
    message.setStringProperty("Selector", "select");

    publisher.publish(message);
    session.commit();

    m = (TextMessage) selector.receive(1000);
    assertNotNull("should have received message", m);
    assertEquals("Message contents were wrong", "hello", m.getText());

    // Send non-matching message
    message = session.createTextMessage("non-matching 2");
    publisher.publish(message);
    session.commit();

    // Assert queue count is 0
    long depth = ((AMQTopicSessionAdaptor) session).getSession().getQueueDepth(topic);
    assertEquals("Queue depth was wrong", 0, depth);

}
 
開發者ID:wso2,項目名稱:andes,代碼行數:49,代碼來源:TopicSessionTest.java


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