本文整理匯總了Java中javax.jms.QueueConnection.close方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueConnection.close方法的具體用法?Java QueueConnection.close怎麽用?Java QueueConnection.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.QueueConnection
的用法示例。
在下文中一共展示了QueueConnection.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSenderAndPublisherDest
import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testSenderAndPublisherDest() throws Exception {
JmsPoolXAConnectionFactory pcf = new JmsPoolXAConnectionFactory();
pcf.setConnectionFactory(new ActiveMQXAConnectionFactory(
"vm://test?broker.persistent=false&broker.useJmx=false"));
QueueConnection connection = pcf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(session.createQueue("AA"));
assertNotNull(sender.getQueue().getQueueName());
connection.close();
TopicConnection topicConnection = pcf.createTopicConnection();
TopicSession topicSession = topicConnection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
TopicPublisher topicPublisher = topicSession.createPublisher(topicSession.createTopic("AA"));
assertNotNull(topicPublisher.getTopic().getTopicName());
topicConnection.close();
pcf.stop();
}
示例2: 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();
}
示例3: invokeJMS
import javax.jms.QueueConnection; //導入方法依賴的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!");
}
示例4: 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);
}
示例5: 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();
}
}
}
}
示例6: acknowledge
import javax.jms.QueueConnection; //導入方法依賴的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();
}
}
示例7: sendMessage
import javax.jms.QueueConnection; //導入方法依賴的package包/類
/**
* Send a message to testInboundQueue queue
*
* @throws Exception
*/
private void sendMessage() throws Exception {
InitialContext initialContext = JmsClientHelper.getActiveMqInitialContext();
QueueConnectionFactory connectionFactory
= (QueueConnectionFactory) initialContext.lookup(JmsClientHelper.QUEUE_CONNECTION_FACTORY);
QueueConnection queueConnection = connectionFactory.createQueueConnection();
QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
QueueSender sender = queueSession.createSender(queueSession.createQueue(QUEUE_NAME));
String message = "<?xml version='1.0' encoding='UTF-8'?>" +
" <ser:getQuote xmlns:ser=\"http://services.samples\" xmlns:xsd=\"http://services.samples/xsd\"> " +
" <ser:request>" +
" <xsd:symbol>IBM</xsd:symbol>" +
" </ser:request>" +
" </ser:getQuote>";
try {
TextMessage jmsMessage = queueSession.createTextMessage(message);
jmsMessage.setJMSType("incorrecttype");
sender.send(jmsMessage);
} finally {
queueConnection.close();
}
}
示例8: 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();
}
示例9: testConnectionCredentialsFail
import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testConnectionCredentialsFail() throws Exception {
resourceAdapter = newResourceAdapter();
MyBootstrapContext ctx = new MyBootstrapContext();
resourceAdapter.start(ctx);
ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
mcf.setResourceAdapter(resourceAdapter);
ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
queueConnection.close();
mc.destroy();
try {
queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
fail("should throw esxception");
} catch (JMSException e) {
//pass
}
}
示例10: 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);
}
}
示例11: 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);
}
示例12: 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);
}
示例13: testCreateQueueConnectionGoodProviderString
import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test(timeout=20000)
public void testCreateQueueConnectionGoodProviderString() throws Exception {
try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
// Ignore errors from peer close due to not sending any Open / Close frames
testPeer.setSuppressReadExceptionOnClose(true);
// DONT create a test fixture, we will drive everything directly.
testPeer.expectSaslAnonymous();
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://127.0.0.1:" + testPeer.getServerPort());
QueueConnection connection = factory.createQueueConnection();
assertNotNull(connection);
testPeer.waitForAllHandlersToComplete(1000);
testPeer.expectOpen();
testPeer.expectClose();
connection.close();
testPeer.waitForAllHandlersToCompleteNoAssert(1000);
}
}
示例14: testCreateQueueSender
import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test
public void testCreateQueueSender() throws Exception {
JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerAmqpConnectionURI());
QueueConnection connection = factory.createQueueConnection();
assertNotNull(connection);
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
assertNotNull(session);
Queue queue = session.createQueue(name.getMethodName());
QueueSender sender = session.createSender(queue);
assertNotNull(sender);
QueueViewMBean proxy = getProxyToQueue(name.getMethodName());
assertEquals(0, proxy.getQueueSize());
connection.close();
}
示例15: testQueueCreateConnection
import javax.jms.QueueConnection; //導入方法依賴的package包/類
@Test(timeout = 60000)
public void testQueueCreateConnection() throws Exception {
QueueConnection connection = cf.createQueueConnection();
assertNotNull(connection);
assertEquals(1, cf.getNumConnections());
connection.close();
assertEquals(1, cf.getNumConnections());
}