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


Java QueueSession.createReceiver方法代碼示例

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


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

示例1: testGetQueue

import javax.jms.QueueSession; //導入方法依賴的package包/類
@Test
public void testGetQueue() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueReceiver receiver = session.createReceiver(queue);

    assertNotNull(receiver.getQueue());
    assertSame(queue, receiver.getQueue());

    receiver.close();

    try {
        receiver.getQueue();
        fail("Cannot read topic on closed receiver");
    } catch (IllegalStateException ise) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolQueueReceiverTest.java

示例2: testGetTopicSubscriber

import javax.jms.QueueSession; //導入方法依賴的package包/類
@Test
public void testGetTopicSubscriber() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueReceiver receiver = (JmsPoolQueueReceiver) session.createReceiver(queue);

    assertNotNull(receiver.getQueueReceiver());
    assertTrue(receiver.getQueueReceiver() instanceof MockJMSQueueReceiver);

    receiver.close();

    try {
        receiver.getQueueReceiver();
        fail("Cannot read state on closed receiver");
    } catch (IllegalStateException ise) {}
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:18,代碼來源:JmsPoolQueueReceiverTest.java

示例3: 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

示例4: testCreateReceiverWithMessageSelector

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

示例5: createReceiver

import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
 * Create a queue receiver
 *
 * @param queue The queue
 * @return The queue receiver
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueReceiver createReceiver(final Queue queue) throws JMSException {
   lock();
   try {
      QueueSession session = getQueueSessionInternal();

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue);
      }

      QueueReceiver result = session.createReceiver(queue);
      result = new ActiveMQRAQueueReceiver(result, this);

      if (ActiveMQRASession.trace) {
         ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
      }

      addConsumer(result);

      return result;
   } finally {
      unlock();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:32,代碼來源:ActiveMQRASession.java

示例6: 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

示例7: 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

示例8: testQueueReceiversAndTopicSubscriber

import javax.jms.QueueSession; //導入方法依賴的package包/類
public void testQueueReceiversAndTopicSubscriber() throws Exception
{
    Queue queue = new AMQAnyDestination("ADDR:my-queue; {create: always}");
    Topic topic = new AMQAnyDestination("ADDR:amq.topic/test");
    
    QueueSession qSession = ((AMQConnection)_connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    QueueReceiver receiver = qSession.createReceiver(queue);
    
    TopicSession tSession = ((AMQConnection)_connection).createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
    TopicSubscriber sub = tSession.createSubscriber(topic);
    
    Session ssn = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    MessageProducer prod1 = ssn.createProducer(ssn.createQueue("ADDR:my-queue"));
    prod1.send(ssn.createTextMessage("test1"));
    
    MessageProducer prod2 = ssn.createProducer(ssn.createTopic("ADDR:amq.topic/test"));
    prod2.send(ssn.createTextMessage("test2"));
    
    Message msg1 = receiver.receive();
    assertNotNull(msg1);
    assertEquals("test1",((TextMessage)msg1).getText());
    
    Message msg2 = sub.receive();
    assertNotNull(msg2);
    assertEquals("test2",((TextMessage)msg2).getText());  
}
 
開發者ID:wso2,項目名稱:andes,代碼行數:27,代碼來源:AddressBasedDestinationTest.java

示例9: createReceiver

import javax.jms.QueueSession; //導入方法依賴的package包/類
public QueueReceiver createReceiver(Queue queue) throws JMSException {
    lock();
    try {
        QueueSession session = getQueueSession();
        if (trace)
            log.trace("createReceiver " + session + " queue=" + queue);
        QueueReceiver result = session.createReceiver(queue);
        result = new JmsQueueReceiver(result, this);
        if (trace)
            log.trace("createdReceiver " + session + " receiver=" + result);
        addConsumer(result);
        return result;
    } finally {
        unlock();
    }
}
 
開發者ID:vratsel,項目名稱:generic-jms-ra,代碼行數:17,代碼來源:JmsSession.java

示例10: testToString

import javax.jms.QueueSession; //導入方法依賴的package包/類
@Test
public void testToString() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueReceiver receiver = session.createReceiver(queue);

    assertNotNull(receiver.toString());
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:10,代碼來源:JmsPoolQueueReceiverTest.java

示例11: 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

示例12: testTempQueueDelete

import javax.jms.QueueSession; //導入方法依賴的package包/類
@Test
public void testTempQueueDelete() throws Exception {
   connection.start();
   QueueSession queueSession = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   TemporaryQueue tempQueue = queueSession.createTemporaryQueue();

   ActiveMQConnection newConn = (ActiveMQConnection) factory.createConnection();
   try {
      QueueSession newQueueSession = newConn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = newQueueSession.createSender(tempQueue);

      Message msg = queueSession.createMessage();
      queueSender.send(msg);

      try {
         QueueReceiver consumer = newQueueSession.createReceiver(tempQueue);
         fail("should have gotten exception but got consumer: " + consumer);
      } catch (JMSException ex) {
         //correct
      }

      connection.close();

      try {
         Message newMsg = newQueueSession.createMessage();
         queueSender.send(newMsg);
      } catch (JMSException e) {
         //ok
      }

   } finally {
      newConn.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:36,代碼來源:SimpleOpenWireTest.java

示例13: testTryToReproduceNullPointerBug

import javax.jms.QueueSession; //導入方法依賴的package包/類
public void testTryToReproduceNullPointerBug() throws Exception {
   String url = connectionUri;
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
   QueueConnection queueConnection = factory.createQueueConnection();
   this.connection = queueConnection;
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createSender(null); // Unidentified
   Queue receiverQueue = session.createTemporaryQueue();
   session.createReceiver(receiverQueue);
   queueConnection.start();
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:12,代碼來源:CreateTemporaryQueueBeforeStartTest.java

示例14: doExecuteRequest

import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
 * Actually execute the given request, sending the invoker request message
 * to the specified target queue and waiting for a corresponding response.
 * <p>The default implementation is based on standard JMS send/receive,
 * using a {@link javax.jms.TemporaryQueue} for receiving the response.
 * @param session the JMS Session to use
 * @param queue the resolved target Queue to send to
 * @param requestMessage the JMS Message to send
 * @return the RemoteInvocationResult object
 * @throws JMSException in case of JMS failure
 */
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
	TemporaryQueue responseQueue = null;
	MessageProducer producer = null;
	MessageConsumer consumer = null;
	try {
		if (jms11Available) {
			// Standard JMS 1.1 API usage...
			responseQueue = session.createTemporaryQueue();
			producer = session.createProducer(queue);
			consumer = session.createConsumer(responseQueue);
			requestMessage.setJMSReplyTo(responseQueue);
			producer.send(requestMessage);
		}
		else {
			// Perform all calls on QueueSession reference for JMS 1.0.2 compatibility...
			// DEPRECATED but kept around with the deprecated JmsTemplate102 etc classes for the time being.
			QueueSession queueSession = (QueueSession) session;
			responseQueue = queueSession.createTemporaryQueue();
			QueueSender sender = queueSession.createSender(queue);
			producer = sender;
			consumer = queueSession.createReceiver(responseQueue);
			requestMessage.setJMSReplyTo(responseQueue);
			sender.send(requestMessage);
		}
		long timeout = getReceiveTimeout();
		return (timeout > 0 ? consumer.receive(timeout) : consumer.receive());
	}
	finally {
		JmsUtils.closeMessageConsumer(consumer);
		JmsUtils.closeMessageProducer(producer);
		if (responseQueue != null) {
			responseQueue.delete();
		}
	}
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:47,代碼來源:JmsInvokerClientInterceptor.java

示例15: createTestResources

import javax.jms.QueueSession; //導入方法依賴的package包/類
protected void createTestResources() throws Exception {
    connection = createQueueConnectionToMockProvider();
    QueueSession session = ((QueueConnection) connection).createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue destination = session.createQueue(_testName.getMethodName());
    receiver = session.createReceiver(destination);
    receiver.close();
}
 
開發者ID:apache,項目名稱:qpid-jms,代碼行數:8,代碼來源:JmsQueueReceiverClosedTest.java


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