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


Java ActiveMQConnectionFactory.createConnection方法代码示例

本文整理汇总了Java中org.apache.activemq.ActiveMQConnectionFactory.createConnection方法的典型用法代码示例。如果您正苦于以下问题:Java ActiveMQConnectionFactory.createConnection方法的具体用法?Java ActiveMQConnectionFactory.createConnection怎么用?Java ActiveMQConnectionFactory.createConnection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.activemq.ActiveMQConnectionFactory的用法示例。


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

示例1: JmsClient

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public JmsClient() {
    ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
    try {
        connection = connectionFactory.createConnection();
        connection.start();
        session = connection.createSession(transacted, ackMode);
        Destination adminQueue = session.createQueue(clientQueueName);
 
        //Setup a message producer to send message to the queue the server is consuming from
        this.producer = session.createProducer(adminQueue);
        this.producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
 
        //Create a temporary queue that this client will listen for responses on then create a consumer
        //that consumes message from this temporary queue...for a real application a client should reuse
        //the same temp queue for each message to the server...one temp queue per client
        tempDest = session.createTemporaryQueue();
        MessageConsumer responseConsumer = session.createConsumer(tempDest);
 
        //This class will handle the messages to the temp queue as well
        responseConsumer.setMessageListener(this);
    } catch (JMSException e) {
        //Handle the exception appropriately
    }
    acks = 0;
}
 
开发者ID:mariaklimenko,项目名称:jeta,代码行数:26,代码来源:JmsClient.java

示例2: main

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");

    Connection connection = factory.createConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue("business-events");
    MessageProducer producer = session.createProducer(destination);

    try {
        for (int i = 0; i < 10; ++i) {
            TextMessage message = session.createTextMessage();
            message.setText("Message-" + i);
            producer.send(message);
        }
    } finally {
        producer.close();
    }

    connection.close();
}
 
开发者ID:madbrain,项目名称:flume-examples,代码行数:23,代码来源:InjectActiveMQMessage.java

示例3: main

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");

    Connection connection = factory.createConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue("business-events");
    MessageConsumer consumer = session.createConsumer(destination);

    try {
        for (int i = 0; i < 10; ++i) {
            TextMessage message = (TextMessage) consumer.receive();
            System.out.println(message.getText());
        }
    } finally {
        consumer.close();
    }

    connection.close();
}
 
开发者ID:madbrain,项目名称:flume-examples,代码行数:22,代码来源:ConsumeActiveMQMessage.java

