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


Java QueueSession.close方法代碼示例

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


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

示例1: testSpecificConsumerRetrieval

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

import javax.jms.QueueSession; //導入方法依賴的package包/類
/** Send a JSON message to our notification queue.
 */
public void invokeJMS(JsonObject json) throws JMSException, NamingException {
	if (!initialized) initialize(); //gets our JMS managed resources (Q and QCF)

	QueueConnection connection = queueCF.createQueueConnection();
	QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

	TextMessage message = session.createTextMessage(json.toString());
	System.out.println("Sending "+json.toString()+" to "+queue.getQueueName());
	QueueSender sender = session.createSender(queue);
	sender.send(message);

	sender.close();
	session.close();
	connection.close();

	System.out.println("Message sent successfully!");
}
 
開發者ID:IBMStockTrader,項目名稱:loyalty-level,代碼行數:20,代碼來源:LoyaltyLevel.java

示例3: send

import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
 * Sends a message to the myWMS application inside the application
 * server.
 * 
 * @param mfcMessage the message to be send
 * @throws JMSException
 * @throws NamingException
 */
public void send(MFCMessage mfcMessage)
    throws JMSException,
        NamingException
{

    // create the jms session
    QueueSession session =
        connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    // lookup of the jms queue over jndi
    Queue outputQueue =
        (Queue) context.lookup("queue/" + OUTPUT_QUEUE_NAME);

    // create the message publisher
    QueueSender sender = session.createSender(outputQueue);

    ObjectMessage objectMessage = session.createObjectMessage();
    objectMessage.setObject(mfcMessage);
    objectMessage.setJMSTimestamp(System.currentTimeMillis());

    sender.send(objectMessage);
    sender.close();

    session.close();
}
 
開發者ID:salimvanak,項目名稱:myWMS,代碼行數:34,代碼來源:ServerConnection.java

示例4: acknowledge

import javax.jms.QueueSession; //導入方法依賴的package包/類
private void acknowledge(Message jmsMessage, String msgid) throws JMSException, ServiceLocatorException {
        QueueConnection connection = null;
        QueueSession session = null;
        QueueSender sender = null;
        try {
            Queue respQueue = (Queue) jmsMessage.getJMSReplyTo();
            QueueConnectionFactory qcf = JMSServices.getInstance().getQueueConnectionFactory(null);
            connection = qcf.createQueueConnection();
            session = connection.createQueueSession(false, QueueSession.DUPS_OK_ACKNOWLEDGE);
            sender = session.createSender(respQueue);
            Message respMsg = session.createTextMessage(msgid);
//        respMsg.setJMSCorrelationID(correlationId); not used
            sender.send(respMsg);
        } finally {
            if (sender != null) sender.close();
            if (session != null) session.close();
            if (connection != null) connection.close();
        }
    }
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:20,代碼來源:InternalEventListener.java

示例5: initializeInboundDestinationBridgesOutboundSide

