javax.jms.QueueSession Java Examples

The following examples show how to use javax.jms.QueueSession. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JmsTypeHeaderInboundEndpointTestCase.java    From product-ei with Apache License 2.0 6 votes vote down vote up
/**
 * 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();
    }
}
 
Example #2
Source File: ActiveMQRASession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a queue receiver
 *
 * @param queue The queue
 * @return The queue receiver
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueReceiver createReceiver(final Queue queue) throws JMSException {
   lock();
   try {
      QueueSession session = getQueueSessionInternal();

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue);
      }

      QueueReceiver result = session.createReceiver(queue);
      result = new ActiveMQRAQueueReceiver(result, this);

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
      }

      addConsumer(result);

      return result;
   } finally {
      unlock();
   }
}
 
Example #3
Source File: JmsPoolQueueReceiverTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetQueue() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueReceiver receiver = session.createReceiver(queue);

    assertNotNull(receiver.getQueue());
    assertSame(queue, receiver.getQueue());

    receiver.close();

    try {
        receiver.getQueue();
        fail("Cannot read topic on closed receiver");
    } catch (IllegalStateException ise) {}
}
 
Example #4
Source File: JmsPoolQueueReceiverTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTopicSubscriber() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueReceiver receiver = (JmsPoolQueueReceiver) session.createReceiver(queue);

    assertNotNull(receiver.getQueueReceiver());
    assertTrue(receiver.getQueueReceiver() instanceof MockJMSQueueReceiver);

    receiver.close();

    try {
        receiver.getQueueReceiver();
        fail("Cannot read state on closed receiver");
    } catch (IllegalStateException ise) {}
}
 
Example #5
Source File: JmsPoolWrappedProducersTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
private void doTestCreateQueueSender(boolean useAnonymousProducers) throws JMSException {
    cf.setUseAnonymousProducers(useAnonymousProducers);

    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

    Queue queue1 = session.createTemporaryQueue();
    Queue queue2 = session.createTemporaryQueue();

    JmsPoolQueueSender sender1 = (JmsPoolQueueSender) session.createSender(queue1);
    JmsPoolQueueSender sender2 = (JmsPoolQueueSender) session.createSender(queue2);

    if (useAnonymousProducers) {
        assertSame(sender1.getMessageProducer(), sender2.getMessageProducer());
    } else {
        assertNotSame(sender1.getMessageProducer(), sender2.getMessageProducer());
    }

    connection.close();
}
 
Example #6
Source File: JmsPoolQueueSenderTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTopicSubscriber() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueSender sender = (JmsPoolQueueSender) session.createSender(queue);

    assertNotNull(sender.getQueueSender());
    assertTrue(sender.getQueueSender() instanceof MockJMSQueueSender);

    sender.close();

    try {
        sender.getQueueSender();
        fail("Cannot read state on closed sender");
    } catch (IllegalStateException ise) {}
}
 
Example #7
Source File: JmsQueueBrowserTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetQueue() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue);

    assertNotNull(browser.getQueue());

    browser.close();
    browser.close();

    try {
        browser.getQueue();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
Example #8
Source File: JmsQueueBrowserTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetQueueBrowser() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    JmsPoolQueueBrowser browser = (JmsPoolQueueBrowser) session.createBrowser(queue);

    assertNotNull(browser.getQueueBrowser());

    browser.close();

    try {
        browser.getQueueBrowser();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
Example #9
Source File: JmsQueueBrowserTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetEnumeration() throws JMSException {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createQueueConnection();
    QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
    Queue queue = session.createTemporaryQueue();
    QueueBrowser browser = session.createBrowser(queue);

    assertNotNull(browser.getEnumeration());

    browser.close();

    try {
        browser.getEnumeration();
        fail("Should not be able to use a closed browser");
    } catch (IllegalStateException ise) {
    }
}
 
Example #10
Source File: ActiveMQRASession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a queue sender
 *
 * @param queue The queue
 * @return The queue sender
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueSender createSender(final Queue queue) throws JMSException {
   lock();
   try {
      QueueSession session = getQueueSessionInternal();

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createSender " + session + " queue=" + queue);
      }

      QueueSender result = session.createSender(queue);
      result = new ActiveMQRAQueueSender(result, this);

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createdSender " + session + " sender=" + result);
      }

      addProducer(result);

      return result;
   } finally {
      unlock();
   }
}
 
Example #11
Source File: PurgeCommandTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
protected void setUp() throws Exception {
   super.setUp();

   context = createApplicationContext();

   createConnections();

   requestServerSession = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   theQueue = requestServerSession.createQueue(QUEUE_NAME);
   requestServerConsumer = requestServerSession.createConsumer(theQueue);
   requestServerProducer = requestServerSession.createProducer(null);

   QueueSession session = localConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   requestor = new QueueRequestor(session, theQueue);
}
 
Example #12
Source File: OutgoingConnectionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testConnectionCredentialsFail() throws Exception {
   resourceAdapter = newResourceAdapter();
   MyBootstrapContext ctx = new MyBootstrapContext();
   resourceAdapter.start(ctx);
   ActiveMQRAManagedConnectionFactory mcf = new ActiveMQRAManagedConnectionFactory();
   mcf.setResourceAdapter(resourceAdapter);
   ActiveMQRAConnectionFactory qraConnectionFactory = new ActiveMQRAConnectionFactoryImpl(mcf, qraConnectionManager);
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

   ManagedConnection mc = ((ActiveMQRASession) session).getManagedConnection();
   queueConnection.close();
   mc.destroy();

   try {
      queueConnection = qraConnectionFactory.createQueueConnection("testuser", "testwrongpassword");
      queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE).close();
      fail("should throw esxception");
   } catch (JMSException e) {
      //pass
   }
}
 
Example #13
Source File: CloseCmdTest.java    From ballerina-message-broker with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a AMQP connection with the number of channels specified, registered on top of it.
 *
 * @param numberOfChannels number of channels to be created using the connection
 * @param userName         admin user
 * @param password         admin password
 * @param hostName         localhost
 * @param port             the AMQP port for which the broker listens to
 * @return the created JMS connection
 * @throws NamingException if an error occurs while creating the context/connection factory using given properties.
 * @throws JMSException    if an error occurs while creating/starting the connection/session
 */
