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


Java TopicConnectionFactory類代碼示例

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


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

示例1: main

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

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
@Before
public void setUp() throws Exception {
  eventBus = new SimpleEventBus();
  cut = new JmsPublisher(eventBus);
  connectionFactory = mock(TopicConnectionFactory.class);
  publisher = mock(TopicPublisher.class);
  topic = mock(Topic.class);
  converter = mock(JmsMessageConverter.class);
  cut.setConnectionFactory(connectionFactory);
  cut.setTopic(topic);
  cut.setTransacted(true);
  cut.setMessageConverter(converter);
  cut.setPersistent(false);
  cut.postConstruct();
  cut.start();
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:17,代碼來源:JmsPublisherTest.java

示例3: testWithTopicConnectionFactoryAndJms11Usage

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

示例4: testWithTopicConnectionFactoryAndJms102Usage

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

示例5: getTopicConnection

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

示例6: getTopicConnectionFactory

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
public TopicConnectionFactory getTopicConnectionFactory(String contextUrl)
        throws ServiceLocatorException {
    TopicConnectionFactory factory = (TopicConnectionFactory) topicConnFactoryCache
            .get(contextUrl == null ? THIS_SERVER : contextUrl);
    if (factory == null) {
        try {
            factory = jmsProvider.getTopicConnectionFactory(namingProvider, contextUrl);
            if (contextUrl == null)
                topicConnFactoryCache.put(THIS_SERVER, factory);
            else
                topicConnFactoryCache.put(contextUrl, factory);
        }
        catch (Exception ex) {
            throw new ServiceLocatorException(-1, ex.getMessage(), ex);
        }
    }
    return factory;
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:19,代碼來源:JMSServices.java

示例7: JMSSink

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
public JMSSink(final String tcfBindingName, final String topicBindingName, final String username,
               final String password) {

   try {
      final Context ctx = new InitialContext();
      final TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) lookup(ctx,
              tcfBindingName);

      final TopicConnection topicConnection =
              topicConnectionFactory.createTopicConnection(username,
                      password);
      topicConnection.start();

      final TopicSession topicSession = topicConnection.createTopicSession(false,
              Session.AUTO_ACKNOWLEDGE);

      final Topic topic = (Topic) ctx.lookup(topicBindingName);

      final TopicSubscriber topicSubscriber = topicSession.createSubscriber(topic);

      topicSubscriber.setMessageListener(this);

   } catch (final Exception e) {
      logger.error("Could not read JMS message.", e);
   }
}
 
開發者ID:cacheonix,項目名稱:cacheonix-core,代碼行數:27,代碼來源:JMSSink.java

示例8: fireAndForget

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
protected void fireAndForget(HttpServletRequest request, HttpServletResponse response, String userMessage) {
    try {
        InitialContext ctx = new InitialContext();
        TopicConnectionFactory qconFactory = (TopicConnectionFactory) ctx.lookup(CONN_FACTORY);

        ConnectionContextFactory ccf = new ConnectionContextFactory(qconFactory);
        ProducerConnectionContext pcc = ccf.createProducerConnectionContext(new Endpoint(Endpoint.Type.TOPIC,
                TOPIC_NAME));

        SimpleBasicMessage msg = new SimpleBasicMessage(userMessage);
        MessageId mid = new MessageProcessor().send(pcc, msg, FNF_HEADER);

        PrintWriter out = response.getWriter();
        out.println("<h1>Fire and Forget</h1>");
        out.println("<p>BasicMessage Sent [" + msg + "]</p>");
        out.println("<p>(messageId=" + mid + ")</p>");
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
開發者ID:hawkular,項目名稱:hawkular-bus,代碼行數:21,代碼來源:VirtualTopicSendServlet.java

示例9: afterPropertiesSet

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
/**
 * In addition to checking if the connection factory is set, make sure
 * that the supplied connection factory is of the appropriate type for
 * the specified destination type: QueueConnectionFactory for queues,
 * and TopicConnectionFactory for topics.
 */
public void afterPropertiesSet() {
	super.afterPropertiesSet();

	// Make sure that the ConnectionFactory passed is consistent.
	// Some provider implementations of the ConnectionFactory interface
	// implement both domain interfaces under the cover, so just check if
	// the selected domain is consistent with the type of connection factory.
	if (isPubSubDomain()) {
		if (!(getConnectionFactory() instanceof TopicConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 transaction manager for topics " +
					"but did not supply an instance of TopicConnectionFactory");
		}
	}
	else {
		if (!(getConnectionFactory() instanceof QueueConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 transaction manager for queues " +
					"but did not supply an instance of QueueConnectionFactory");
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:29,代碼來源:JmsTransactionManager102.java

示例10: afterPropertiesSet

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
/**
 * In addition to checking whether the target ConnectionFactory is set,
 * make sure that the supplied factory is of the appropriate type for
 * the specified destination type: QueueConnectionFactory for queues,
 * TopicConnectionFactory for topics.
 */
public void afterPropertiesSet() {
	super.afterPropertiesSet();

	// Make sure that the ConnectionFactory passed is consistent.
	// Some provider implementations of the ConnectionFactory interface
	// implement both domain interfaces under the cover, so just check if
	// the selected domain is consistent with the type of connection factory.
	if (isPubSubDomain()) {
		if (!(getTargetConnectionFactory() instanceof TopicConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 SingleConnectionFactory for topics " +
					"but did not supply an instance of TopicConnectionFactory");
		}
	}
	else {
		if (!(getTargetConnectionFactory() instanceof QueueConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 SingleConnectionFactory for queues " +
					"but did not supply an instance of QueueConnectionFactory");
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:29,代碼來源:SingleConnectionFactory102.java

示例11: afterPropertiesSet

import javax.jms.TopicConnectionFactory; //導入依賴的package包/類
/**
 * In addition to checking if the connection factory is set, make sure
 * that the supplied connection factory is of the appropriate type for
 * the specified destination type: QueueConnectionFactory for queues,
 * and TopicConnectionFactory for topics.
 */
public void afterPropertiesSet() {
	super.afterPropertiesSet();

	// Make sure that the ConnectionFactory passed is consistent.
	// Some provider implementations of the ConnectionFactory interface
	// implement both domain interfaces under the cover, so just check if
	// the selected domain is consistent with the type of connection factory.
	if (isPubSubDomain()) {
		if (!(getConnectionFactory() instanceof TopicConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 template for topics " +
					"but did not supply an instance of TopicConnectionFactory");
		}
	}
	else {
		if (!(getConnectionFactory() instanceof QueueConnectionFactory)) {
			throw new IllegalArgumentException(
					"Specified a Spring JMS 1.0.2 template for queues " +
					"but did not supply an instance of QueueConnectionFactory");
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:29,代碼來源:JmsTemplate102.java

示例12: testTransactionCommit102WithTopic

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

	given(cf.createTopicConnection()).willReturn(con);
	given(con.createTopicSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(session);

	JmsTransactionManager tm = new JmsTransactionManager102(cf, true);
	TransactionStatus ts = tm.getTransaction(new DefaultTransactionDefinition());
	JmsTemplate jt = new JmsTemplate102(cf, true);
	jt.execute(new SessionCallback() {
		@Override
		public Object doInJms(Session sess) {
			assertTrue(sess == session);
			return null;
		}
	});
	tm.commit(ts);

	verify(session).commit();
	verify(session).close();
	verify(con).close();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:27,代碼來源:JmsTransactionManagerTests.java

示例13: testWithTopicConnectionFactoryAndJms11Usage

import javax.jms.TopicConnectionFactory; //導入依賴的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();
	con1.start();
	con1.close();  // should be ignored
	Connection con2 = scf.createConnection();
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

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

示例14: testWithTopicConnectionFactoryAndJms102Usage

import javax.jms.TopicConnectionFactory; //導入依賴的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();
	con1.start();
	con1.close();  // should be ignored
	Connection con2 = scf.createTopicConnection();
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

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

示例15: testConnectionFactory102WithTopic

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

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

	SingleConnectionFactory scf = new SingleConnectionFactory102(cf, true);
	TopicConnection con1 = scf.createTopicConnection();
	con1.start();
	con1.close();  // should be ignored
	TopicConnection con2 = scf.createTopicConnection();
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

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


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