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


Java TopicConnection類代碼示例

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


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

示例1: main

import javax.jms.TopicConnection; //導入依賴的package包/類
/**
 * @param args
 * @throws JMSException
 * @throws IOException
 */
public static void main(String[] args) throws JMSException, IOException {
	
	if (args.length != 1) {
		System.out.println("User Name is required....");
	} else {
		userId = args[0];
		ApplicationContext ctx = new ClassPathXmlApplicationContext(
				"com/springtraining/jms/spring-config.xml");

		BasicJMSChat basicJMSChat = (BasicJMSChat) ctx
				.getBean("basicJMSChat");
		TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) basicJMSChat.chatJMSTemplate
				.getConnectionFactory();
		TopicConnection tc = topicConnectionFactory.createTopicConnection();

		basicJMSChat.publish(tc,  basicJMSChat.chatTopic, userId);
		basicJMSChat.subscribe(tc,  basicJMSChat.chatTopic, basicJMSChat);
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:25,代碼來源:BasicJMSChat.java

示例2: testWithSessionCloseOutsideTheLoop

import javax.jms.TopicConnection; //導入依賴的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

示例3: testSenderAndPublisherDest

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
    JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
    pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
        "vm://test?broker.persistent=false&broker.useJmx=false"));

    QueueConnection connection = pcf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueSender sender = session.createSender(session.createQueue("AA"));
    assertNotNull(sender.getQueue().getQueueName());

    connection.close();

    TopicConnection topicConnection = pcf.createTopicConnection();
    TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
    assertNotNull(topicPublisher.getTopic().getTopicName());

    topicConnection.close();
    pcf.stop();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:22,代碼來源:XAConnectionPoolTest.java

示例4: publish

import javax.jms.TopicConnection; //導入依賴的package包/類
/**
 * @param topicConnection
 * @param chatTopic
 * @param userId
 * @throws JMSException
 * @throws IOException
 */
void publish(TopicConnection topicConnection, Topic chatTopic, String userId)
		throws JMSException, IOException {
	TopicSession tsession = topicConnection.createTopicSession(false,
			Session.AUTO_ACKNOWLEDGE);
	TopicPublisher topicPublisher = tsession.createPublisher(chatTopic);
	topicConnection.start();
	
	BufferedReader reader = new BufferedReader(new InputStreamReader(
			System.in));
	while (true) {
		String msgToSend = reader.readLine();
		if (msgToSend.equalsIgnoreCase("exit")) {
			topicConnection.close();
			System.exit(0);
		} else {

			TextMessage msg = (TextMessage) tsession.createTextMessage();
			msg.setText("\n["+userId + " : " + msgToSend+"]");
			topicPublisher.publish(msg);
		}
	}
}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:30,代碼來源:BasicJMSChat.java

示例5: create

import javax.jms.TopicConnection; //導入依賴的package包/類
public static ManagedConnection create(
                                        final Connection connection ) {

    if ( (connection instanceof XAQueueConnection) && (connection instanceof XATopicConnection)) {
        return new ManagedXAQueueTopicConnection(connection);
    } else if (connection instanceof XAQueueConnection) {
        return new ManagedXAQueueConnection((XAQueueConnection) connection);
    } else if (connection instanceof XATopicConnection) {
        return new ManagedXATopicConnection((XATopicConnection) connection);
    } else if ( (connection instanceof QueueConnection) && (connection instanceof TopicConnection)) {
        return new ManagedQueueTopicConnection(connection);
    } else if (connection instanceof QueueConnection) {
        return new ManagedQueueConnection((QueueConnection) connection);
    } else if (connection instanceof TopicConnection) {
        return new ManagedTopicConnection((TopicConnection) connection);
    } else {
        return new ManagedConnection(connection);
    }
}
 
開發者ID:Axway,項目名稱:ats-framework,代碼行數:20,代碼來源:ManagedConnection.java

示例6: send

import javax.jms.TopicConnection; //導入依賴的package包/類
/**
 * Sends the given {@code events} to the configured JMS Topic. It takes the current Unit of Work
 * into account when available. Otherwise, it simply publishes directly.
 *
 * @param events the events to publish on the JMS Message Broker
 */