import javax.jms.QueueSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException {
    if (inboundQueueBridges != null) {
        QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (InboundQueueBridge bridge : inboundQueueBridges) {
            String queueName = bridge.getInboundQueueName();
            Queue foreignQueue = createForeignQueue(outboundSession, queueName);
            bridge.setConsumer(null);
            bridge.setConsumerQueue(foreignQueue);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        outboundSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:17,代碼來源:SimpleJmsQueueConnector.java

示例6: initializeInboundDestinationBridgesLocalSide

import javax.jms.QueueSession; //導入方法依賴的package包/類
protected void initializeInboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException {
    if (inboundQueueBridges != null) {
        QueueSession localSession = connection.createQueueSession(false,Session.AUTO_ACKNOWLEDGE);

        for (InboundQueueBridge bridge : inboundQueueBridges) {
            String localQueueName = bridge.getLocalQueueName();
            Queue activemqQueue = createActiveMQQueue(localSession, localQueueName);
            bridge.setProducerQueue(activemqQueue);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getInboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addInboundBridge(bridge);
        }
        localSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:19,代碼來源:SimpleJmsQueueConnector.java

示例7: initializeOutboundDestinationBridgesOutboundSide

import javax.jms.QueueSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesOutboundSide(QueueConnection connection) throws JMSException {
    if (outboundQueueBridges != null) {
        QueueSession outboundSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundQueueBridge bridge : outboundQueueBridges) {
            String queueName = bridge.getOutboundQueueName();
            Queue foreignQueue = createForeignQueue(outboundSession, queueName);
            bridge.setProducerQueue(foreignQueue);
            bridge.setProducerConnection(connection);
            if (bridge.getJmsMessageConvertor() == null) {
                bridge.setJmsMessageConvertor(getOutboundMessageConvertor());
            }
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        outboundSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:19,代碼來源:SimpleJmsQueueConnector.java

示例8: initializeOutboundDestinationBridgesLocalSide

import javax.jms.QueueSession; //導入方法依賴的package包/類
protected void initializeOutboundDestinationBridgesLocalSide(QueueConnection connection) throws JMSException {
    if (outboundQueueBridges != null) {
        QueueSession localSession =
                connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        for (OutboundQueueBridge bridge : outboundQueueBridges) {
            String localQueueName = bridge.getLocalQueueName();
            Queue activemqQueue = createActiveMQQueue(localSession, localQueueName);
            bridge.setConsumer(null);
            bridge.setConsumerQueue(activemqQueue);
            bridge.setConsumerConnection(connection);
            bridge.setJmsConnector(this);
            addOutboundBridge(bridge);
        }
        localSession.close();
    }
}
 
開發者ID:DiamondLightSource,項目名稱:daq-eclipse,代碼行數:18,代碼來源:SimpleJmsQueueConnector.java

示例9: publishMessagesToQueue

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

示例10: testCreateReceiverQueue

import javax.jms.QueueSession; //導入方法依賴的package包/類
public void testCreateReceiverQueue() throws Exception
{        
    QueueSession session;       
    session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    
    try
    {
        session.createReceiver(null);
        fail("Should have failed");
    }
    catch (JMSException e)
    {
        assertTrue(e.getMessage().indexOf("destination") != -1);
    }
    
    session.createReceiver(queue1);
    session.close();
}
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:19,代碼來源:LocalQueueSessionTest.java

示例11: testCreateReceiverQueueString

import javax.jms.QueueSession; //導入方法依賴的package包/類
public void testCreateReceiverQueueString() throws Exception
{
    QueueSession session;       
    session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    
    try
    {
        session.createReceiver(null,null);
        fail("Should have failed");
    }
    catch (JMSException e)
    {
        assertTrue(e.getMessage().indexOf("destination") != -1);
    }
    
    session.createReceiver(queue1,null);
    session.createReceiver(queue1,"JMSMessageID='toto'");
    session.close();
}
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:20,代碼來源:LocalQueueSessionTest.java

示例12: testRetrieveConsumerList

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

示例13: closeResources

import javax.jms.QueueSession; //導入方法依賴的package包/類
private void closeResources(QueueConnection pConn, QueueSession pSession, QueueSender pSender)
        throws JMSException {
    if (pSender != null) {
        pSender.close();
    }
    if (pSession != null) {
        pSession.close();
    }
    if (pConn != null) {
        pConn.close();
    }
}
 
開發者ID:CenturyLinkCloud,項目名稱:mdw,代碼行數:13,代碼來源:JMSServices.java

示例14: testCreateSenderQueue

import javax.jms.QueueSession; //導入方法依賴的package包/類
public void testCreateSenderQueue() throws Exception
{
    QueueSession session;       
    session = ((QueueConnection)connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    session.createSender(null);
    session.createSender(queue1);
    session.close();
}
 
開發者ID:timewalker74,項目名稱:ffmq,代碼行數:9,代碼來源:LocalQueueSessionTest.java

示例15: rollback

import javax.jms.QueueSession; //導入方法依賴的package包/類
public static final void rollback(QueueSession aSession)
{
  if (aSession == null) return;
  try
  {
    aSession.rollback();
    aSession.close();
  }
  catch (Exception e)
  {
  }
}
 
開發者ID:objectof-group,項目名稱:objectof,代碼行數:13,代碼來源:IMsgSender.java


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