Java Code Examples for javax.jms.QueueConnection#start()

The following examples show how to use javax.jms.QueueConnection#start() . 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: SingleConnectionFactoryTests.java    From java-technology-stack with MIT License 6 votes vote down vote up
@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);
}
 
Example 2
Source File: ConnectionsRestApiTest.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 3
Source File: SingleConnectionFactoryTests.java    From spring4-understanding with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example 4
Source File: QueueReceiverTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void createReceiver() throws Exception
{
    Queue queue = createQueue(getTestName());
    QueueConnection queueConnection = getQueueConnection();
    try
    {
        queueConnection.start();
        Utils.sendMessages(queueConnection, queue, 3);

        QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        QueueReceiver receiver = session.createReceiver(queue, String.format("%s=2", INDEX));
        assertEquals("Queue names should match from QueueReceiver", queue.getQueueName(), receiver.getQueue().getQueueName());

        Message received = receiver.receive(getReceiveTimeout());
        assertNotNull("Message is not received", received);
        assertEquals("Unexpected message is received", 2, received.getIntProperty(INDEX));
    }
    finally
    {
        queueConnection.close();
    }
}
 
Example 5
Source File: SingleConnectionFactoryTests.java    From spring-analysis-note with MIT License 6 votes vote down vote up
@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);
}
 
Example 6
Source File: QueueReceiverTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * 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);
   }
}
 
Example 7
Source File: CreateTemporaryQueueBeforeStartTest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void testTryToReproduceNullPointerBug() throws Exception {
   String url = connectionUri;
   ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(url);
   QueueConnection queueConnection = factory.createQueueConnection();
   this.connection = queueConnection;
   QueueSession session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
   session.createSender(null); // Unidentified
   Queue receiverQueue = session.createTemporaryQueue();
   session.createReceiver(receiverQueue);
   queueConnection.start();
}
 
Example 8
Source File: OutgoingConnectionNoJTATest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleMessageSendAndReceive() throws Exception {
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
}
 
Example 9
Source File: OutgoingConnectionJTATest.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Test
public void testSimpleMessageSendAndReceive() throws Exception {
   QueueConnection queueConnection = qraConnectionFactory.createQueueConnection();
   Session s = queueConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
   Queue q = ActiveMQJMSClient.createQueue(MDBQUEUE);
   MessageProducer mp = s.createProducer(q);
   MessageConsumer consumer = s.createConsumer(q);
   Message message = s.createTextMessage("test");
   mp.send(message);
   queueConnection.start();
   TextMessage textMessage = (TextMessage) consumer.receive(1000);
   assertNotNull(textMessage);
   assertEquals(textMessage.getText(), "test");
}
 
Example 10
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 11
Source File: SingleConnectionFactoryTests.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
Example 12
Source File: IbmMqManager.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
IbmMqManager(String host, int port, String username, String password, String channel) throws JMSException {
    MQQueueConnectionFactory connectionFactory = new MQQueueConnectionFactory();
    connectionFactory.setHostName(host);
    connectionFactory.setPort(port);
    connectionFactory.setTransportType(WMQConstants.WMQ_CM_CLIENT);

    if(channel != null && !channel.isEmpty()) {
        connectionFactory.setChannel(channel);
    }

    connection = (QueueConnection) connectionFactory.createConnection(username, password);
    connection.start();
}
 
Example 13
Source File: SingleConnectionFactoryTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
Example 14
Source File: SingleConnectionFactoryTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
@Test
public void testCachingConnectionFactoryWithQueueConnectionFactoryAndJms102Usage() throws JMSException {
	QueueConnectionFactory cf = mock(QueueConnectionFactory.class);
	QueueConnection con = mock(QueueConnection.class);
	QueueSession txSession = mock(QueueSession.class);
	QueueSession nonTxSession = mock(QueueSession.class);

	given(cf.createQueueConnection()).willReturn(con);
	given(con.createQueueSession(true, Session.AUTO_ACKNOWLEDGE)).willReturn(txSession);
	given(txSession.getTransacted()).willReturn(true);
	given(con.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE)).willReturn(nonTxSession);

	CachingConnectionFactory scf = new CachingConnectionFactory(cf);
	scf.setReconnectOnException(false);
	Connection con1 = scf.createQueueConnection();
	Session session1 = con1.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session1.rollback();
	session1.close();
	session1 = con1.createSession(false, Session.CLIENT_ACKNOWLEDGE);
	session1.close();
	con1.start();
	QueueConnection con2 = scf.createQueueConnection();
	Session session2 = con2.createQueueSession(false, Session.CLIENT_ACKNOWLEDGE);
	session2.close();
	session2 = con2.createSession(true, Session.AUTO_ACKNOWLEDGE);
	session2.getTransacted();
	session2.close();  // should lead to rollback
	con2.start();
	con1.close();
	con2.close();
	scf.destroy();  // should trigger actual close

	verify(txSession).rollback();
	verify(txSession).close();
	verify(nonTxSession).close();
	verify(con).start();
	verify(con).stop();
	verify(con).close();
}
 
