本文整理汇总了Java中javax.jms.QueueReceiver.close方法的典型用法代码示例。如果您正苦于以下问题:Java QueueReceiver.close方法的具体用法?Java QueueReceiver.close怎么用?Java QueueReceiver.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.jms.QueueReceiver
的用法示例。
在下文中一共展示了QueueReceiver.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testGetQueue
import javax.jms.QueueReceiver; //导入方法依赖的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) {}
}
示例2: testSpecificConsumerRetrieval
import javax.jms.QueueReceiver; //导入方法依赖的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();
}
示例3: testRetrieveConsumerList
import javax.jms.QueueReceiver; //导入方法依赖的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();
}
示例4: releaseReceiver
import javax.jms.QueueReceiver; //导入方法依赖的package包/类
protected void releaseReceiver(QueueReceiver receiver) throws ListenerException {
if (isSessionsArePooled() && receiver != null) {
try {
receiver.close();
// do not write to log, this occurs too often
} catch (Exception e) {
throw new ListenerException(getLogPrefix()+"exception closing QueueReceiver", e);
}
}
}
示例5: closeReplyReceiver
import javax.jms.QueueReceiver; //导入方法依赖的package包/类
public void closeReplyReceiver(QueueReceiver receiver) throws IfsaException {
try {
if (receiver!=null) {
Queue replyQueue = receiver.getQueue();
receiver.close();
releaseClientReplyQueue(replyQueue);
}
} catch (JMSException e) {
throw new IfsaException(e);
}
}
示例6: testSpecificQueueRetrieval
import javax.jms.QueueReceiver; //导入方法依赖的package包/类
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificQueueRetrieval(String username, String password, String hostname, String port)
throws JMSException, NamingException, IOException {
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 receiver = queueSession.createReceiver(queue);
// Test queue retrieval through REST API
HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/" + queueName);
CloseableHttpResponse response = client.execute(httpGet);
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK, "Incorrect status code.");
String body = EntityUtils.toString(response.getEntity());
QueueMetadata queueMetadata = objectMapper.readValue(body, QueueMetadata.class);
Assert.assertEquals(queueMetadata.getName(), queueName, "Incorrect queue name.");
Assert.assertEquals(queueMetadata.getConsumerCount().intValue(), 1, "JMS consumer should be present.");
Assert.assertTrue(queueMetadata.isDurable());
Assert.assertEquals(queueMetadata.getSize().intValue(), 0, "Queue should be empty.");
Assert.assertFalse(queueMetadata.isAutoDelete());
receiver.close();
queueSession.close();
connection.close();
}
示例7: testNonExistingConsumer
import javax.jms.QueueReceiver; //导入方法依赖的package包/类
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testNonExistingConsumer(String username, String password,
String hostname, String port) throws Exception {
String queueName = "testNonExistingConsumer";
// 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);
HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
+ "/" + queueName + "/consumers");
CloseableHttpResponse response = client.execute(getAllConsumers);
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK,
"Incorrect status code");
String consumerArray = EntityUtils.toString(response.getEntity());
ConsumerMetadata[] consumers = objectMapper.readValue(consumerArray, ConsumerMetadata[].class);
Assert.assertEquals(consumers.length, 1, "There should be a single consumer");
int id = consumers[0].getId();
receiver1.close();
HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
+ "/" + queueName + "/consumers/" + String.valueOf(id));
response = client.execute(getConsumer);
Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_NOT_FOUND);
String errorMessage = EntityUtils.toString(response.getEntity());
Error error = objectMapper.readValue(errorMessage, Error.class);
Assert.assertFalse(error.getMessage().isEmpty(), "Error message should be non empty.");
}