protected void send(List<? extends EventMessage<?>> events) {
  try (TopicConnection topicConnection = connectionFactory.createTopicConnection()) {
    int ackMode = isTransacted ? Session.SESSION_TRANSACTED : Session.AUTO_ACKNOWLEDGE;
    TopicSession topicSession = topicConnection.createTopicSession(isTransacted, ackMode);
    try (TopicPublisher publisher = topicSession.createPublisher(topic)) {
      for (EventMessage event : events) {
        Message jmsMessage = messageConverter.createJmsMessage(event, topicSession);
        doSendMessage(publisher, jmsMessage);
      }
    } finally {
      handleTransaction(topicSession);
    }
  } catch (JMSException ex) {
    throw new EventPublicationFailedException(
        "Unable to establish TopicConnection to JMS message broker.", ex);
  }
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:24,代碼來源:JmsPublisher.java

示例7: testSendMessage_NoUnitOfWork

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testSendMessage_NoUnitOfWork() throws Exception {
  TopicConnection connection = mock(TopicConnection.class);
  when(connectionFactory.createTopicConnection()).thenReturn(connection);
  TopicSession transactionalSession = mock(TopicSession.class);
  when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
      .thenReturn(transactionalSession);
  when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
  GenericEventMessage<String> message = new GenericEventMessage<>("Message");
  TextMessage jmsMessage = mock(TextMessage.class);
  when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
  eventBus.publish(message);

  verify(publisher).publish(jmsMessage);
  verify(transactionalSession).commit();
  verify(transactionalSession).close();
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:18,代碼來源:JmsPublisherTest.java

示例8: testSendMessage_WithTransactionalUnitOfWork

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testSendMessage_WithTransactionalUnitOfWork() throws Exception {
  GenericEventMessage<String> message = new GenericEventMessage<>("Message");
  final UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(message);

  TopicConnection connection = mock(TopicConnection.class);
  when(connectionFactory.createTopicConnection()).thenReturn(connection);
  TopicSession transactionalSession = mock(TopicSession.class);

  when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
      .thenReturn(transactionalSession);
  when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
  when(transactionalSession.getTransacted()).thenReturn(true);
  TextMessage jmsMessage = mock(TextMessage.class);
  when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
  eventBus.publish(message);

  uow.commit();
  verify(publisher).publish(jmsMessage);
  verify(transactionalSession).commit();
  verify(transactionalSession).close();
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:23,代碼來源:JmsPublisherTest.java

示例9: testSendMessage_WithUnitOfWorkRollback

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testSendMessage_WithUnitOfWorkRollback() throws Exception {
  GenericEventMessage<String> message = new GenericEventMessage<>("Message");
  final UnitOfWork<?> uow = DefaultUnitOfWork.startAndGet(message);

  TopicConnection connection = mock(TopicConnection.class);
  when(connectionFactory.createTopicConnection()).thenReturn(connection);
  TopicSession transactionalSession = mock(TopicSession.class);

  when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
      .thenReturn(transactionalSession);
  when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
  when(transactionalSession.getTransacted()).thenReturn(true);
  TextMessage jmsMessage = mock(TextMessage.class);
  when(converter.createJmsMessage(message, transactionalSession)).thenReturn(jmsMessage);
  eventBus.publish(message);

  verify(transactionalSession, never()).rollback();
  verify(transactionalSession, never()).commit();
  verify(transactionalSession, never()).close();

  uow.rollback();
  verify(publisher, never()).publish(jmsMessage);
  verify(transactionalSession, never()).commit();
  verify(connectionFactory, never()).createTopicConnection();
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:27,代碼來源:JmsPublisherTest.java

示例10: testSendPersistentMessage

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testSendPersistentMessage() throws Exception {
  cut.setPersistent(true);
  cut.setMessageConverter(null);
  cut.postConstruct();

  TopicConnection connection = mock(TopicConnection.class);
  when(connectionFactory.createTopicConnection()).thenReturn(connection);
  TopicSession transactionalSession = mock(TopicSession.class);

  when(connection.createTopicSession(true, Session.SESSION_TRANSACTED))
      .thenReturn(transactionalSession);
  when(transactionalSession.createPublisher(topic)).thenReturn(publisher);
  TextMessage jmsMessage = mock(TextMessage.class);
  when(transactionalSession.createTextMessage(any())).thenReturn(jmsMessage);
  ArgumentCaptor<Message> jmsMsgCapture = ArgumentCaptor.forClass(Message.class);
  doNothing().when(publisher).publish(jmsMsgCapture.capture());

  eventBus.publish(new GenericEventMessage<>("Message"));

  verify(jmsMessage).setJMSDeliveryMode(DeliveryMode.PERSISTENT);
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:23,代碼來源:JmsPublisherTest.java

示例11: createSession

import javax.jms.TopicConnection; //導入依賴的package包/類
/**
 * Create a default Session for this ConnectionFactory,
 * adapting to JMS 1.0.2 style queue/topic mode if necessary.
 * @param con the JMS Connection to operate on
 * @param mode the Session acknowledgement mode
 * ({@code Session.TRANSACTED} or one of the common modes)
 * @return the newly created Session
 * @throws JMSException if thrown by the JMS API
 */
protected Session createSession(Connection con, Integer mode) throws JMSException {
	// Determine JMS API arguments...
	boolean transacted = (mode == Session.SESSION_TRANSACTED);
	int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
	// Now actually call the appropriate JMS factory method...
	if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
		return ((QueueConnection) con).createQueueSession(transacted, ackMode);
	}
	else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
		return ((TopicConnection) con).createTopicSession(transacted, ackMode);
	}
	else {
		return con.createSession(transacted, ackMode);
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:SingleConnectionFactory.java

示例12: testWithTopicConnection

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testWithTopicConnection() throws JMSException {
	Connection con = mock(TopicConnection.class);

	SingleConnectionFactory scf = new SingleConnectionFactory(con);
	TopicConnection con1 = scf.createTopicConnection();
	con1.start();
	con1.stop();
	con1.close();
	TopicConnection con2 = scf.createTopicConnection();
	con2.start();
	con2.stop();
	con2.close();
	scf.destroy();  // should trigger actual close

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

示例13: testWithTopicConnectionFactoryAndJms11Usage

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testWithTopicConnectionFactoryAndJms11Usage() throws JMSException {
	TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
	TopicConnection con = mock(TopicConnection.class);

	given(cf.createConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	Connection con1 = scf.createConnection();
	Connection con2 = scf.createConnection();
	con1.start();
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

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

示例14: testWithTopicConnectionFactoryAndJms102Usage

import javax.jms.TopicConnection; //導入依賴的package包/類
@Test
public void testWithTopicConnectionFactoryAndJms102Usage() throws JMSException {
	TopicConnectionFactory cf = mock(TopicConnectionFactory.class);
	TopicConnection con = mock(TopicConnection.class);

	given(cf.createTopicConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory(cf);
	Connection con1 = scf.createTopicConnection();
	Connection con2 = scf.createTopicConnection();
	con1.start();
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

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

示例15: getTopicConnection

import javax.jms.TopicConnection; //導入依賴的package包/類
public TopicConnection getTopicConnection(TopicConnectionFactory tcf, String uniqueID )
		throws JMSException {

	final TopicConnection tc;
	final String username = Config.parms.getString("us");
	if (username != null && username.length() != 0) {
		Log.logger.log(Level.INFO, "getTopicConnection(): authenticating as \"" + username + "\"");
		final String password = Config.parms.getString("pw");
		tc = tcf.createTopicConnection(username, password);
	} else {
		tc = tcf.createTopicConnection();
	}

	if (durable) {
		// Note: change signature to match getConnection
		setDurableConnectionId( tc, ((WorkerThread)Thread.currentThread()), uniqueID );
	} // end if durable

	return tc;

}
 
開發者ID:ot4i,項目名稱:perf-harness,代碼行數:22,代碼來源:AbstractJMSProvider.java


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