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


Java Session.createQueue方法代碼示例

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


在下文中一共展示了Session.createQueue方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testFailedCreateConsumerConnectionStillWorks

import javax.jms.Session; //導入方法依賴的package包/類
@Test
public void testFailedCreateConsumerConnectionStillWorks() throws JMSException {
    Connection connection = pooledConnFact.createConnection("guest", "password");
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(name.getMethodName());

    try {
        session.createConsumer(queue);
        fail("Should fail to create consumer");
    } catch (JMSSecurityException ex) {
        LOG.info("Caught expected security error");
    }

    queue = session.createQueue("GUESTS." + name.getMethodName());

    MessageProducer producer = session.createProducer(queue);
    producer.close();

    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:PooledConnectionSecurityExceptionTest.java

示例2: sendMessages

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

示例3: validateFactoryCreationWithActiveMQLibraries

import javax.jms.Session; //導入方法依賴的package包/類
/**
 * This test simply validates that {@link ConnectionFactory} can be setup by
 * pointing to the location of the client libraries at runtime. It uses
 * ActiveMQ which is not present at the POM but instead pulled from Maven
 * repo using {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which
 * implies that for this test to run the computer must be connected to the
 * Internet. If computer is not connected to the Internet, this test will
 * quietly fail logging a message.
 */
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
    try {
        String libPath = TestUtils.setupActiveMqLibForTesting(true);

        TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
        JMSConnectionFactoryProvider cfProvider = new JMSConnectionFactoryProvider();
        runner.addControllerService("cfProvider", cfProvider);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.BROKER_URI,
                "vm://localhost?broker.persistent=false");
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
        runner.setProperty(cfProvider, JMSConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
                "org.apache.activemq.ActiveMQConnectionFactory");
        runner.enableControllerService(cfProvider);
        runner.assertValid(cfProvider);

        Connection connection = cfProvider.getConnectionFactory().createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination queue = session.createQueue("myqueue");
        MessageProducer producer = session.createProducer(queue);
        MessageConsumer consumer = session.createConsumer(queue);

        TextMessage message = session.createTextMessage("Hello");
        producer.send(message);
        assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
        connection.stop();
        connection.close();
    } catch (Exception e) {
        logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:43,代碼來源:JMSConnectionFactoryProviderTest.java

示例4: testCreateQueue

import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testCreateQueue() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createQueue(getTestName());
    assertNotNull(queue);
    assertEquals(getTestName(), queue.getQueueName());
    assertTrue(queue instanceof MockJMSQueue);
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:10,代碼來源:JmsPoolSessionTest.java

示例5: testTemporaryQueueWithMultipleConnectionUsers

import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTemporaryQueueWithMultipleConnectionUsers() throws Exception {
    JmsPoolConnection connection1 = null;
    JmsPoolConnection connection2 = null;

    MockJMSConnection pooledConnection = null;

    Session session1 = null;
    Session session2 = null;
    Queue tempQueue = null;
    Queue normalQueue = null;

    connection1 = (JmsPoolConnection) cf.createConnection();
    pooledConnection = (MockJMSConnection) connection1.getConnection();
    session1 = connection1.createSession(false, Session.AUTO_ACKNOWLEDGE);
    tempQueue = session1.createTemporaryQueue();
    LOG.info("Created temporary queue named: " + tempQueue.getQueueName());

    assertEquals(1, pooledConnection.getConnectionStats().getActiveTemporaryQueueCount());

    connection2 = (JmsPoolConnection) cf.createConnection();
    assertSame(connection1.getConnection(), connection2.getConnection());
    session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    normalQueue = session2.createQueue("queue:FOO.TEST");
    LOG.info("Created queue named: " + normalQueue.getQueueName());

    // didn't create a temp queue on pooledConnection2 so we should still have a temp queue
    connection2.close();
    assertEquals(1, pooledConnection.getConnectionStats().getActiveTemporaryQueueCount());

    // after closing pooledConnection, where we created the temp queue, there should
    // be no temp queues left
    connection1.close();
    assertEquals(0, pooledConnection.getConnectionStats().getActiveTemporaryQueueCount());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:36,代碼來源:JmsPoolConnectionTemporaryDestinationTest.java

示例6: requeueFailedMessages

import javax.jms.Session; //導入方法依賴的package包/類
@Override
public void requeueFailedMessages() {
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = ActiveMqUtils.startSession(connection);

        int count = getQueueSize(session, queueError);

        if (count < 1) {
            return;
        }

        log.info("Requeuing {} failed messages...", count);

        Queue queueErr = session.createQueue(queueError);
        MessageConsumer consumer = session.createConsumer(queueErr);

        Queue queueRetry = session.createQueue(queueInput);
        MessageProducer producer = session.createProducer(queueRetry);

        for (int consumed = 0; consumed < count; consumed++) {
            TextMessage message = (TextMessage) consumer.receive(REQUEUE_TIMEOUT);

            if (message == null) {
                continue;
            }

            String text = message.getText();
            String requestId = message.getJMSCorrelationID();

            log.info("Requeuing message '{}'", text);

            try {
                TextMessage newMessage = session.createTextMessage(text);
                newMessage.setJMSCorrelationID(requestId);

                producer.send(newMessage);
            } catch (Exception e) {
                log.error("Failed to requeue message", e);
            }

            message.acknowledge();
            session.commit();
        }

        producer.close();
        consumer.close();
    } catch (JMSException ex) {
        throw new MessageQueueException("Failed to requeue failed messages", ex);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:52,代碼來源:ActiveMqListener.java

示例7: validateFactoryCreationWithActiveMQLibraries

import javax.jms.Session; //導入方法依賴的package包/類
/**
 * This test simply validates that {@link ConnectionFactory} can be setup by pointing to the location of the client
 * libraries at runtime. It uses ActiveMQ which is not present at the POM but instead pulled from Maven repo using
 * {@link TestUtils#setupActiveMqLibForTesting(boolean)}, which implies that for this test to run the computer must
 * be connected to the Internet. If computer is not connected to the Internet, this test will quietly fail logging a
 * message.
 */
@Test
public void validateFactoryCreationWithActiveMQLibraries() throws Exception {
    try {
        String libPath = TestUtils.setupActiveMqLibForTesting(true);

        TestRunner runner = TestRunners.newTestRunner(mock(Processor.class));
        JNDIConnectionFactoryProvider cfProvider = new JNDIConnectionFactoryProvider();
        runner.addControllerService("cfProvider", cfProvider);
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.BROKER_URI,
                "vm://localhost?broker.persistent=false");
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.JNDI_CF_LOOKUP, "ConnectionFactory");
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CLIENT_LIB_DIR_PATH, libPath);
        runner.setProperty(cfProvider, JNDIConnectionFactoryProvider.CONNECTION_FACTORY_IMPL,
                "org.apache.activemq.jndi.ActiveMQInitialContextFactory");
        runner.enableControllerService(cfProvider);
        runner.assertValid(cfProvider);

        Connection connection = cfProvider.getConnectionFactory().createConnection();
        connection.start();

        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination queue = session.createQueue("myqueue");
        MessageProducer producer = session.createProducer(queue);
        MessageConsumer consumer = session.createConsumer(queue);

        TextMessage message = session.createTextMessage("Hello");
        producer.send(message);
        assertEquals("Hello", ((TextMessage) consumer.receive()).getText());
        connection.stop();
        connection.close();
    } catch (Exception e) {
        logger.error("'validateFactoryCreationWithActiveMQLibraries' failed due to ", e);
    }
}
 
