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


Java QueueConnection.start方法代碼示例

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


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

示例1: testSpecificConsumerRetrieval

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificConsumerRetrieval(String username, String password,
                                          String hostname, String port) throws Exception {
    String queueName = "testSpecificConsumerRetrieval";

    // Create a durable queue using a JMS client
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(username, password, hostname, port)
            .withQueue(queueName)
            .build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();

    QueueSession queueSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(queueName);
    QueueReceiver receiver = queueSession.createReceiver(queue);

    HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");

    CloseableHttpResponse response = client.execute(getAllConsumers);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String body = EntityUtils.toString(response.getEntity());

    ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);

    Assert.assertTrue(consumers.length > 0, "Number of consumers returned is incorrect.");

    int id = consumers[0].getId();
    HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/"
                                              + queueName + "/consumers/" + id);

    response = client.execute(getConsumer);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK);
    String consumerString = EntityUtils.toString(response.getEntity());
    ConsumerMetadata consumerMetadata = objectMapper.readValue(consumerString, ConsumerMetadata.class);

    Assert.assertEquals(consumerMetadata.getId().intValue(), id, "incorrect message id");

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

示例2: testWithQueueConnection

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testWithQueueConnection() throws JMSException {
	Connection con = mock(QueueConnection.class);

	SingleConnectionFactory scf = new SingleConnectionFactory(con);
	QueueConnection con1 = scf.createQueueConnection();
	con1.start();
	con1.stop();
	con1.close();
	QueueConnection con2 = scf.createQueueConnection();
	con2.start();
	con2.stop();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(con, times(2)).start();
	verify(con, times(2)).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:SingleConnectionFactoryTests.java

示例3: sendTextMessage

import javax.jms.QueueConnection; //導入方法依賴的package包/類
public String sendTextMessage(String queueName, String msg) throws Exception {

        if (StringUtils.isBlank(queueName)) {
            throw new IllegalArgumentException("Queue can not be null!");
        }

        if (logger.isDebugEnabled()) {

            StringBuilder sb = new StringBuilder();
            sb.append("sendTextMessage :: Setting params... \n");
            sb.append("\t- queueManagerName = '{}' \n");
            sb.append("\t- queueName = '{}' \n");
            sb.append("\t- replyToQueueName = '{}' \n");
            sb.append("\t- hostname = '{}' \n");
            sb.append("\t- port = '{}' \n");
            sb.append("\t- channel = '{}' \n");

            LoggerUtils.logDebug(logger, sb.toString(), queueManagerName, queueName, responseQueueName, hostname, port,
                channel);
        }

        QueueConnection connection = null;
        TextMessage requestMessage;
        try {

            QueueConnectionFactory qcf = new MQQueueConnectionFactory();
            ((MQQueueConnectionFactory) qcf).setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                WMQConstants.WMQ_CM_CLIENT);
            ((MQQueueConnectionFactory) qcf).setHostName(hostname);
            ((MQQueueConnectionFactory) qcf).setPort(port);
            ((MQQueueConnectionFactory) qcf).setQueueManager(queueManagerName);
            if (StringUtils.isNotBlank(channel)) {
                ((MQQueueConnectionFactory) qcf).setChannel(channel);
            }
            // ((MQQueueConnectionFactory) qcf).setCCSID(500);

            connection = qcf.createQueueConnection(" ", " ");
            connection.start();

            // Create a session
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);

            // Get a request queue
            Queue queue = ((MQQueueSession) session).createQueue("queue://" + queueManagerName + "/" + queueName);

            // Create message sender
            QueueSender sender = session.createSender(queue);
            requestMessage = session.createTextMessage(msg);
            // m1.setIntProperty("JMS_", MQC.MQENC_NATIVE);

            // Setting reply-to queue
            Queue queueResp = ((MQQueueSession) session)
                .createQueue("queue://" + queueManagerName + "/" + responseQueueName);
            requestMessage.setJMSReplyTo(queueResp);
            LoggerUtils.logDebug(logger, "sendTextMessage :: message \n{}", requestMessage.toString());

            sender.send(requestMessage);
            LoggerUtils.logDebug(logger, "sendTextMessage :: Message Sent! ID: {} \n",
                requestMessage.getJMSMessageID());

            return requestMessage.getJMSMessageID();

        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException je) {
                    je.printStackTrace();
                }
            }
        }
    }
 
