本文整理匯總了Java中javax.jms.QueueSender.close方法的典型用法代碼示例。如果您正苦於以下問題:Java QueueSender.close方法的具體用法?Java QueueSender.close怎麽用?Java QueueSender.close使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.jms.QueueSender
的用法示例。
在下文中一共展示了QueueSender.close方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testGetQueue
import javax.jms.QueueSender; //導入方法依賴的package包/類
@Test
public void testGetQueue() throws JMSException {
JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
Queue queue = session.createTemporaryQueue();
QueueSender sender = session.createSender(queue);
assertNotNull(sender.getQueue());
assertSame(queue, sender.getQueue());
sender.close();
try {
sender.getQueue();
fail("Cannot read topic on closed sender");
} catch (IllegalStateException ise) {}
}
示例2: invokeJMS
import javax.jms.QueueSender; //導入方法依賴的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!");
}
示例3: send
import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
* Sends a message to the myWMS application inside the application
* server.
*
* @param mfcMessage the message to be send
* @throws JMSException
* @throws NamingException
*/
public void send(MFCMessage mfcMessage)
throws JMSException,
NamingException
{
// create the jms session
QueueSession session =
connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
// lookup of the jms queue over jndi
Queue outputQueue =
(Queue) context.lookup("queue/" + OUTPUT_QUEUE_NAME);
// create the message publisher
QueueSender sender = session.createSender(outputQueue);
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(mfcMessage);
objectMessage.setJMSTimestamp(System.currentTimeMillis());
sender.send(objectMessage);
sender.close();
session.close();
}
示例4: acknowledge
import javax.jms.QueueSender; //導入方法依賴的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();
}
}
示例5: sendReply
import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
* Intended for server-side reponse sending and implies that the received
* message *always* contains a reply-to address.
*/
public void sendReply(QueueSession session, Message received_message, String response) throws IfsaException {
QueueSender tqs=null;
try {
TextMessage answer = session.createTextMessage();
answer.setText(response);
Queue replyQueue = (Queue)received_message.getJMSReplyTo();
tqs = session.createSender(replyQueue );
if (log.isDebugEnabled()) log.debug(getLogPrefix()+ "sending reply to ["+ received_message.getJMSReplyTo()+ "]");
((IFSAServerQueueSender) tqs).sendReply(received_message, answer);
} catch (Throwable t) {
throw new IfsaException(t);
} finally {
if (tqs!=null) {
try {
tqs.close();
} catch (JMSException e) {
log.warn(getLogPrefix()+ "exception closing reply queue sender",e);
}
}
}
}
示例6: closeResources
import javax.jms.QueueSender; //導入方法依賴的package包/類
private void closeResources(QueueConnection pConn, QueueSession pSession, QueueSender pSender)
throws JMSException {
if (pSender != null) {
pSender.close();
}
if (pSession != null) {
pSession.close();
}
if (pConn != null) {
pConn.close();
}
}
示例7: sendAMessage
import javax.jms.QueueSender; //導入方法依賴的package包/類
public void sendAMessage(String msg) throws JMSException {
QueueSender send = session.createSender(que);
TextMessage tm = session.createTextMessage(msg);
send.send(tm);
send.close();
}
示例8: run
import javax.jms.QueueSender; //導入方法依賴的package包/類
@Override
public void run()
{
super.run();
try
{
QueueSender sender = getSession().createSender(queue);
startSynchro.waitFor();
for (int n = 0 ; n < messageCount ; n++)
{
variableWait();
int msgPriority = (priority != -1) ? priority : random.nextInt(10);
Message message = msgFactory.createDummyMessage(messageSize);
sender.send(message, deliveryMode, msgPriority, timeToLive);
if (transacted)
getSession().commit();
}
sender.close();
//System.out.println(getName()+" thread complete ("+messageCount+" messages sent)");
}
catch (Throwable e)
{
inError = true;
e.printStackTrace();
}
}
示例9: testMultipleCloseCallsNoErrors
import javax.jms.QueueSender; //導入方法依賴的package包/類
@Test(timeout = 10000)
public void testMultipleCloseCallsNoErrors() throws Exception {
Queue queue = session.createQueue(getTestName());
QueueSender sender = session.createSender(queue);
sender.close();
sender.close();
}
示例10: sendByQueue
import javax.jms.QueueSender; //導入方法依賴的package包/類
protected String sendByQueue(QueueSession session, Queue destination,
Message message) throws NamingException, JMSException {
QueueSender tqs = session.createSender(destination);
tqs.send(message);
tqs.close();
return message.getJMSMessageID();
}
示例11: send
import javax.jms.QueueSender; //導入方法依賴的package包/類
public void send(String request) throws JMSException {
TextMessage message = session.createTextMessage(request);
message.setJMSReplyTo(responseQueue);
QueueSender sender = null;
try {
sender = session.createSender(requestQueue);
sender.send(message);
} finally {
if (sender != null) sender.close();
}
}
示例12: close
import javax.jms.QueueSender; //導入方法依賴的package包/類
private void close(QueueSender queueSender) {
if (queueSender != null) {
try {
queueSender.close();
} catch (JMSException e) {
LOG.error("Couldn't close QueueSender", e);
}
}
}
示例13: sendRequest
import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
* Send an AnalysisRequest to the JMS request queue. Note this method does not store anything
* in the cache.
* @throws JMSException
* @see sendRequest(Query query, AnalysisRequest request)
*/
public void sendRequest(AnalysisRequest request) throws JMSException {
ObjectMessage msg;
try {
QueueSession requestSession = queueConnection.createQueueSession(
// No transaction
false,
// Auto ack
Session.AUTO_ACKNOWLEDGE);
// Create a message
msg = requestSession.createObjectMessage(request);
msg.setJMSReplyTo(resultQueue);
QueueSender requestSender = requestSession.createSender(requestQueue);
// Send the message
requestSender.send(msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
requestSender.close();
requestSession.close();
logger.debug("sendRequest session: "+request.getSessionId()+" & task: "+request.getTaskId()+" has been sent to the JMQ");
} catch (JMSException e) {
logger.error(e);
throw e;
}
}
示例14: sendRequest
import javax.jms.QueueSender; //導入方法依賴的package包/類
/**
* Send an AnalysisRequest to the JMS request queue. Note this method does not store anything
* in the cache.
* @throws JMSException
* @see sendRequest(Query query, AnalysisRequest request)
*/
public void sendRequest(final AnalysisRequest request) throws JMSException {
ObjectMessage msg;
try {
if(managedBean) {
queueConnection = queueConnectionFactory.createQueueConnection();
}
QueueSession requestSession = queueConnection.createQueueSession(
// No transaction
false,
// Auto ack
Session.AUTO_ACKNOWLEDGE);
// Create a message
msg = requestSession.createObjectMessage(request);
msg.setJMSReplyTo(resultQueue);
QueueSender requestSender = requestSession.createSender(requestQueue);
// Send the message
requestSender.send(msg, DeliveryMode.NON_PERSISTENT, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
requestSender.close();
requestSession.close();
if(managedBean) {
queueConnection.close();
}
logger.debug("sendRequest session: "+request.getSessionId()+" & task: "+request.getTaskId()+" has been sent to the JMQ");
} catch (JMSException e) {
logger.error(e);
throw e;
}
}
示例15: main
import javax.jms.QueueSender; //導入方法依賴的package包/類
public static void main(String[] args) {
String queueConnectionFactoryName = "myjmsconnectionfactory"; //JMS Connection Factory的JNDI
String queueName = "myjmsqueue"; //JMS Queue或者JMS Topic的JNDI
boolean transacted = false;//transaction模式
int acknowledgementMode = Session.AUTO_ACKNOWLEDGE;//acknowledgement模式
String message="Message need to send";//模擬需要發送的消息
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, "t3://localhost:7001");
try {
Context context = new InitialContext(properties);
Object obj = context.lookup(queueConnectionFactoryName);
QueueConnectionFactory queueConnectionFactory = (QueueConnectionFactory) obj;//JMS Connection Factory的獲得
obj = context.lookup(queueName);
Queue queue = (Queue) obj;//JMS Queue或者JMS Topic的獲得
QueueConnection queueConnection=queueConnectionFactory.createQueueConnection();//產生連接
queueConnection.start();
QueueSession queueSession = queueConnection.createQueueSession(transacted, acknowledgementMode);
TextMessage textMessage = queueSession.createTextMessage();
textMessage.clearBody();
textMessage.setText(message);
QueueSender queueSender = queueSession.createSender(queue);
queueSender.send(textMessage);
if (transacted) {
queueSession.commit();
}
if (queueSender != null) {
queueSender.close();
}
if (queueSession != null) {
queueSession.close();
}
if (queueConnection != null) {
queueConnection.close();
}
}
catch(Exception ex){
ex.printStackTrace();
}
}