本文整理匯總了Java中javax.jms.QueueConnection類的典型用法代碼示例。如果您正苦於以下問題:Java QueueConnection類的具體用法?Java QueueConnection怎麽用?Java QueueConnection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
QueueConnection類屬於javax.jms包,在下文中一共展示了QueueConnection類的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: create
import javax.jms.QueueConnection; //導入依賴的package包/類
public static ManagedConnection create(
final Connection connection ) {
if ( (connection instanceof XAQueueConnection) && (connection instanceof XATopicConnection)) {
return new ManagedXAQueueTopicConnection(connection);
} else if (connection instanceof XAQueueConnection) {
return new ManagedXAQueueConnection((XAQueueConnection) connection);
} else if (connection instanceof XATopicConnection) {
return new ManagedXATopicConnection((XATopicConnection) connection);
} else if ( (connection instanceof QueueConnection) && (connection instanceof TopicConnection)) {
return new ManagedQueueTopicConnection(connection);
} else if (connection instanceof QueueConnection) {
return new ManagedQueueConnection((QueueConnection) connection);
} else if (connection instanceof TopicConnection) {
return new ManagedTopicConnection((TopicConnection) connection);
} else {
return new ManagedConnection(connection);
}
}
示例4: 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!");
}
示例5: createSession
import javax.jms.QueueConnection; //導入依賴的package包/類
/**
* Create a default Session for this ConnectionFactory,
* adapting to JMS 1.0.2 style queue/topic mode if necessary.
* @param con the JMS Connection to operate on
* @param mode the Session acknowledgement mode
* ({@code Session.TRANSACTED} or one of the common modes)
* @return the newly created Session
* @throws JMSException if thrown by the JMS API
*/
protected Session createSession(Connection con, Integer mode) throws JMSException {
// Determine JMS API arguments...
boolean transacted = (mode == Session.SESSION_TRANSACTED);
int ackMode = (transacted ? Session.AUTO_ACKNOWLEDGE : mode);
// Now actually call the appropriate JMS factory method...
if (Boolean.FALSE.equals(this.pubSubMode) && con instanceof QueueConnection) {
return ((QueueConnection) con).createQueueSession(transacted, ackMode);
}
else if (Boolean.TRUE.equals(this.pubSubMode) && con instanceof TopicConnection) {
return ((TopicConnection) con).createTopicSession(transacted, ackMode);
}
else {
return con.createSession(transacted, ackMode);
}
}
示例6: 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);
}
示例7: testWithQueueConnectionFactoryAndJms102Usage
import javax.jms.QueueConnection; //導入依賴的package包/類
@Test
public void testWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
QueueConnection con = mock(QueueConnection.class);
given(cf.createQueueConnection()).willReturn(con);
SingleConnectionFactory scf = new SingleConnectionFactory(cf);
Connection con1 = scf.createQueueConnection();
Connection con2 = scf.createQueueConnection();
con1.start();
con2.start();
con1.close();
con2.close();
scf.destroy(); // should trigger actual close
verify(con).start();
verify(con).stop();
verify(con).close();
verifyNoMoreInteractions(con);
}
示例8: getQueueConnection
import javax.jms.QueueConnection; //導入依賴的package包/類
public QueueConnection getQueueConnection(QueueConnectionFactory qcf)
throws JMSException {
final QueueConnection qc;
final String username = Config.parms.getString("us");
if (username != null && username.length() != 0) {
Log.logger.log(Level.INFO, "getQueueConnection(): authenticating as \"" + username + "\"");
final String password = Config.parms.getString("pw");
qc = qcf.createQueueConnection(username, password);
} else {
qc = qcf.createQueueConnection();
}
return qc;
}
示例9: 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();
}
}
}
}
示例10: 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();
}
}
示例11: 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();
}
}
示例12: 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();
}
}
示例13: 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();
}
}
示例14: 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();
}
}
示例15: 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();
}
}