本文整理匯總了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);
}
}
示例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();
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
}
示例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();
}
}
示例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");
}
}
}
示例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");
}
}
}
示例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");
}
}
}
示例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();
}
示例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);
}
示例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);
}
示例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);
}