當前位置: 首頁>>代碼示例>>Java>>正文


Java TemporaryQueue類代碼示例

本文整理匯總了Java中javax.jms.TemporaryQueue的典型用法代碼示例。如果您正苦於以下問題:Java TemporaryQueue類的具體用法?Java TemporaryQueue怎麽用?Java TemporaryQueue使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TemporaryQueue類屬於javax.jms包,在下文中一共展示了TemporaryQueue類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sendWithReplyToTemp

import javax.jms.TemporaryQueue; //導入依賴的package包/類
private void sendWithReplyToTemp(ConnectionFactory cf, String serviceQueue) throws JMSException, InterruptedException {
    Connection connection = cf.createConnection();
    connection.start();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    TextMessage msg = session.createTextMessage("Request");
    msg.setJMSReplyTo(tempQueue);
    MessageProducer producer = session.createProducer(session.createQueue(serviceQueue));
    producer.send(msg);

    MessageConsumer consumer = session.createConsumer(tempQueue);
    Message replyMsg = consumer.receive();
    assertNotNull(replyMsg);

    LOG.debug("Reply message: {}", replyMsg);

    consumer.close();

    producer.close();
    session.close();
    connection.close();
}
 
開發者ID:messaginghub,項目名稱:pooled-jms,代碼行數:23,代碼來源:PooledConnectionTempQueueTest.java

示例2: doExecuteRequest

import javax.jms.TemporaryQueue; //導入依賴的package包/類
/**
 * Actually execute the given request, sending the invoker request message
 * to the specified target queue and waiting for a corresponding response.
 * <p>The default implementation is based on standard JMS send/receive,
 * using a {@link javax.jms.TemporaryQueue} for receiving the response.
 * @param session the JMS Session to use
 * @param queue the resolved target Queue to send to
 * @param requestMessage the JMS Message to send
 * @return the RemoteInvocationResult object
 * @throws JMSException in case of JMS failure
 */
