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


Java TopicConnectionFactory.createTopicConnection方法代碼示例

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


在下文中一共展示了TopicConnectionFactory.createTopicConnection方法的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: 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

示例3: 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

示例4: createTopic

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

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
/**
 * {@inheritDoc}
 */
public void sendEnqueueMessage() {
    ServiceLocator locator = ServiceLocatorFactory.getLocator();
    final TopicConnectionFactory factory = (TopicConnectionFactory) locator.lookup(DEFAULT_QUEUE_CONN_FACTORY);
    final Topic topic = (Topic) locator.lookup(FileManagementMDB.QUEUE_JNDI_NAME);
    TopicConnection connection = null;
    TopicSession session = null;
    TopicPublisher publisher = null;
    try {
        connection = factory.createTopicConnection();
        session = connection.createTopicSession(true, 0);
        publisher = session.createPublisher(topic);
        
        final Message message = session.createTextMessage("enqueue");
        publisher.send(message);
    } catch (JMSException e) {
        LOG.error("Couldn't submit job to JMS", e);
    } finally {
        close(publisher);
        close(session);
        close(connection);
    }
}
 
開發者ID:NCIP,項目名稱:caarray,代碼行數:26,代碼來源:JobMessageSenderImpl.java

示例7: testSubscriberPublisher

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
@Parameters({ "broker-port"})
@Test
public void testSubscriberPublisher(String port) throws Exception {
    String topicName = "MyTopic1";
    int numberOfMessages = 100;

    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .withTopic(topicName)
            .build();

    TopicConnectionFactory connectionFactory
            = (TopicConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();

    // Initialize subscriber
    TopicSession subscriberSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    Topic subscriberDestination = (Topic) initialContext.lookup(topicName);
    TopicSubscriber subscriber = subscriberSession.createSubscriber(subscriberDestination);

    // publish 100 messages
    TopicSession producerSession = connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicPublisher producer = producerSession.createPublisher(subscriberDestination);

    for (int i = 0; i < numberOfMessages; i++) {
        producer.publish(producerSession.createTextMessage("Test message " + i));
    }

    producerSession.close();

    for (int i = 0; i < numberOfMessages; i++) {
        Message message = subscriber.receive(1000);
        Assert.assertNotNull(message, "Message #" + i + " was not received");
    }

    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:39,代碼來源:TopicSubscriberTest.java

示例8: testValidClientConnection

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
@Parameters({ "broker-port", "admin-username", "admin-password" })
@Test
public void testValidClientConnection(String port, String adminUsername, String adminPassword) throws Exception {
    String topicName = "MyTopic1";
    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, "localhost", port).withTopic(topicName).build();
    TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext
            .lookup(ClientHelper.CONNECTION_FACTORY);
    TopicConnection connection = connectionFactory.createTopicConnection();
    connection.start();
    connection.close();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:13,代碼來源:AuthenticationTest.java

示例9: testInvalidClientConnection

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
@Parameters({ "broker-port", "admin-username" })
@Test(expectedExceptions = JMSException.class)
public void testInvalidClientConnection(String port, String adminUsername) throws Exception {
    String topicName = "MyTopic1";
    InitialContext initialContext = ClientHelper
            .getInitialContextBuilder(adminUsername, "invalidPassword", "localhost", port).withTopic(topicName)
            .build();
    TopicConnectionFactory connectionFactory = (TopicConnectionFactory) initialContext
            .lookup(ClientHelper.CONNECTION_FACTORY);
    connectionFactory.createTopicConnection();
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:12,代碼來源:AuthenticationTest.java

示例10: setUp

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
  cut = new DefaultJmsMessageConverter(new XStreamSerializer());
  TopicConnectionFactory connectionFactory = embeddedBroker.createConnectionFactory();
  topicConnection = connectionFactory.createTopicConnection();
  topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
}
 
開發者ID:sventorben,項目名稱:axon-jms,代碼行數:8,代碼來源:DefaultJmsMessageConverterTest.java

示例11: load

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
public synchronized void load() throws GenericServiceException {
    try {
        InitialContext jndi = JNDIContextFactory.getInitialContext(jndiServer);
        TopicConnectionFactory factory = (TopicConnectionFactory) jndi.lookup(jndiName);

        if (factory != null) {
            con = factory.createTopicConnection(userName, password);
            con.setExceptionListener(this);
            session = con.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
            topic = (Topic) jndi.lookup(topicName);
            if (topic != null) {
                TopicSubscriber subscriber = session.createSubscriber(topic);
                subscriber.setMessageListener(this);
                con.start();
                this.setConnected(true);
                if (Debug.infoOn()) Debug.logInfo("Listening to topic [" + topicName + "] on [" + jndiServer + "]...", module);
            } else {
                throw new GenericServiceException("Topic lookup failed.");
            }
        } else {
            throw new GenericServiceException("Factory (broker) lookup failed.");
        }
    } catch (NamingException ne) {
        throw new GenericServiceException("JNDI lookup problems; listener not running.", ne);
    } catch (JMSException je) {
        throw new GenericServiceException("JMS internal error; listener not running.", je);
    } catch (GeneralException ge) {
        throw new GenericServiceException("Problems with InitialContext; listener not running.", ge);
    }
}
 
開發者ID:ilscipio,項目名稱:scipio-erp,代碼行數:31,代碼來源:JmsTopicListener.java

示例12: doCreateTopicConnection

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
/**
 * This implementation delegates to the {@code createTopicConnection(username, password)}
 * method of the target TopicConnectionFactory, passing in the specified user credentials.
 * If the specified username is empty, it will simply delegate to the standard
 * {@code createTopicConnection()} method of the target ConnectionFactory.
 * @param username the username to use
 * @param password the password to use
 * @return the Connection
 * @see javax.jms.TopicConnectionFactory#createTopicConnection(String, String)
 * @see javax.jms.TopicConnectionFactory#createTopicConnection()
 */
protected TopicConnection doCreateTopicConnection(String username, String password) throws JMSException {
	Assert.state(this.targetConnectionFactory != null, "'targetConnectionFactory' is required");
	if (!(this.targetConnectionFactory instanceof TopicConnectionFactory)) {
		throw new javax.jms.IllegalStateException("'targetConnectionFactory' is not a TopicConnectionFactory");
	}
	TopicConnectionFactory queueFactory = (TopicConnectionFactory) this.targetConnectionFactory;
	if (StringUtils.hasLength(username)) {
		return queueFactory.createTopicConnection(username, password);
	}
	else {
		return queueFactory.createTopicConnection();
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:25,代碼來源:UserCredentialsConnectionFactoryAdapter.java

示例13: start

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
public synchronized void start() throws RestException {
    try {
        String jndiProviderUrl = String.format(PROVIDER_URL_FMT, jmsHost, jmsPort);
        String jndiFactory = JNDI_FACTORY;
        String jmsFactory = JMS_FACTORY;

        // Debug
        logger.debug("Creating JNDI connection to: " + jndiProviderUrl + " using factory: " + jndiFactory);

        // Initialize JNDI connection
        Properties env = new Properties();
        env.put(Context.INITIAL_CONTEXT_FACTORY, jndiFactory);
        env.put(Context.PROVIDER_URL, jndiProviderUrl);
        context = new InitialContext(env);

        // Debug
        logger.debug("Creating JMS connection using factory: " + jmsFactory + " user: " + jmsUser + " passwd: " + jmsPassword);

        // Create the JMS topic connection and start it
        TopicConnectionFactory topicConnectionFactory = (TopicConnectionFactory) context.lookup(jmsFactory);
        topicConnection = topicConnectionFactory.createTopicConnection(jmsUser, jmsPassword);
        topicConnection.start();

        // Debug
        logger.debug("Subscribing to JMS topic: " + jmsTopic);

        // Create the subscriber
        Topic topic = (Topic) context.lookup(jmsTopic);
        TopicSession topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
        createSubscriber(topicSession, topic);

        // Debug
        logger.info("JMS connection started");
    } catch (NamingException | JMSException ex) {
        throw new RestException(ex);
    }
}
 
開發者ID:nuagenetworks,項目名稱:java-bambou,代碼行數:38,代碼來源:RestPushCenterJmsActiveMQ.java

示例14: start

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
public synchronized void start() throws RestException {
    try {

        // Debug
        logger.debug("Creating JMS connection using host: " + jmsHost + " user: " + jmsUser + " passwd: " + jmsPassword);

        // Create topic connection factory - connecting directly to VSD,
        // bypassing JNDI factory
        String brokerUrl = String.format(BROKER_URL_FMT, jmsHost, jmsPort);
        TopicConnectionFactory topicConnectionFactory = new ActiveMQConnectionFactory(brokerUrl);

        // Create the JMS topic connection and start it
        topicConnection = topicConnectionFactory.createTopicConnection(jmsUser, jmsPassword);
        topicConnection.start();

        // Debug
        logger.debug("Subscribing to JMS topic: " + jmsTopic);

        // Create the subscriber
        TopicSession topicSession = topicConnection.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE);
        String[] topicSubNames = jmsTopic.split("/");
        String topicName = topicSubNames[topicSubNames.length - 2] + '/' + topicSubNames[topicSubNames.length - 1];
        Topic topic = topicSession.createTopic(topicName);
        createSubscriber(topicSession, topic);

        // Debug
        logger.info("JMS connection started");
    } catch (JMSException ex) {
        throw new RestException(ex);
    }
}
 
開發者ID:nuagenetworks,項目名稱:java-bambou,代碼行數:32,代碼來源:RestPushCenterJmsDirectActiveMQ.java

示例15: setUp

import javax.jms.TopicConnectionFactory; //導入方法依賴的package包/類
/**
 * Create all administrated objects connections and sessions ready to use for tests.
 * <br />
 * Start connections.
 */
@Override
@Before
public void setUp() throws Exception {
   super.setUp();

   try {
      // ...and creates administrated objects and binds them
      admin.createTopicConnectionFactory(PubSubTestCase.TCF_NAME);
      admin.createTopic(PubSubTestCase.TOPIC_NAME);

      Context ctx = admin.createContext();

      publisherTCF = (TopicConnectionFactory) ctx.lookup(PubSubTestCase.TCF_NAME);
      publisherTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME);
      publisherConnection = publisherTCF.createTopicConnection();
      publisherConnection.setClientID("publisherConnection");
      publisherSession = publisherConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      publisher = publisherSession.createPublisher(publisherTopic);

      subscriberTCF = (TopicConnectionFactory) ctx.lookup(PubSubTestCase.TCF_NAME);
      subscriberTopic = (Topic) ctx.lookup(PubSubTestCase.TOPIC_NAME);
      subscriberConnection = subscriberTCF.createTopicConnection();
      subscriberConnection.setClientID("subscriberConnection");
      subscriberSession = subscriberConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
      subscriber = subscriberSession.createSubscriber(subscriberTopic);

      publisherConnection.start();
      subscriberConnection.start();
      // end of client step
   } catch (Exception e) {
      e.printStackTrace();
      throw new RuntimeException(e);
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:40,代碼來源:PubSubTestCase.java


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