private Connection createConnection(int numberOfChannels, String userName, String password, String hostName,
                                    String port) throws NamingException, JMSException {

    InitialContext initialContext
            = ClientHelper.getInitialContextBuilder(userName, password, hostName, port).build();

    QueueConnectionFactory connectionFactory
            = (QueueConnectionFactory) initialContext.lookup(ClientHelper.CONNECTION_FACTORY);
    QueueConnection connection = connectionFactory.createQueueConnection();
    connection.start();
    for (int i = 0; i < numberOfChannels; i++) {
        QueueSession session = connection.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);

        /*
          For each channel, create a number of consumers that is equal to the channel number.
          e.g. if the channel count is 3, channel1 has 1 consumer, channel2 has 2 consumers and channel3 has 3
          consumers
        */
        for (int j = 0; j < i; j++) {
            Queue queue = session.createQueue("queue");
            session.createReceiver(queue);
        }
    }
    return connection;
}
 
Example #14
Source File: ManagedSession.java    From ats-framework with Apache License 2.0 6 votes vote down vote up
public static ManagedSession create( Session session ) {

        if ( (session instanceof XAQueueSession) && (session instanceof XATopicSession))
            return new ManagedXAQueueTopicSession(session);
        if (session instanceof XAQueueSession)
            return new ManagedXAQueueSession((XAQueueSession) session);
        if (session instanceof XATopicSession)
            return new ManagedXATopicSession((XATopicSession) session);
        if ( (session instanceof QueueSession) && (session instanceof TopicSession))
            return new ManagedQueueTopicSession(session);
        if (session instanceof QueueSession)
            return new ManagedQueueSession((QueueSession) session);
        if (session instanceof TopicSession)
            return new ManagedTopicSession((TopicSession) session);

        return new ManagedSession(session);
    }
 