示例4: canDetectTheOpenwireProtocol

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
@Test
public void canDetectTheOpenwireProtocol() throws Exception {

    DetectingGateway gateway = createGateway();

    gateway.init();
    String url = "tcp://localhost:" + gateway.getBoundPort()+"?wireFormat.host=broker0";
    final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
    Connection connection = factory.createConnection();
    connection.start();

    assertConnectedToBroker(0);
    assertEquals(1, gateway.getSuccessfulConnectionAttempts());
    assertEquals(1, gateway.getConnectedClients().length);

    connection.close();
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:18,代码来源:DetectingGatewayTest.java

示例5: canDetectTheOpenwireSslProtocol

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
@Test
public void canDetectTheOpenwireSslProtocol() throws Exception {

    System.setProperty("javax.net.ssl.trustStore", new File(basedir(), "src/test/resources/client.ks").getCanonicalPath());
    System.setProperty("javax.net.ssl.trustStorePassword", "password");
    System.setProperty("javax.net.ssl.trustStoreType", "jks");

    DetectingGateway gateway = createGateway();

    String url = "ssl://localhost:" + gateway.getBoundPort()+"?wireFormat.host=broker0";
    final ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
    Connection connection = factory.createConnection();
    connection.start();

    assertEquals(1, gateway.getSuccessfulConnectionAttempts());
    assertEquals(1, gateway.getConnectedClients().length);

    assertConnectedToBroker(0);
    connection.close();

}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:22,代码来源:DetectingGatewayTest.java

示例6: Sender

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
/**
 * 
 * @param queue_name : name of destination message queue
 * @param host_name : destination ip/host name
 */
public Sender(String queue_name, String host_name) {
	connectionFactory = new ActiveMQConnectionFactory(
               ActiveMQConnection.DEFAULT_USER,
               ActiveMQConnection.DEFAULT_PASSWORD,
               "tcp://" + host_name +":61616");
	
       try {
           connection = connectionFactory.createConnection();
           connection.start();
           session = connection.createSession(Boolean.TRUE,
                   Session.AUTO_ACKNOWLEDGE);      
           destination = session.createQueue(queue_name);
           producer = session.createProducer(destination);
           producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
           
       } catch (JMSException je) {
           je.printStackTrace();
       } 

}
 
开发者ID:knshen,项目名称:JSearcher,代码行数:26,代码来源:Sender.java

示例7: destroyMessageQueue

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static void destroyMessageQueue(String brokerHost, String brokerPort, String topic) throws JMSException {
	// Create a ConnectionFactory
	ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));

	// Create a Connection
	Connection connection = connectionFactory.createConnection();
	connection.start();

	// Create a Session
	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

	// Create the destination (Topic or Queue)
	Destination destination = session.createQueue(topic);
	session.close();

	// Destroy Empty Queue
	((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
	connection.close();
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:20,代码来源:JMSProvider.java

示例8: checkConnection

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
synchronized void checkConnection() {
    log.info("Checking the status of the ActiveMQ Broker: {}", brokerUrl);
    Connection connection = null;
    try {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory("tcp://localhost:61616");
        connection = factory.createConnection(userName, password);
        log.info( "Connection succeeded");
        registerService();
    } catch (Exception ex) {
        log.warn( "Connection failed");
        unregisterService();
    } finally {
        if (null != connection) {
            try {
                connection.close();
            } catch (JMSException jmxEx) {
                log.warn( "Closing connection failed");
            } finally {
                connection = null;
            }
        }
    }
}
 
开发者ID:hqstevenson,项目名称:osgi-dynamic-service,代码行数:24,代码来源:ActiveMQServiceManager.java

示例9: receiveMessage

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static String receiveMessage(MessageListener listener, String brokerHost, String brokerPort, String topic) throws JMSException {
	// Create a ConnectionFactory
	ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));

	// Create a Connection
	Connection connection = connectionFactory.createConnection();
	connection.start();

	// Create a Session
	Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

	// Create the destination (Topic or Queue)
	Destination destination = session.createQueue(topic);

	// register MessageListener
	MessageConsumer consumer = session.createConsumer(destination);
	Message message = consumer.receive();
	if (message instanceof TextMessage) {
		return ((TextMessage) message).getText();
	} else {
		return null;
	}
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:24,代码来源:JMSProvider.java

示例10: initialize

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
@Override
public void initialize(UimaContext aContext) throws ResourceInitializationException {
  super.initialize(aContext);

  String activeMqUrl = (String) aContext.getConfigParameterValue(PARAM_ACTIVE_MQ_URL);
  LOGGER.info("Starting connection to ActiveMQ server: {}", activeMqUrl);
  String queueName = (String) aContext.getConfigParameterValue(PARAM_ACTIVE_MQ_QUEUE_NAME);

  ActiveMQConnectionFactory activeMQConnectionFactory = new ActiveMQConnectionFactory(
      activeMqUrl);
  try {
    connection = activeMQConnectionFactory.createConnection();
    session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue = session.createQueue(queueName);
    messageProducer = session.createProducer(queue);
  } catch (JMSException e) {
    throw new ResourceInitializationException(e);
  }
}
 
开发者ID:nlpie,项目名称:biomedicus,代码行数:21,代码来源:ActiveMqXmiWriter.java

示例11: receiveMessage

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static void receiveMessage(final MessageListener listener, final String brokerHost, final String brokerPort, final String topic) throws JMSException {
	// Create a ConnectionFactory
	final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));

	// Create a Connection
	final Connection connection = connectionFactory.createConnection();
	connection.start();

	// Create a Session
	final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

	// Create the destination (Topic or Queue)
	final Destination destination = session.createQueue(topic);

	// register MessageListener
	final MessageConsumer consumer = session.createConsumer(destination);
	consumer.setMessageListener(listener);
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:19,代码来源:JMSProvider.java

示例12: destroyMessageQueue

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
/**
 * Queues are created dynamically, but can must be destroyed explicitly by
 * calling this method. Queues with active subscribers cannot be destroyed
 * and result in an exception.
 *
 * @param brokerHost
 * @param brokerPort
 * @param topic
 * @throws JMSException
 */
