本文整理匯總了Java中javax.jms.QueueSession.createQueue方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueSession.createQueue方法的具體用法?Java QueueSession.createQueue怎麽用?Java QueueSession.createQueue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.QueueSession
的用法示例。
在下文中一共展示了QueueSession.createQueue方法的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();
}
示例2: 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();
}
示例3: receiveMessagesFromQueue
import javax.jms.QueueSession; //導入方法依賴的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();
}
示例4: testCreateQueueSender
import javax.jms.QueueSession; //導入方法依賴的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();
}
示例5: createQueue
import javax.jms.QueueSession; //導入方法依賴的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;
}
示例6: 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();
}
示例7: lookupQueue
import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
* <b>JMS 1.0.2</b>
* @return A valid Queue object created either from JNDI lookup or directly from the given session.
*/
public DestinationWrapper<Queue> lookupQueue(String uri, QueueSession session) throws JMSException, NamingException {
if ( usingJNDI ) {
return lookupQueueFromJNDI( uri );
} else {
return new DestinationWrapper<Queue>( uri, session.createQueue( uri ) );
}
}
示例8: 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());
sender = session.createSender(destination);
sender.close();
}
示例9: 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();
}
示例10: testSpecificQueueRetrieval
import javax.jms.QueueSession; //導入方法依賴的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();
}
示例11: testNonExistingConsumer
import javax.jms.QueueSession; //導入方法依賴的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.");
}
示例12: getBeans
import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
* Read the status beans from any queue.
* Returns a list of optionally date-ordered beans in the queue.
*
* @param uri
* @param queueName
* @param clazz
* @param monitor
* @return
* @throws Exception
*/
public List<T> getBeans(final URI uri, final String queueName, final Class<T> beanClass) throws Exception {
QueueConnection qCon = null;
try {
QueueConnectionFactory connectionFactory = (QueueConnectionFactory)service.createConnectionFactory(uri);
qCon = connectionFactory.createQueueConnection(); // This times out when the server is not there.
QueueSession qSes = qCon.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = qSes.createQueue(queueName);
qCon.start();
QueueBrowser qb = qSes.createBrowser(queue);
@SuppressWarnings("rawtypes")
Enumeration e = qb.getEnumeration();
final Collection<T> list;
if (comparator!=null) {
list = new TreeSet<T>(comparator);
} else {
list = new ArrayList<T>(17);
}
while(e.hasMoreElements()) {
Message m = (Message)e.nextElement();
if (m==null) continue;
if (m instanceof TextMessage) {
TextMessage t = (TextMessage)m;
String json = t.getText();
@SuppressWarnings("unchecked")
final Class<T> statusBeanClass = (Class<T>) StatusBean.class;
try {
final T bean = (T)service.unmarshal(json, beanClass != null ? beanClass : statusBeanClass);
list.add(bean);
} catch (Exception unmarshallable) {
System.out.println("Removing old message "+json);
String jMSMessageID = m.getJMSMessageID();
if (jMSMessageID!=null) {
MessageConsumer consumer = qSes.createConsumer(queue, "JMSMessageID = '"+jMSMessageID+"'");
Message ignored = consumer.receive(1000);
consumer.close();
System.out.println("Removed");
}
}
}
}
return list instanceof List ? (List<T>)list : new ArrayList<T>(list);
} finally {
if (qCon!=null) qCon.close();
}
}
示例13: sendTextMessage
import javax.jms.QueueSession; //導入方法依賴的package包/類
/**
* Sends a JMS text message.
*
* @param contextUrl
* null for local queues
* @param queueName
* local queues are based on logical queue names
* @param message
* the message string
* @param delaySeconds
* 0 for immediate
* @throws ServiceLocatorException
*/
public void sendTextMessage(String contextUrl, String queueName, String message,
int delaySeconds, String correlationId)
throws NamingException, JMSException, ServiceLocatorException {
if (logger.isDebugEnabled())
logger.debug("Send JMS message: " + message);
if (mdwMessageProducer != null) {
if (logger.isDebugEnabled())
logger.debug("Send JMS message: queue " + queueName + " corrId " + correlationId
+ " delay " + delaySeconds);
mdwMessageProducer.sendMessage(message, queueName, correlationId, delaySeconds,
DeliveryMode.NON_PERSISTENT);
}
else {
QueueConnection connection = null;
QueueSession session = null;
QueueSender sender = null;
Queue queue = null;
try {
QueueConnectionFactory connectionFactory = getQueueConnectionFactory(contextUrl);
connection = connectionFactory.createQueueConnection();
session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
if (contextUrl == null)
queue = getQueue(session, queueName);
else
queue = getQueue(contextUrl, queueName);
if (queue == null)
queue = session.createQueue(queueName);
sender = session.createSender(queue);
TextMessage textMessage = session.createTextMessage(message);
if (delaySeconds > 0)
jmsProvider.setMessageDelay(sender, textMessage, delaySeconds);
if (correlationId != null)
textMessage.setJMSCorrelationID(correlationId);
connection.start();
if (contextUrl == null)
sender.send(textMessage, DeliveryMode.NON_PERSISTENT, sender.getPriority(),
sender.getTimeToLive());
else
sender.send(textMessage);
// }
// catch(ServiceLocatorException ex) {
// logger.severeException(ex.getMessage(), ex);
// JMSException jmsEx = new JMSException(ex.getMessage());
// jmsEx.setLinkedException(ex);
// throw jmsEx;
}
finally {
closeResources(connection, session, sender);
}
}
}
示例14: createActiveMQQueue
import javax.jms.QueueSession; //導入方法依賴的package包/類
protected Queue createActiveMQQueue(QueueSession session, String queueName) throws JMSException {
return session.createQueue(queueName);
}
示例15: test
import javax.jms.QueueSession; //導入方法依賴的package包/類
@Test(timeout = 5 * 60 * 1000)
public void test() throws Throwable {
executeCommand("bundle:list");
withinReason(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
assertTrue("artemis bundle installed", verifyBundleInstalled("artemis-server-osgi"));
return true;
}
});
Object service = waitForService("(objectClass=org.apache.activemq.artemis.core.server.ActiveMQServer)", 30000);
assertNotNull(service);
LOG.info("have service " + service);
executeCommand("service:list -n");
Connection connection = null;
try {
JmsConnectionFactory factory = new JmsConnectionFactory("amqp://localhost:5672");
connection = factory.createConnection(USER, PASSWORD);
connection.start();
QueueSession sess = (QueueSession) connection.createSession(false, javax.jms.Session.AUTO_ACKNOWLEDGE);
Queue queue = sess.createQueue("exampleQueue");
MessageProducer producer = sess.createProducer(queue);
producer.send(sess.createTextMessage("TEST"));
// Test browsing
try (QueueBrowser browser = sess.createBrowser(queue)) {
Enumeration messages = browser.getEnumeration();
while (messages.hasMoreElements()) {
messages.nextElement();
}
}
// Test management
Queue managementQueue = sess.createQueue("activemq.management");
QueueRequestor requestor = new QueueRequestor(sess, managementQueue);
connection.start();
TextMessage m = sess.createTextMessage();
m.setStringProperty("_AMQ_ResourceName", "broker");
m.setStringProperty("_AMQ_OperationName", "getQueueNames");
m.setText("[\"ANYCAST\"]");
Message reply = requestor.request(m);
String json = ((TextMessage) reply).getText();
JsonArray array = Json.createReader(new StringReader(json)).readArray();
List<JsonString> queues = (List<JsonString>) array.get(0);
assertNotNull(queues);
assertFalse(queues.isEmpty());
MessageConsumer consumer = sess.createConsumer(queue);
Message msg = consumer.receive(5000);
assertNotNull(msg);
} finally {
if (connection != null) {
connection.close();
}
}
}