Example #15
Source File: JMSFacade.java    From iaf with Apache License 2.0 6 votes vote down vote up
/**
 * Create a MessageConsumer. In this overloaded function the selector is taken into account.
 * This ensures that listeners (or other extensions of this class) do not influence how the selector
 * is used: when a correlationID should be in the filter the  <code>getMessageConsumerForCorrelationId</code>
 * should be used, other wise the <code>getMessageConsumer</code> function which has no attribute for
 * <code>selector</code>. When a MessageSelector is set, it will be used when no correlation id is required.
 * @param session the Session
 * @param destination the Destination
 * @param selector the MessageSelector
 * @return MessageConsumer
 */
public MessageConsumer getMessageConsumer(Session session, Destination destination, String selector) throws NamingException, JMSException {
	if (useTopicFunctions) {
		if (useJms102()) {
			return getTopicSubscriber((TopicSession)session, (Topic)destination, selector);
		} else {
			return getTopicSubscriber(session, (Topic)destination, selector);
		}
	} else {
		if (useJms102()) {
			return getQueueReceiver((QueueSession)session, (Queue)destination, selector);
		} else {
			return session.createConsumer(destination, selector);
		}
	}
}
 
Example #16
Source File: AbstractPersistentStatTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void consumeDurableTestMessages(Connection connection, String sub, int size, String topicName,
      AtomicLong publishedMessageSize) throws Exception {


   Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
   Topic topic = session.createTopic(topicName);

   try {
      TopicSubscriber consumer = session.createDurableSubscriber(topic, sub);
      for (int i = 0; i < size; i++) {
         ActiveMQMessage message = (ActiveMQMessage) consumer.receive();
         if (publishedMessageSize != null) {
            publishedMessageSize.addAndGet(-message.getCoreMessage().getEncodeSize());
         }
      }

   } finally {
      session.close();
   }

}
 
Example #17
Source File: QueueSenderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void anonymousSenderSendToUnknownQueue() throws Exception
{
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().setSyncPublish(true).build());

    try
    {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");

        try
        {
            QueueSender sender = session.createSender(null);
            sender.send(invalidDestination, session.createMessage());
            fail("Exception not thrown");
        }
        catch (InvalidDestinationException e)
        {
            //PASS
        }
    }
    finally
    {
        connection.close();
    }
}
 
Example #18
Source File: PullingIfsaProviderListener.java    From iaf with Apache License 2.0 6 votes vote down vote up
@Override
public Map openThread() throws ListenerException {
	Map threadContext = new HashMap();

	try {
		if (!isSessionsArePooled()) {
			QueueSession session = createSession();
			threadContext.put(THREAD_CONTEXT_SESSION_KEY, session);

			QueueReceiver receiver;
			receiver = getServiceReceiver(session);
			threadContext.put(THREAD_CONTEXT_RECEIVER_KEY, receiver);
		}
		return threadContext;
	} catch (IfsaException e) {
		throw new ListenerException(getLogPrefix()+"exception in openThread()", e);
	}
}
 
