本文整理匯總了Java中javax.jms.QueueConnection.createQueueSession方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueConnection.createQueueSession方法的具體用法?Java QueueConnection.createQueueSession怎麽用?Java QueueConnection.createQueueSession使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.QueueConnection
的用法示例。
在下文中一共展示了QueueConnection.createQueueSession方法的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: 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();
}
}
}
}
示例5: 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();
}
}
示例6: 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();
}
}
示例7: ReorderRequestMessageListener
import javax.jms.QueueConnection; //導入方法依賴的package包/類
public ReorderRequestMessageListener() {
try {
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
properties.put(CF_NAME_PREFIX + CF_NAME, getTCPConnectionURL(USERNAME, PASSWORD));
properties.put(QUEUE_NAME_PREFIX + REORDER_REQUEST_QUEUE, REORDER_REQUEST_QUEUE);
InitialContext ctx = new InitialContext(properties);
// Lookup connection factory
QueueConnectionFactory connFactory = (QueueConnectionFactory) ctx.lookup(CF_NAME);
QueueConnection queueConnection = connFactory.createQueueConnection();
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
//Receive message
Queue queue = (Queue) ctx.lookup(REORDER_REQUEST_QUEUE);
MessageConsumer consumer = queueSession.createConsumer(queue);
consumer.setMessageListener(this);
} catch (NamingException | JMSException e) {
e.printStackTrace();
}
}
示例8: initializeInboundDestinationBridgesOutboundSide
import javax.jms.QueueConnection; //導入方法依賴的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();
}
}
示例9: initializeInboundDestinationBridgesLocalSide
import javax.jms.QueueConnection; //導入方法依賴的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();
}
}
示例10: initializeOutboundDestinationBridgesOutboundSide
import javax.jms.QueueConnection; //導入方法依賴的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();
}
}
示例11: initializeOutboundDestinationBridgesLocalSide
import javax.jms.QueueConnection; //導入方法依賴的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();
}
}
示例12: 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();
}
示例13: receiveMessagesFromQueue
import javax.jms.QueueConnection; //導入方法依賴的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();
}
示例14: 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);
}
}
示例15: 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();
}