開發者ID:dalifreire,項目名稱:mq-gateway,代碼行數:73,代碼來源:MQGatewayImpl.java

示例4: ReorderRequestMessageListener

import javax.jms.QueueConnection; //導入方法依賴的package包/類
public ReorderRequestMessageListener() {
    try {
        Properties properties = new Properties();
        properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
        properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
        properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
        InitialContext ctx = new InitialContext(properties);
        // Lookup connection factory
        QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
        QueueConnection queueConnection = connFactory.createQueueConnection();
        queueConnection.start();
        QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
        //Receive message
        Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
        MessageConsumer consumer = queueSession.createConsumer(queue);
        consumer.setMessageListener(this);
    } catch (NamingException | JMSException e) {
        e.printStackTrace();
    }
}
 
開發者ID:afkham,項目名稱:msf4j-queueing,代碼行數:21,代碼來源:ReorderRequestMessageListener.java

示例5: publishMessagesToQueue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
 * To publish the messages to a queue.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void publishMessagesToQueue(String queueName) throws JMSException, InterruptedException {
    QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
    queueConn.start();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = queueSession.createQueue(queueName);
    MessageProducer queueSender = queueSession.createProducer(destination);
    queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    for (int index = 0; index < 10; index++) {
        String queueText = "Queue Message : " + (index + 1);
        TextMessage queueMessage = queueSession.createTextMessage(queueText);
        queueSender.send(queueMessage);
        Thread.sleep(1000);
        logger.info("Publishing " + queueText + " to queue " + queueName);
    }
    queueConn.close();
    queueSession.close();
    queueSender.close();
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:25,代碼來源:JMSServer.java

示例6: receiveMessagesFromQueue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
 * To receive a message from a queue.
 *
 * @throws JMSException         JMS Exception.
 * @throws InterruptedException Interrupted exception while waiting in between messages.
 */
public void receiveMessagesFromQueue() throws JMSException, InterruptedException {
    QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
    QueueSession queueSession = queueConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = queueSession.createQueue(JMSTestConstants.QUEUE_NAME_1);
    MessageConsumer queueReceiver = queueSession.createConsumer(destination);
    MessageListener listener = message -> {
        try {
            if (message instanceof TextMessage) {
                TextMessage textMessage = (TextMessage) message;
                logger.info("Message text received : " + (textMessage.getText()));
            }
        } catch (JMSException e) {
            logger.info("JMS exception occurred.");
        }
    };
    queueReceiver.setMessageListener(listener);
    queueConn.start();
}
 
開發者ID:wso2,項目名稱:carbon-transports,代碼行數:25,代碼來源:JMSServer.java

示例7: testCreateReceiverWithMessageSelector

import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
 * com.sun.ts.tests.jms.ee.all.queueconn.QueueConnTest line 171
 */
@Test
public void testCreateReceiverWithMessageSelector() throws Exception {
   QueueConnection qc = null;

   try {
      qc = createQueueConnection();
      QueueSession qs = qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      QueueReceiver qreceiver = qs.createReceiver(queue1, "targetMessage = TRUE");

      qc.start();

      TextMessage m = qs.createTextMessage();
      m.setText("one");
      m.setBooleanProperty("targetMessage", false);

      QueueSender qsender = qs.createSender(queue1);

      qsender.send(m);

      m.setText("two");
      m.setBooleanProperty("targetMessage", true);

      qsender.send(m);

      TextMessage rm = (TextMessage) qreceiver.receive(1000);

      ProxyAssertSupport.assertEquals("two", rm.getText());
   } finally {
      if (qc != null) {
         qc.close();
      }
      Thread.sleep(2000);
      removeAllMessages(queue1.getQueueName(), true);
      checkEmpty(queue1);
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:41,代碼來源:QueueReceiverTest.java

示例8: testWithQueueConnection

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testWithQueueConnection() throws JMSException {
	Connection con = mock(QueueConnection.class);

	SingleConnectionFactory scf = new SingleConnectionFactory(con);
	QueueConnection con1 = scf.createQueueConnection();
	con1.start();
	con1.stop();  // should be ignored
	con1.close();  // should be ignored
	QueueConnection con2 = scf.createQueueConnection();
	con2.start();
	con2.stop();  // should be ignored
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:21,代碼來源:SingleConnectionFactoryTests.java

示例9: testConnectionFactory102WithQueue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testConnectionFactory102WithQueue() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);

	given(cf.createQueueConnection()).willReturn(con);

	SingleConnectionFactory scf = new SingleConnectionFactory102(cf, false);
	QueueConnection con1 = scf.createQueueConnection();
	con1.start();
	con1.close();  // should be ignored
	QueueConnection con2 = scf.createQueueConnection();
	con2.start();
	con2.close();  // should be ignored
	scf.destroy();  // should trigger actual close

	verify(con).start();
	verify(con).stop();
	verify(con).close();
	verifyNoMoreInteractions(con);
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:22,代碼來源:SingleConnectionFactoryTests.java

示例10: createQueue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
public static Queue createQueue(String uri, String queueName) throws JMSException {
	QueueConnectionFactory connectionFactory = null;
	QueueConnection connection = null;
	QueueSession session = null;
	Queue queue = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createQueueConnection();
		connection.start();
		session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		queue = session.createQueue(queueName);
		session.commit();
	} finally {
		closeQuietly(session);
		closeQuietly(connection);
	}
	return queue;
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:19,代碼來源:MsgUtils.java

示例11: produceTextMsg2Queue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
 * Product message for assigned queue.
 * 
 * @param uri
 *            e.g.: tcp://3CNL12096:61616
 * @param queueName
 *            name of queue
 * @throws JMSException
 */
public static void produceTextMsg2Queue(String uri, String queueName, String text) throws JMSException {
	QueueConnectionFactory connectionFactory = null;
	QueueConnection connection = null;
	QueueSession session = null;
	MessageProducer mp = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createQueueConnection();
		connection.start();
		session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		mp = session.createProducer(session.createQueue(queueName));
		mp.setDeliveryMode(DeliveryMode.PERSISTENT);
		mp.send(session.createTextMessage(text));
		session.commit();
	} finally {
		closeQuietly(mp);
		closeQuietly(session);
		closeQuietly(connection);
	}
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:30,代碼來源:MsgUtils.java

示例12: consumeTextMsg4Queue

import javax.jms.QueueConnection; //導入方法依賴的package包/類
public static String consumeTextMsg4Queue(String uri, String queueName) throws JMSException {
	QueueConnectionFactory connectionFactory = null;
	QueueConnection connection = null;
	QueueSession session = null;
	TextMessage msg = null;
	MessageConsumer consumer = null;
	try {
		connectionFactory = new ActiveMQConnectionFactory(uri);
		connection = connectionFactory.createQueueConnection();
		connection.start();
		session = connection.createQueueSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
		consumer = session.createConsumer(session.createQueue(queueName));
		msg = (TextMessage) consumer.receive();
		session.commit();
	} finally {
		closeQuietly(consumer);
		closeQuietly(session);
		closeQuietly(connection);
	}
	if (msg == null)
		return null;
	else
		return msg.getText();
}
 
開發者ID:slimsymphony,項目名稱:testgrid,代碼行數:25,代碼來源:MsgUtils.java

示例13: testRetrieveConsumerList

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testRetrieveConsumerList(String username, String password,
                                     String hostname, String port) throws Exception {
    String queueName = "testSpecificQueueRetrieval";


    // Create a durable queue using a JMS client
    InitialContext initialContextForQueue = ClientHelper
            .getInitialContextBuilder(username, password, hostname, port)
            .withQueue(queueName)
            .build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContextForQueue.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();

    QueueSession queueSession = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
    Queue queue = queueSession.createQueue(queueName);
    QueueReceiver receiver1 = queueSession.createReceiver(queue);
    QueueReceiver receiver2 = queueSession.createReceiver(queue);

    HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");

    CloseableHttpResponse response = client.execute(httpGet);
    String body = EntityUtils.toString(response.getEntity());

    ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);

    Assert.assertEquals(consumers.length, 2, "Number of consumers returned is incorrect.");

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

示例14: testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage

import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:40,代碼來源:SingleConnectionFactoryTests.java

示例15: receiveTextMessage

import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
 * Recupera as mensagens da fila de reponse de acordo com o messageID passado como parametro.
 *
 * @param messageID
 * @return String
 * @throws JMSException
 */
public String receiveTextMessage(String messageID) throws JMSException {

    if (StringUtils.isEmpty(messageID)) {
        throw new IllegalArgumentException(BundleMenssageUtils.getMensagem("mensagem.selector.null"));
    }

    if (StringUtils.isBlank(this.responseQueueName)) {
        throw new IllegalArgumentException(BundleMenssageUtils.getMensagem("mensagem.fila.response.null"));
    }

    LoggerUtils.logDebug(logger, "receiveTextMessage :: Selecting response message using: '{}'", messageID);
    String resMessage = null;

    long finishTime = System.currentTimeMillis() + totalTimeOut;
    while (StringUtils.isBlank(resMessage) && (System.currentTimeMillis() < finishTime)) {

        QueueConnection connection = null;
        TextMessage receivedMessage;
        try {

            QueueConnectionFactory qcf = new MQQueueConnectionFactory();
            ((MQQueueConnectionFactory) qcf).setIntProperty(WMQConstants.WMQ_CONNECTION_MODE,
                WMQConstants.WMQ_CM_CLIENT);
            ((MQQueueConnectionFactory) qcf).setHostName(hostname);
            ((MQQueueConnectionFactory) qcf).setPort(port);
            ((MQQueueConnectionFactory) qcf).setQueueManager(queueManagerName);
            if (StringUtils.isNotBlank(channel)) {
                ((MQQueueConnectionFactory) qcf).setChannel(channel);
            }
            // ((MQQueueConnectionFactory) qcf).setCCSID(500);

            connection = qcf.createQueueConnection();
            connection.start();

            // Create a session
            MQQueueSession session = (MQQueueSession) connection.createQueueSession(false,
                Session.CLIENT_ACKNOWLEDGE);

            // Get a response queue
            Queue responseQueue = ((MQQueueSession) session)
                .createQueue("queue://" + queueManagerName + "/" + responseQueueName);
            MQQueueReceiver receiver = (MQQueueReceiver) session.createReceiver(responseQueue);

            receivedMessage = (TextMessage) receiver.receive(totalTimeOut);
            if (receivedMessage != null) {
                resMessage = receivedMessage.getText();
                receivedMessage.acknowledge();
                LoggerUtils.logDebug(logger, "receiveTextMessage :: Response = '{}' \n", resMessage);
            }

        } finally {
            if (connection != null) {
                try {
                    connection.close();
                } catch (JMSException je) {
                    je.printStackTrace();
                }
            }
        }

    }

    return resMessage;
}
 
開發者ID:dalifreire,項目名稱:mq-gateway,代碼行數:72,代碼來源:MQGatewayImpl.java


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