public static void destroyMessageQueue(final String brokerHost, final String brokerPort, final String topic) throws JMSException {
	// Create a ConnectionFactory
	final ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory(String.format("tcp://%s:%s", brokerHost, brokerPort));

	// Create a Connection
	final Connection connection = connectionFactory.createConnection();
	connection.start();

	// Create a Session
	final Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

	// Create the destination (Topic or Queue), close Handle after that
	final Destination destination = session.createQueue(topic);
	session.close();

	// Destroy Empty Queue And Clean Up
	((ActiveMQConnection) connection).destroyDestination((ActiveMQDestination) destination);
	connection.close();
}
 
开发者ID:bptlab,项目名称:Unicorn,代码行数:30,代码来源:JMSProvider.java

示例13: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
/**
 * Prepare to run a test case: create, configure, and start the embedded
 * broker, as well as creating the client connections to the broker.
 */
@Override
@Before
public void setUp() throws java.lang.Exception {
    super.setUp();

    brokerService = new BrokerService();
    configureBroker(brokerService);
    brokerService.start();
    brokerService.waitUntilStarted();

    // Create the ActiveMQConnectionFactory and the JmsPoolConnectionFactory.
    directConnFact = new ActiveMQConnectionFactory(getBrokerConnectionURI());
    pooledConnFact = new JmsPoolConnectionFactory();
    pooledConnFact.setConnectionFactory(directConnFact);

    // Prepare the connections
    directConn1 = directConnFact.createConnection();
    directConn1.start();
    directConn2 = directConnFact.createConnection();
    directConn2.start();

    pooledConn1 = pooledConnFact.createConnection();
    pooledConn1.start();
    pooledConn2 = pooledConnFact.createConnection();
    pooledConn2.start();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:31,代码来源:PooledConnectionTempDestCleanupTest.java

示例14: setUp

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
/**
 * Prepare to run a test case: create, configure, and start the embedded
 * broker, as well as creating the client connections to the broker.
 */
@Override
@Before
public void setUp() throws java.lang.Exception {
    super.setUp();

    brokerService = new BrokerService();
    brokerService.setBrokerName("PooledConnectionSessionCleanupTestBroker");
    brokerService.setUseJmx(true);
    brokerService.getManagementContext().setCreateConnector(false);
    brokerService.setPersistent(false);
    brokerService.setSchedulerSupport(false);
    brokerService.setAdvisorySupport(false);
    brokerService.start();
    brokerService.waitUntilStarted();

    // Create the ActiveMQConnectionFactory and the JmsPoolConnectionFactory.
    // Set a long idle timeout on the pooled connections to better show the
    // problem of holding onto created resources on close.
    directConnFact = new ActiveMQConnectionFactory(brokerService.getVmConnectorURI());
    pooledConnFact = new JmsPoolConnectionFactory();
    pooledConnFact.setConnectionFactory(directConnFact);
    pooledConnFact.setIdleTimeout((int)TimeUnit.MINUTES.toMillis(60));
    pooledConnFact.setMaxConnections(1);

    // Prepare the connections
    directConn1 = directConnFact.createConnection();
    directConn1.start();
    directConn2 = directConnFact.createConnection();
    directConn2.start();

    // The pooled Connections should have the same underlying connection
    pooledConn1 = pooledConnFact.createConnection();
    pooledConn1.start();
    pooledConn2 = pooledConnFact.createConnection();
    pooledConn2.start();
}
 
开发者ID:messaginghub,项目名称:pooled-jms,代码行数:41,代码来源:PooledConnectionSessionCleanupTest.java

示例15: main

import org.apache.activemq.ActiveMQConnectionFactory; //导入方法依赖的package包/类
public static void main(String[] args) {

        try {
            // Create a ConnectionFactory
            ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://Toshiba:61616");

            // Create a Connection
            Connection connection = connectionFactory.createConnection();
            connection.start();

            // Create a Session
            Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

            // Create the destination (Topic or Queue)
            Destination destination = session.createQueue("HELLOWORLD.TESTQ");

            // Create a MessageProducer from the Session to the Topic or Queue
            MessageProducer producer = session.createProducer(destination);
            producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);

            // Create a messages
            String text = "Hello world! From: " + Thread.currentThread().getName();
            TextMessage message = session.createTextMessage(text);

            // Tell the producer to send the message
            System.out.println("Sent message: "+ message.hashCode() + " : " + Thread.currentThread().getName());
            producer.send(message);

            // Clean up
            session.close();
            connection.close();
        }
        catch (Exception e) {
            System.out.println("Caught: " + e);
            e.printStackTrace();
        }
    
	}
 
开发者ID:Illusionist80,项目名称:SpringTutorial,代码行数:39,代码来源:HelloWorldProducer.java


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