protected Message doExecuteRequest(Session session, Queue queue, Message requestMessage) throws JMSException {
	TemporaryQueue responseQueue = null;
	MessageProducer producer = null;
	MessageConsumer consumer = null;
	try {
		responseQueue = session.createTemporaryQueue();
		producer = session.createProducer(queue);
		consumer = session.createConsumer(responseQueue);
		requestMessage.setJMSReplyTo(responseQueue);
		producer.send(requestMessage);
		long timeout = getReceiveTimeout();
		return (timeout > 0 ? consumer.receive(timeout) : consumer.receive());
	}
	finally {
		JmsUtils.closeMessageConsumer(consumer);
		JmsUtils.closeMessageProducer(producer);
		if (responseQueue != null) {
			responseQueue.delete();
		}
	}
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:33,代碼來源:JmsInvokerClientInterceptor.java

示例3: oneIteration

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public final boolean oneIteration() throws Exception {
	if ((tempQueues) && (tempQueuePerMessage)) {
		// Close existing temporary queue
		if (messageConsumer != null) messageConsumer.close();
		if (destConsumer != null) {
			((TemporaryQueue) destConsumer).delete();
		}
		
		// Open new temporary queue
		destConsumer = context.createTemporaryQueue();
		messageConsumer = context.createConsumer(destConsumer);
		outMessage.setJMSReplyTo(destConsumer);
	}
	
	messageProducer.send(destProducer, outMessage);				
	if ( transacted ) context.commit();
	
	if ((inMessage = messageConsumer.receive(timeout)) != null) {
		if ( transacted ) context.commit();
		incIterations();
	} else {
		throw new Exception("No response to message (\nID: " + outMessage.getJMSMessageID() + "\nCorrID: " + outMessage.getJMSCorrelationID() +" )");
	}
	return true;
}
 
開發者ID:ot4i,項目名稱:perf-harness,代碼行數:26,代碼來源:Requestor.java

示例4: oneIteration

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public final boolean oneIteration() throws Exception {
	if ((tempQueues) && (tempQueuePerMessage)) {
		// Close temporary queue
		if (messageConsumer != null) messageConsumer.close();
		if (destConsumer != null) {
			((TemporaryQueue) destConsumer).delete();
		}
		
		// Open new temporary queue
		destConsumer = session.createTemporaryQueue();
		messageConsumer = session.createConsumer(destConsumer);
		outMessage.setJMSReplyTo(destConsumer);
	}
	
	startResponseTimePeriod();
	messageProducer.send(outMessage, deliveryMode, priority, expiry);				
	if (transacted) session.commit();
	
	if ((inMessage = messageConsumer.receive(timeout))!= null) {
		if (transacted) session.commit();
		incIterations();
	} else {
		throw new Exception("No response to message (\nID: "+outMessage.getJMSMessageID()+ "\nCorrId: " + outMessage.getJMSCorrelationID() +")");
	}
	return true;
}
 
開發者ID:ot4i,項目名稱:perf-harness,代碼行數:27,代碼來源:Requestor.java

示例5: loadTemporaryDestinationTypes

import javax.jms.TemporaryQueue; //導入依賴的package包/類
protected void loadTemporaryDestinationTypes(JmsOperations template) {
    if (template == null) {
        throw new IllegalArgumentException("No JmsTemplate supplied!");
    }
    template.execute(new SessionCallback<Object>() {
        public Object doInJms(Session session) throws JMSException {
            TemporaryQueue queue = session.createTemporaryQueue();
            setTemporaryQueueType(queue.getClass());

            TemporaryTopic topic = session.createTemporaryTopic();
            setTemporaryTopicType(topic.getClass());

            queue.delete();
            topic.delete();
            return null;
        }
    });
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:19,代碼來源:JmsProviderMetadata.java

示例6: testTemporaryDestinationTypes

import javax.jms.TemporaryQueue; //導入依賴的package包/類
@Test
public void testTemporaryDestinationTypes() throws Exception {
    JmsEndpoint endpoint = getMandatoryEndpoint("activemq:test.queue", JmsEndpoint.class);
    JmsConfiguration configuration = endpoint.getConfiguration();
    JmsProviderMetadata providerMetadata = configuration.getProviderMetadata();
    assertNotNull("provider", providerMetadata);

    Class<? extends TemporaryQueue> queueType = endpoint.getTemporaryQueueType();
    Class<? extends TemporaryTopic> topicType = endpoint.getTemporaryTopicType();

    log.info("Found queue type: " + queueType);
    log.info("Found topic type: " + topicType);

    assertNotNull("queueType", queueType);
    assertNotNull("topicType", topicType);

    assertEquals("queueType", ActiveMQTempQueue.class, queueType);
    assertEquals("topicType", ActiveMQTempTopic.class, topicType);
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:20,代碼來源:JmsProviderTest.java

示例7: FileClient

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public FileClient(String filename) throws NamingException, JMSException {
	Context ctx = new InitialContext();
	ConnectionFactory factory = (ConnectionFactory) ctx.lookup("ConnectionFactory");
	Destination requestQueue = (Destination) ctx.lookup(DESTINATION);
	mConnection = factory.createConnection();
	mConnection.start();
	mSession = mConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
	mMessageProducer = mSession.createProducer(requestQueue);
	TemporaryQueue replyQueue = null;
	replyQueue = mSession.createTemporaryQueue();
	mMessageConsumer = mSession.createConsumer(replyQueue);
	TextMessage request = mSession.createTextMessage();
	request.setText(filename);
	request.setJMSReplyTo(replyQueue);
	mMessageProducer.send(request);
}
 
開發者ID:marcelherd,項目名稱:hochschule-mannheim,代碼行數:17,代碼來源:FileClient.java

示例8: testReplyToUsingQueue

import javax.jms.TemporaryQueue; //導入依賴的package包/類
@Test(timeout = 60000)
public void testReplyToUsingQueue() throws Throwable {
   Connection connection = createConnection();

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TemporaryQueue queue = session.createTemporaryQueue();
      MessageProducer p = session.createProducer(queue);

      TextMessage message = session.createTextMessage();
      message.setText("Message temporary");
      message.setJMSReplyTo(session.createQueue(getQueueName()));
      p.send(message);

      MessageConsumer cons = session.createConsumer(queue);
      connection.start();

      message = (TextMessage) cons.receive(5000);
      assertNotNull(message);
      Destination jmsReplyTo = message.getJMSReplyTo();
      assertNotNull(jmsReplyTo);
      assertNotNull(message);
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:27,代碼來源:JMSMessageProducerTest.java

示例9: testReplyToUsingTempQueue

import javax.jms.TemporaryQueue; //導入依賴的package包/類
@Test(timeout = 60000)
public void testReplyToUsingTempQueue() throws Throwable {
   Connection connection = createConnection();

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TemporaryQueue queue = session.createTemporaryQueue();
      MessageProducer p = session.createProducer(queue);

      TextMessage message = session.createTextMessage();
      message.setText("Message temporary");
      message.setJMSReplyTo(session.createTemporaryQueue());
      p.send(message);

      MessageConsumer cons = session.createConsumer(queue);
      connection.start();

      message = (TextMessage) cons.receive(5000);
      Destination jmsReplyTo = message.getJMSReplyTo();
      assertNotNull(jmsReplyTo);
      assertNotNull(message);
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:JMSMessageProducerTest.java

示例10: testCreateTemporaryQueue

import javax.jms.TemporaryQueue; //導入依賴的package包/類
@Test(timeout = 60000)
public void testCreateTemporaryQueue() throws Throwable {
   Connection connection = createConnection();

   try {
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      TemporaryQueue queue = session.createTemporaryQueue();
      System.out.println("queue:" + queue.getQueueName());
      MessageProducer producer = session.createProducer(queue);

      TextMessage message = session.createTextMessage();
      message.setText("Message temporary");
      producer.send(message);

      MessageConsumer consumer = session.createConsumer(queue);
      connection.start();

      message = (TextMessage) consumer.receive(5000);

      assertNotNull(message);
   } finally {
      connection.close();
   }
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:25,代碼來源:JMSTemporaryDestinationTest.java

示例11: testTempQueues

import javax.jms.TemporaryQueue; //導入依賴的package包/類
@Test
public void testTempQueues() throws Exception {
   TemporaryQueue temp = localSession.createTemporaryQueue();
   MessageProducer producer = localSession.createProducer(temp);
   producer.send(localSession.createTextMessage("test"));
   Thread.sleep(100);
   assertEquals("Destination not created", 1, remoteBroker.getAdminView().getTemporaryQueues().length);
   temp.delete();

   assertTrue("Destination not deleted", Wait.waitFor(new Wait.Condition() {
      @Override
      public boolean isSatisified() throws Exception {
         return 0 == remoteBroker.getAdminView().getTemporaryQueues().length;
      }
   }));
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:17,代碼來源:DuplexNetworkTest.java

示例12: testNoSlowConsumerAdvisory

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public void testNoSlowConsumerAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TemporaryQueue queue = s.createTemporaryQueue();
   MessageConsumer consumer = s.createConsumer(queue);
   consumer.setMessageListener(new MessageListener() {
      @Override
      public void onMessage(Message message) {
      }
   });
   Topic advisoryTopic = AdvisorySupport.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
   s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   // start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      BytesMessage m = s.createBytesMessage();
      m.writeBytes(new byte[1024]);
      producer.send(m);
   }
   Message msg = advisoryConsumer.receive(1000);
   assertNull(msg);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:23,代碼來源:AdvisoryTempDestinationTests.java

示例13: testSlowConsumerAdvisory

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public void testSlowConsumerAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TemporaryQueue queue = s.createTemporaryQueue();
   MessageConsumer consumer = s.createConsumer(queue);
   assertNotNull(consumer);

   Topic advisoryTopic = AdvisorySupport.getSlowConsumerAdvisoryTopic((ActiveMQDestination) queue);
   s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   // start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);
   for (int i = 0; i < MESSAGE_COUNT; i++) {
      BytesMessage m = s.createBytesMessage();
      m.writeBytes(new byte[1024]);
      producer.send(m);
   }
   Message msg = advisoryConsumer.receive(1000);
   assertNotNull(msg);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:20,代碼來源:AdvisoryTempDestinationTests.java

示例14: testMessageDeliveryAdvisory

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public void testMessageDeliveryAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TemporaryQueue queue = s.createTemporaryQueue();
   MessageConsumer consumer = s.createConsumer(queue);
   assertNotNull(consumer);

   Topic advisoryTopic = AdvisorySupport.getMessageDeliveredAdvisoryTopic((ActiveMQDestination) queue);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   //start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);

   BytesMessage m = s.createBytesMessage();
   m.writeBytes(new byte[1024]);
   producer.send(m);

   Message msg = advisoryConsumer.receive(1000);
   assertNotNull(msg);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:19,代碼來源:AdvisoryTempDestinationTests.java

示例15: testTempMessageConsumedAdvisory

import javax.jms.TemporaryQueue; //導入依賴的package包/類
public void testTempMessageConsumedAdvisory() throws Exception {
   Session s = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   TemporaryQueue queue = s.createTemporaryQueue();
   MessageConsumer consumer = s.createConsumer(queue);

   Topic advisoryTopic = AdvisorySupport.getMessageConsumedAdvisoryTopic((ActiveMQDestination) queue);
   MessageConsumer advisoryConsumer = s.createConsumer(advisoryTopic);
   //start throwing messages at the consumer
   MessageProducer producer = s.createProducer(queue);

   BytesMessage m = s.createBytesMessage();
   m.writeBytes(new byte[1024]);
   producer.send(m);
   String id = m.getJMSMessageID();
   Message msg = consumer.receive(1000);
   assertNotNull(msg);

   msg = advisoryConsumer.receive(1000);
   assertNotNull(msg);

   ActiveMQMessage message = (ActiveMQMessage) msg;
   ActiveMQMessage payload = (ActiveMQMessage) message.getDataStructure();
   String originalId = payload.getJMSMessageID();
   assertEquals(originalId, id);
}
 
開發者ID:apache,項目名稱:activemq-artemis,代碼行數:26,代碼來源:AdvisoryTempDestinationTests.java


注:本文中的javax.jms.TemporaryQueue類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。