当前位置: 首页>>代码示例>>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;未经允许,请勿转载。