Example #19
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotCreateDurableSubscriber() throws Exception
{
    Topic topic = createTopic(getTestName());
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

        try
        {
            queueSession.createDurableSubscriber(topic, "abc");
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #20
Source File: QueueSessionTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testQueueSessionCannotCreateTopics() throws Exception
{
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        QueueSession queueSession = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        try
        {
            queueSession.createTopic("abc");
            fail("expected exception did not occur");
        }
        catch (javax.jms.IllegalStateException s)
        {
            // PASS
        }
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example #21
Source File: AbstractPersistentStatTestSupport.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
protected void consumeTestQueueMessages(String queueName, int num) throws Exception {

      // Start the connection
      Connection connection = cf.createConnection();
      connection.setClientID("clientId2" + queueName);
      connection.start();
      Session session = connection.createSession(false, QueueSession.AUTO_ACKNOWLEDGE);
      Queue queue = session.createQueue(queueName);
      MessageConsumer consumer;
      try {
         consumer = session.createConsumer(queue);
         for (int i = 0; i < num; i++) {
            consumer.receive();
         }
         consumer.close();
      } finally {
         // consumer.close();
         connection.close();
      }

   }
 
Example #22
Source File: ActiveMQRASession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Create a queue receiver
 *
 * @param queue           The queue
 * @param messageSelector
 * @return The queue receiver
 * @throws JMSException Thrown if an error occurs
 */
@Override
public QueueReceiver createReceiver(final Queue queue, final String messageSelector) throws JMSException {
   lock();
   try {
      QueueSession session = getQueueSessionInternal();

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createReceiver " + session + " queue=" + queue + " selector=" + messageSelector);
      }

      QueueReceiver result = session.createReceiver(queue, messageSelector);
      result = new ActiveMQRAQueueReceiver(result, this);

      if (ActiveMQRALogger.LOGGER.isTraceEnabled()) {
         ActiveMQRALogger.LOGGER.trace("createdReceiver " + session + " receiver=" + result);
      }

      addConsumer(result);

      return result;
   } finally {
      unlock();
   }
}
 
Example #23
Source File: TibcoMessagingSource.java    From iaf with Apache License 2.0 6 votes vote down vote up
public Destination lookupDestination(String destinationName) throws JmsException {
	Session session=null;		
	try {
		session = createSession(false,Session.AUTO_ACKNOWLEDGE);
		log.debug("Session class ["+session.getClass().getName()+"]");
		Destination destination;

		/* create the destination */
		if (session instanceof TopicSession) {
			destination = ((TopicSession)session).createTopic(destinationName);
		} else {
			destination = ((QueueSession)session).createQueue(destinationName);
		}

		return destination;
	} catch (Exception e) {
		throw new JmsException("cannot create destination", e);
	} finally {
		releaseSession(session);
	}
}
 
Example #24
Source File: JmsInvokerTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Before
public void setUpMocks() throws Exception {
	mockConnectionFactory = mock(QueueConnectionFactory.class);
	mockConnection = mock(QueueConnection.class);
	mockSession = mock(QueueSession.class);
	mockQueue = mock(Queue.class);

	given(mockConnectionFactory.createConnection()).willReturn(mockConnection);
	given(mockConnection.createSession(false, Session.AUTO_ACKNOWLEDGE)).willReturn(mockSession);
}
 
Example #25
Source File: TransactionAwareConnectionFactoryProxy.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private Session getCloseSuppressingSessionProxy(Session target) {
	List<Class<?>> classes = new ArrayList<>(3);
	classes.add(SessionProxy.class);
	if (target instanceof QueueSession) {
		classes.add(QueueSession.class);
	}
	if (target instanceof TopicSession) {
		classes.add(TopicSession.class);
	}
	return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(),
			ClassUtils.toClassArray(classes), new CloseSuppressingSessionInvocationHandler(target));
}
 
Example #26
Source File: TracingSession.java    From brave with Apache License 2.0 5 votes vote down vote up
TracingSession(Session delegate, JmsTracing jmsTracing) {
  this.delegate = delegate;
  this.jmsTracing = jmsTracing;
  int types = 0;
  if (delegate instanceof QueueSession) types |= TYPE_QUEUE;
  if (delegate instanceof TopicSession) types |= TYPE_TOPIC;
  if (delegate instanceof XASession) types |= TYPE_XA;
  if (delegate instanceof XAQueueSession) types |= TYPE_XA_QUEUE;
  if (delegate instanceof XATopicSession) types |= TYPE_XA_TOPIC;
  this.types = types;
}
 
Example #27
Source File: CachingConnectionFactory.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Wrap the given Session with a proxy that delegates every method call to it
 * but adapts close calls. This is useful for allowing application code to
 * handle a special framework Session just like an ordinary Session.
 * @param target the original Session to wrap
 * @param sessionList the List of cached Sessions that the given Session belongs to
 * @return the wrapped Session
 */
protected Session getCachedSessionProxy(Session target, LinkedList<Session> sessionList) {
	List<Class<?>> classes = new ArrayList<>(3);
	classes.add(SessionProxy.class);
	if (target instanceof QueueSession) {
		classes.add(QueueSession.class);
	}
	if (target instanceof TopicSession) {
		classes.add(TopicSession.class);
	}
	return (Session) Proxy.newProxyInstance(SessionProxy.class.getClassLoader(),
			ClassUtils.toClassArray(classes), new CachedSessionInvocationHandler(target, sessionList));
}
 
Example #28
Source File: JMSWrapper.java    From core with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Dynamically creates a topic. This goes against the normal idea
    * that JMS queues and topics should managed administratively, using
    * management tools. But for some applications this would be too 
    * burdensome. The user would have to additionally know about the
    * administration tools as well. Given that might be creating quite
    * a few AVL feeds, each one being a separate topic, this could be
    * a real nuisance.
    * 
 * @param topicName
 * @return true if topic created successfully
 * @throws JMSException
 */
private boolean createTopic(String topicName) throws JMSException {
	QueueConnectionFactory queueConnectionFactory = 
			(QueueConnectionFactory) connectionFactory;
	QueueConnection connection = queueConnectionFactory.createQueueConnection();

	Queue managementQueue = HornetQJMSClient.createQueue("hornetq.management");
	QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
	connection.start();
	Message message = session.createMessage();
	JMSManagementHelper.putOperationInvocation(message, 
			"jms.server", 
			"createTopic", // management command
			topicName,     // Name in hornetq
			topicName);    // JNDI name. This peculiar seemingly undocumented 
						   // parameter is needed so that can use JNDI to access 
	                       // the dynamically created topic. Found info on doing 
	                       // this at https://community.jboss.org/thread/165355 .
	QueueRequestor requestor = new QueueRequestor(session, managementQueue);

	// Determine if was successful
	Message reply = requestor.request(message);
	boolean topicCreated = JMSManagementHelper.hasOperationSucceeded(reply);
	
	if (topicCreated)
		logger.info("Dynamically created topic \"" + topicName + "\"");
	else
		logger.error("Failed to dynamically created topic \"" + topicName + "\"");
	
	// Return whether successful
	return topicCreated;
}
 
Example #29
Source File: MessageListenerAdapterTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testWithResponsiveMessageDelegateNoDefaultDestination_SendsReturnTextMessageWhenSessionSupplied_AndSendingThrowsJMSException() throws Exception {
	Queue destination = mock(Queue.class);

	final TextMessage sentTextMessage = mock(TextMessage.class);
	// correlation ID is queried when response is being created...
	given(sentTextMessage.getJMSCorrelationID()).willReturn(CORRELATION_ID);
	// Reply-To is queried when response is being created...
	given(sentTextMessage.getJMSReplyTo()).willReturn(destination);

	TextMessage responseTextMessage = mock(TextMessage.class);
	MessageProducer messageProducer = mock(MessageProducer.class);
	willThrow(new JMSException("Doe!")).given(messageProducer).send(responseTextMessage);

	final QueueSession session = mock(QueueSession.class);
	given(session.createTextMessage(RESPONSE_TEXT)).willReturn(responseTextMessage);
	given(session.createProducer(destination)).willReturn(messageProducer);

	ResponsiveMessageDelegate delegate = mock(ResponsiveMessageDelegate.class);
	given(delegate.handleMessage(sentTextMessage)).willReturn(RESPONSE_TEXT);

	final MessageListenerAdapter adapter = new MessageListenerAdapter(delegate) {
		@Override
		protected Object extractMessage(Message message) {
			return message;
		}
	};
	try {
		adapter.onMessage(sentTextMessage, session);
		fail("expected CouldNotSendReplyException with JMSException");
	}
	catch (ReplyFailureException ex) {
		assertEquals(JMSException.class, ex.getCause().getClass());
	}

	verify(responseTextMessage).setJMSCorrelationID(CORRELATION_ID);
	verify(messageProducer).close();
	verify(delegate).handleMessage(sentTextMessage);
}
 
Example #30
Source File: DynamicDestinationResolverTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void resolveWithPointToPointQueueSession() throws Exception {
	Queue expectedDestination = new StubQueue();
	Session session = mock(QueueSession.class);
	given(session.createQueue(DESTINATION_NAME)).willReturn(expectedDestination);
	testResolveDestination(session, expectedDestination, false);
}