開發者ID:SolaceLabs,項目名稱:solace-integration-guides,代碼行數:42,代碼來源:JNDIConnectionFactoryProviderTest.java

示例8: testTemporaryQueueWithMultipleConnectionUsers

import javax.jms.Session; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testTemporaryQueueWithMultipleConnectionUsers() throws Exception {
    Connection pooledConnection = null;
    Connection pooledConnection2 = null;
    Session session = null;
    Session session2 = null;
    Queue tempQueue = null;
    Queue normalQueue = null;

    pooledConnection = pooledFactory.createConnection();
    session = pooledConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    tempQueue = session.createTemporaryQueue();
    LOG.info("Created queue named: " + tempQueue.getQueueName());

    assertEquals(1, countBrokerTemporaryQueues());

    pooledConnection2 = pooledFactory.createConnection();
    session2 = pooledConnection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
    normalQueue = session2.createQueue("queue:FOO.TEST");
    LOG.info("Created queue named: " + normalQueue.getQueueName());

    // didn't create a temp queue on pooledConnection2 so we should still have a temp queue
    pooledConnection2.close();
    assertEquals(1, countBrokerTemporaryQueues());

    // after closing pooledConnection, where we created the temp queue, there should
    // be no temp queues left
    pooledConnection.close();
    assertEquals(0, countBrokerTemporaryQueues());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:31,代碼來源:PooledConnectionFactoryWithTemporaryDestinationsTest.java

示例9: testConsumerProducerWithAutoAck

import javax.jms.Session; //導入方法依賴的package包/類
@Parameters({ "broker-port"})
@Test
public void testConsumerProducerWithAutoAck(String port) throws Exception {
    String queueName = "testConsumerProducerWithAutoAck";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder("admin", "admin", "localhost", port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish 100 messages
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

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

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

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

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

示例10: main

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

示例11: main

import javax.jms.Session; //導入方法依賴的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 MessageConsumer from the Session to the Topic or Queue
            MessageConsumer consumer = session.createConsumer(destination);

            // Wait for a message
            Message message = consumer.receive(1000);

            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                String text = textMessage.getText();
                System.out.println("Received: " + text);
            } else {
                System.out.println("Received: " + message);
            }

            consumer.close();
            session.close();
            connection.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    
	}
 
開發者ID:Illusionist80,項目名稱:SpringTutorial,代碼行數:41,代碼來源:HelloWorldConsumer.java

示例12: run

import javax.jms.Session; //導入方法依賴的package包/類
public void run() {
    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() + " : " + this.hashCode();
        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,代碼行數:37,代碼來源:HelloWorldProducerThread.java

示例13: startListener

import javax.jms.Session; //導入方法依賴的package包/類
private void startListener(MessageHandler handler) {
    log.debug("Starting listener...");
    try {
        ActiveMQConnection connection = ActiveMqUtils.openConnection(user, password, url);
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = session.createQueue(queueInput);
        MessageConsumer consumer = session.createConsumer(queue);
        consumer.setMessageListener(message -> handleMessage(handler, message, session));
        log.debug("Listening to {}", queueInput);
    } catch (Exception e) {
        log.error("Error starting listening to queue {}", queueInput, e);
    }
}
 
開發者ID:code-obos,項目名稱:servicebuilder,代碼行數:14,代碼來源:ActiveMqListener.java

示例14: testConsumerWithBasicRecover

import javax.jms.Session; //導入方法依賴的package包/類
@Parameters({ "broker-port", "admin-username", "admin-password", "broker-hostname" })
@Test
public void testConsumerWithBasicRecover(String port,
                                        String adminUsername,
                                        String adminPassword,
                                        String brokerHostname) throws Exception {
    String queueName = "testConsumerWithBasicRecover";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish message
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

    TextMessage firstMessage = producerSession.createTextMessage("First message for reject test");
    TextMessage secondMessage = producerSession.createTextMessage("Second message for reject test");
    String correlationIdOne = "1";
    String correlationIdTwo = "2";
    firstMessage.setJMSCorrelationID(correlationIdOne);
    secondMessage.setJMSCorrelationID(correlationIdTwo);
    producer.send(firstMessage);
    producer.send(secondMessage);
    producerSession.close();

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    Message message = consumer.receive(5000);
    Assert.assertNotNull(message, "Message was not received");

    subscriberSession.recover();

    // Message order can change after recovering
    for (int i = 0; i < 2; i++) {
        message = consumer.receive(5000);
        Assert.assertNotNull(message, "Requeued message was not received");

        if (correlationIdOne.equals(message.getJMSCorrelationID())) {
            Assert.assertTrue(message.getJMSRedelivered(), "Redelivered flag was set in second message" + message);
        } else {
            Assert.assertFalse(message.getJMSRedelivered(), "Redelivered flag was set in first message");
        }

        message.acknowledge();
    }

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

示例15: testConsumerWithBasicReject

import javax.jms.Session; //導入方法依賴的package包/類
@Parameters({ "broker-port", "admin-username", "admin-password", "broker-hostname" })
@Test
public void testConsumerWithBasicReject(String port,
                                        String adminUsername,
                                        String adminPassword,
                                        String brokerHostname) throws Exception {
    System.setProperty("AndesAckWaitTimeOut", "5000");
    String queueName = "testConsumerWithBasicReject";
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(adminUsername, adminPassword, brokerHostname, port)
            .withQueue(queueName)
            .build();

    ConnectionFactory connectionFactory
            = (ConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    Connection connection = connectionFactory.createConnection();
    connection.start();

    // publish message
    Session producerSession = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = producerSession.createQueue(queueName);
    MessageProducer producer = producerSession.createProducer(queue);

    producer.send(producerSession.createTextMessage("Test message for reject test"));
    producerSession.close();

    // Consume published messages
    Session subscriberSession = connection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
    Destination subscriberDestination = (Destination) initialContextForQueue.lookup(queueName);
    MessageConsumer consumer = subscriberSession.createConsumer(subscriberDestination);

    Message message = consumer.receive(5000);
    Assert.assertNotNull(message, "Message was not received");

    message = consumer.receive(10000);
    Assert.assertNotNull(message, "Requeued Message was not received");
    Assert.assertTrue(message.getJMSRedelivered(), "Redelivered flag was not set");
    message.acknowledge();

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


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