Example 15
Source File: ConsumersRestApiTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testNonExistingConsumer(String username, String password,
                                    String hostname, String port) throws Exception {

    String queueName = "testNonExistingConsumer";

    // 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 receiver1 = queueSession.createReceiver(queue);

    HttpGet getAllConsumers = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");
    ClientHelper.setAuthHeader(getAllConsumers, username, password);

    CloseableHttpResponse response = client.execute(getAllConsumers);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK,
                        "Incorrect status code");
    String consumerArray = EntityUtils.toString(response.getEntity());
    ConsumerMetadata[] consumers = objectMapper.readValue(consumerArray, ConsumerMetadata[].class);

    Assert.assertEquals(consumers.length, 1, "There should be a single consumer");
    int id = consumers[0].getId();
    receiver1.close();

    HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers/" + String.valueOf(id));
    ClientHelper.setAuthHeader(getConsumer, username, password);

    response = client.execute(getConsumer);
    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_NOT_FOUND);

    String errorMessage = EntityUtils.toString(response.getEntity());
    Error error = objectMapper.readValue(errorMessage, Error.class);

    Assert.assertFalse(error.getMessage().isEmpty(), "Error message should be non empty.");
    queueSession.close();
    connection.close();
}
 
Example 16
Source File: ConsumersRestApiTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@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");
    ClientHelper.setAuthHeader(getAllConsumers, username, password);

    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();
    validateTransportPropertyExistence(consumers[0]);
    HttpGet getConsumer = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/"
                                              + queueName + "/consumers/" + id);
    ClientHelper.setAuthHeader(getConsumer, username, password);

    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();
}
 
Example 17
Source File: ConsumersRestApiTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testRetrieveConsumerList(String username, String password,
                                     String hostname, String port) throws Exception {
    String queueName = "testSpecificQueueRetrieval";


    // 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 receiver1 = queueSession.createReceiver(queue);
    QueueReceiver receiver2 = queueSession.createReceiver(queue);

    HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH
                                          + "/" + queueName + "/consumers");
    ClientHelper.setAuthHeader(httpGet, username, password);

    CloseableHttpResponse response = client.execute(httpGet);
    String body = EntityUtils.toString(response.getEntity());

    ConsumerMetadata[] consumers = objectMapper.readValue(body, ConsumerMetadata[].class);
    for (ConsumerMetadata consumerMetadata : consumers) {
        validateTransportPropertyExistence(consumerMetadata);
    }

    Assert.assertEquals(consumers.length, 2, "Number of consumers returned is incorrect.");

    receiver1.close();
    receiver2.close();
    queueSession.close();
    connection.close();
}
 
Example 18
Source File: QueuesRestApiTest.java    From ballerina-message-broker with Apache License 2.0 4 votes vote down vote up
@Parameters({"admin-username", "admin-password", "broker-hostname", "broker-port"})
@Test
public void testSpecificQueueRetrieval(String username, String password, String hostname, String port)
        throws JMSException, NamingException, IOException {

    String queueName = "testSpecificQueueRetrieval";

    // 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);

    // Test queue retrieval through REST API
    HttpGet httpGet = new HttpGet(apiBasePath + QueuesApiDelegate.QUEUES_API_PATH + "/" + queueName);
    ClientHelper.setAuthHeader(httpGet, username, password);
    CloseableHttpResponse response = client.execute(httpGet);

    Assert.assertEquals(response.getStatusLine().getStatusCode(), HttpStatus.SC_OK, "Incorrect status code.");

    String body = EntityUtils.toString(response.getEntity());
    QueueMetadata queueMetadata = objectMapper.readValue(body, QueueMetadata.class);

    Assert.assertEquals(queueMetadata.getName(), queueName, "Incorrect queue name.");
    Assert.assertEquals(queueMetadata.getConsumerCount().intValue(), 1, "JMS consumer should be present.");
    Assert.assertTrue(queueMetadata.isDurable());
    Assert.assertEquals(queueMetadata.getSize().intValue(), 0, "Queue should be empty.");
    Assert.assertFalse(queueMetadata.isAutoDelete());

    receiver.close();
    queueSession.close();
    connection.close();
}
 
Example 19
Source File: AzureServiceBusEventsListnerTest.java    From oneops with Apache License 2.0 3 votes vote down vote up
private void sendMessageToServer() throws JMSException, IOException {

		QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
		queueConn.start();

		QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);

		Destination destination = queueSession.createQueue(jmsQueue);

		MessageProducer queueSender = queueSession.createProducer(destination);
		queueSender.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
		Message message = queueSession.createTextMessage(createMessage());
		queueSender.send(message);

	}
 
Example 20
Source File: AzureServiceBusEventsListnerTest.java    From oneops with Apache License 2.0 3 votes vote down vote up
public void startListner() throws JMSException {

		QueueConnection queueConn = (QueueConnection) connectionFactory.createConnection();
		QueueSession queueSession = queueConn.createQueueSession(false, Session.DUPS_OK_ACKNOWLEDGE);

		Destination destination = queueSession.createQueue("TESTQUEUE");

		MessageConsumer consumer = queueSession.createConsumer(destination);

		azureServiceBusEventsListner.setAzureEventsHandler(azureEventsHandler);
		consumer.setMessageListener(azureServiceBusEventsListner);
		queueConn.start();

	}