当前位置: 首页>>代码示例>>Java>>正文


Java ConnectionFactory类代码示例

本文整理汇总了Java中javax.jms.ConnectionFactory的典型用法代码示例。如果您正苦于以下问题:Java ConnectionFactory类的具体用法?Java ConnectionFactory怎么用?Java ConnectionFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ConnectionFactory类属于javax.jms包,在下文中一共展示了ConnectionFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: putTopic

import javax.jms.ConnectionFactory; //导入依赖的package包/类
private void putTopic(List<String> events) throws Exception {
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  Connection connection = factory.createConnection();
  connection.start();

  Session session = connection.createSession(true,
      Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createTopic(DESTINATION_NAME);
  MessageProducer producer = session.createProducer(destination);

  for (String event : events) {
    TextMessage message = session.createTextMessage();
    message.setText(event);
    producer.send(message);
  }
  session.commit();
  session.close();
  connection.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestIntegrationActiveMQ.java

示例2: createProviderContext

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Override
protected XAJMSContext createProviderContext(String username, String password, int sessionMode) {
    if (connectionFactory instanceof ConnectionFactory) {
        if (username == null && password == null) {
            return ((XAConnectionFactory) connectionFactory).createXAContext();
        } else {
            return ((XAConnectionFactory) connectionFactory).createXAContext(username, password);
        }
    } else {
        throw new javax.jms.IllegalStateRuntimeException("connectionFactory should implement javax.jms.ConnectionFactory");
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:13,代码来源:JmsPoolXAConnectionFactory.java

示例3: receiveAndRespondWithMessageIdAsCorrelationId

import javax.jms.ConnectionFactory; //导入依赖的package包/类
public void receiveAndRespondWithMessageIdAsCorrelationId(ConnectionFactory connectionFactory, String queueName) throws JMSException {
    Connection connection = connectionFactory.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageConsumer consumer = session.createConsumer(session.createQueue(queueName));
    final javax.jms.Message inMessage = consumer.receive();

    String requestMessageId = inMessage.getJMSMessageID();
    LOG.debug("Received message " + requestMessageId);
    final TextMessage replyMessage = session.createTextMessage("Result");
    replyMessage.setJMSCorrelationID(inMessage.getJMSMessageID());
    final MessageProducer producer = session.createProducer(inMessage.getJMSReplyTo());
    LOG.debug("Sending reply to " + inMessage.getJMSReplyTo());
    producer.send(replyMessage);

    producer.close();
    consumer.close();
    session.close();
    connection.close();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:20,代码来源:PooledConnectionTempQueueTest.java

示例4: connectionFactory

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Bean(name="connectionFactory")
	public ConnectionFactory connectionFactory(){
		ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory();
//		activeMQConnectionFactory.setUseAsyncSend(true);
		activeMQConnectionFactory.setUserName(jmsUserName);
		activeMQConnectionFactory.setPassword(jmsPassword);
		activeMQConnectionFactory.setBrokerURL(jmsBrokerUrl);

		// 默认重复投递6次将转发到死信队列,改为无限次数
//		RedeliveryPolicy redeliveryPolicy = new RedeliveryPolicy();
//		redeliveryPolicy.setMaximumRedeliveries(-1);
//		
//		activeMQConnectionFactory.setRedeliveryPolicy(redeliveryPolicy);
		
		PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(activeMQConnectionFactory);
		pooledConnectionFactory.setMaxConnections(jmsMaxPooledConnections);
//		CachingConnectionFactory cachingConnectionFactory = new CachingConnectionFactory(pooledConnectionFactory);
//		cachingConnectionFactory.setSessionCacheSize(10);
		return pooledConnectionFactory;
	}
 
开发者ID:eXcellme,项目名称:eds,代码行数:21,代码来源:EdsCamelConfig.java

示例5: myFactory

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory,
		DefaultJmsListenerContainerFactoryConfigurer configurer) {
	DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
	configurer.configure(factory, connectionFactory);
	return factory;
}
 
开发者ID:Estafet-LTD,项目名称:estafet-microservices-scrum-api-project-burndown,代码行数:8,代码来源:Application.java

示例6: testSetClientIDTwiceWithSameID

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDTwiceWithSameID() throws Exception {
    LOG.debug("running testRepeatedSetClientIDCalls()");

    // test: call setClientID("newID") twice
    // this should be tolerated and not result in an exception
    ConnectionFactory cf = createPooledConnectionFactory();
    Connection conn = cf.createConnection();
    conn.setClientID("newID");

    try {
        conn.setClientID("newID");
        conn.start();
        conn.close();
    } catch (IllegalStateException ise) {
        LOG.error("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
        fail("Repeated calls to newID2.setClientID(\"newID\") caused " + ise.getMessage());
    } finally {
        ((JmsPoolConnectionFactory) cf).stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:24,代码来源:PooledConnectionTest.java

示例7: jmsListenerContainerQueue

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Bean(name = "queueListenerContainerFactory")
@ConditionalOnProperty(prefix = "spring.activemq", name = "broker-url")
public JmsListenerContainerFactory<?> jmsListenerContainerQueue(ConnectionFactory activeMQConnectionFactory) {
    DefaultJmsListenerContainerFactory bean = new DefaultJmsListenerContainerFactory();
    bean.setConnectionFactory(activeMQConnectionFactory);
    bean.setPubSubDomain(Boolean.FALSE);
    return bean;
}
 
开发者ID:yu199195,项目名称:myth,代码行数:9,代码来源:JmsConfig.java

示例8: testSetClientIDAfterConnectionStart

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Test(timeout = 60000)
public void testSetClientIDAfterConnectionStart() throws Exception {
    LOG.debug("running testRepeatedSetClientIDCalls()");

    ConnectionFactory cf = createPooledConnectionFactory();
    Connection conn = cf.createConnection();

    // test: try to call setClientID() after start()
    // should result in an exception
    try {
        conn.start();
        conn.setClientID("newID3");
        fail("Calling setClientID() after start() mut raise a JMSException.");
    } catch (IllegalStateException ise) {
        LOG.debug("Correctly received " + ise);
    } finally {
        conn.close();
        ((JmsPoolConnectionFactory) cf).stop();
    }

    LOG.debug("Test finished.");
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:23,代码来源:PooledConnectionTest.java

示例9: sendMessages

import javax.jms.ConnectionFactory; //导入依赖的package包/类
public void sendMessages(ConnectionFactory connectionFactory) throws Exception {
    for (int i = 0; i < NUM_MESSAGES; i++) {
        Connection connection = connectionFactory.createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = session.createQueue(QUEUE);
        MessageProducer producer = session.createProducer(destination);

        String msgTo = "hello";
        TextMessage message = session.createTextMessage(msgTo);
        producer.send(message);
        connection.close();
        LOG.debug("sent " + i + " messages using " + connectionFactory.getClass());
    }
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:17,代码来源:PooledSessionExhaustionBlockTimeoutTest.java

示例10: putQueue

import javax.jms.ConnectionFactory; //导入依赖的package包/类
private void putQueue(List<String> events) throws Exception {
  ConnectionFactory factory = new ActiveMQConnectionFactory(USERNAME,
      PASSWORD, BROKER_BIND_URL);
  Connection connection = factory.createConnection();
  connection.start();

  Session session = connection.createSession(true,
      Session.AUTO_ACKNOWLEDGE);
  Destination destination = session.createQueue(DESTINATION_NAME);
  MessageProducer producer = session.createProducer(destination);

  for (String event : events) {
    TextMessage message = session.createTextMessage();
    message.setText(event);
    producer.send(message);
  }
  session.commit();
  session.close();
  connection.close();
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:21,代码来源:TestIntegrationActiveMQ.java

示例11: createConnectionFactory

import javax.jms.ConnectionFactory; //导入依赖的package包/类
private static ConnectionFactory createConnectionFactory(String options, Integer maximumRedeliveries) {
        // using a unique broker name improves testing when running the entire test suite in the same JVM
        int id = counter.incrementAndGet();
        String url = "tcp://192.168.3.103:61618";
//        if (options != null) {
//            url = url + "&" + options;
//        }
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
        // optimize AMQ to be as fast as possible so unit testing is quicker
        connectionFactory.setCopyMessageOnSend(false);
        connectionFactory.setOptimizeAcknowledge(true);
        connectionFactory.setOptimizedMessageDispatch(true);
        // When using asyncSend, producers will not be guaranteed to send in the order we
        // have in the tests (which may be confusing for queues) so we need this set to false.
        // Another way of guaranteeing order is to use persistent messages or transactions.
        connectionFactory.setUseAsyncSend(false);
        connectionFactory.setAlwaysSessionAsync(false);
        if (maximumRedeliveries != null) {
            connectionFactory.getRedeliveryPolicy().setMaximumRedeliveries(maximumRedeliveries);
        }
//        connectionFactory.setTrustAllPackages(true);
        return connectionFactory;
    }
 
开发者ID:eXcellme,项目名称:eds,代码行数:24,代码来源:CamelJmsTestHelper.java

示例12: createPersistentConnectionFactory

import javax.jms.ConnectionFactory; //导入依赖的package包/类
private static ConnectionFactory createPersistentConnectionFactory(String options) {
        // using a unique broker name improves testing when running the entire test suite in the same JVM
        int id = counter.incrementAndGet();

        // use an unique data directory in target
        String dir = "target/activemq-data-" + id;

        // remove dir so its empty on startup
        FileUtil.removeDir(new File(dir));

        String url = "vm://test-broker-" + id + "?broker.persistent=true&broker.useJmx=false&broker.dataDirectory=" + dir;
        if (options != null) {
            url = url + "&" + options;
        }
        ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(url);
        // optimize AMQ to be as fast as possible so unit testing is quicker
        connectionFactory.setCopyMessageOnSend(false);
        connectionFactory.setOptimizeAcknowledge(true);
        connectionFactory.setOptimizedMessageDispatch(true);
        connectionFactory.setAlwaysSessionAsync(false);
//        connectionFactory.setTrustAllPackages(true);
        return connectionFactory;
    }
 
开发者ID:eXcellme,项目名称:eds,代码行数:24,代码来源:CamelJmsTestHelper.java

示例13: buildTargetResource

import javax.jms.ConnectionFactory; //导入依赖的package包/类
/**
 * This method essentially performs initialization of this Processor by
 * obtaining an instance of the {@link ConnectionFactory} from the
 * {@link JMSConnectionFactoryProvider} (ControllerService) and performing a
 * series of {@link ConnectionFactory} adaptations which eventually results
 * in an instance of the {@link CachingConnectionFactory} used to construct
 * {@link JmsTemplate} used by this Processor.
 */
private void buildTargetResource(ProcessContext context) {
    if (this.targetResource == null) {
        JMSConnectionFactoryProviderDefinition cfProvider = context.getProperty(CF_SERVICE).asControllerService(JMSConnectionFactoryProviderDefinition.class);
        ConnectionFactory connectionFactory = cfProvider.getConnectionFactory();

        UserCredentialsConnectionFactoryAdapter cfCredentialsAdapter = new UserCredentialsConnectionFactoryAdapter();
        cfCredentialsAdapter.setTargetConnectionFactory(connectionFactory);
        cfCredentialsAdapter.setUsername(context.getProperty(USER).getValue());
        cfCredentialsAdapter.setPassword(context.getProperty(PASSWORD).getValue());

        this.cachingConnectionFactory = new CachingConnectionFactory(cfCredentialsAdapter);
        this.cachingConnectionFactory.setSessionCacheSize(Integer.parseInt(context.getProperty(SESSION_CACHE_SIZE).getValue()));

        JmsTemplate jmsTemplate = new JmsTemplate();
        jmsTemplate.setConnectionFactory(this.cachingConnectionFactory);
        jmsTemplate.setPubSubDomain(TOPIC.equals(context.getProperty(DESTINATION_TYPE).getValue()));

        // set of properties that may be good candidates for exposure via configuration
        jmsTemplate.setReceiveTimeout(1000);

        this.targetResource = this.finishBuildingTargetResource(jmsTemplate, context);
    }
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:32,代码来源:AbstractJMSProcessor.java

示例14: validateFailedPublishAndTransferToFailure

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Test
public void validateFailedPublishAndTransferToFailure() throws Exception {
    ConnectionFactory cf = mock(ConnectionFactory.class);

    PublishJMS pubProc = new PublishJMS();
    TestRunner runner = TestRunners.newTestRunner(pubProc);
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(cf);

    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(PublishJMS.DESTINATION, "fooQueue");

    runner.enqueue("Hello Joe".getBytes());

    runner.run();
    Thread.sleep(200);

    assertTrue(runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).isEmpty());
    assertNotNull(runner.getFlowFilesForRelationship(PublishJMS.REL_FAILURE).get(0));
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:25,代码来源:PublishJMSTest.java

示例15: validateFailedPublishAndTransferToFailureOverJNDI

import javax.jms.ConnectionFactory; //导入依赖的package包/类
@Test
public void validateFailedPublishAndTransferToFailureOverJNDI() throws Exception {
    ConnectionFactory cf = mock(ConnectionFactory.class);

    PublishJMS pubProc = new PublishJMS();
    TestRunner runner = TestRunners.newTestRunner(pubProc);
    JMSConnectionFactoryProviderDefinition cs = mock(JMSConnectionFactoryProviderDefinition.class);
    when(cs.getIdentifier()).thenReturn("cfProvider");
    when(cs.getConnectionFactory()).thenReturn(cf);

    runner.addControllerService("cfProvider", cs);
    runner.enableControllerService(cs);

    runner.setProperty(PublishJMS.CF_SERVICE, "cfProvider");
    runner.setProperty(PublishJMS.DESTINATION, "fooQueue");

    runner.enqueue("Hello Joe".getBytes());

    runner.run();
    Thread.sleep(200);

    assertTrue(runner.getFlowFilesForRelationship(PublishJMS.REL_SUCCESS).isEmpty());
    assertNotNull(runner.getFlowFilesForRelationship(PublishJMS.REL_FAILURE).get(0));
}
 
开发者ID:lsac,项目名称:nifi-jms-jndi,代码行数:25,代码来源:PublishJMSTest.java


注:本文中的javax.jms.ConnectionFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。