Package javax.jms

Examples of javax.jms.QueueConnection


    * A rollback will cause the first message to be re-delivered.
    * A commit will cause the second message to be available for delivery.
    */
   public void testRollbackCommit() throws Exception
   {
      QueueConnection conn = null;

      try
      {
         conn = cf.createQueueConnection();
         QueueSession sess = conn.createQueueSession(true, 0);
         JBossMessageProducer producer = (JBossMessageProducer)sess.createProducer(queue1);
         producer.enableOrderingGroup(null);

         QueueReceiver cons = sess.createReceiver(queue1);

         conn.start();

         Message m1 = sess.createTextMessage("testing1");
         Message m2 = sess.createTextMessage("testing2");
         producer.send(m1);
         producer.send(m2);

         sess.commit();

         TextMessage mr = (TextMessage)cons.receive(3000);
         assertNotNull(mr);
         assertEquals("testing1", mr.getText());

         sess.rollback();

         mr = (TextMessage)cons.receive(3000);
         assertNotNull(mr);
         assertEquals("testing1", mr.getText());

         // second message cannot be received
         // if the first message is not committed.
         mr = (TextMessage)cons.receive(3000);
         assertNull(mr);

         sess.commit();

         mr = (TextMessage)cons.receive(3000);
         assertNotNull(mr);
         assertEquals("testing2", mr.getText());

         sess.commit();

         checkEmpty(queue1);
      }
      finally
      {
         if (conn != null)
         {
            conn.close();
         }
      }
   }
View Full Code Here


    }
    LuceneWorkSerializer serializer = indexManager.getSerializer();
    byte[] data = serializer.toSerializedModel( filteredQueue );
    QueueSender sender;
    QueueSession session;
    QueueConnection connection;
    try {
      connection = processor.getJMSConnection();
      //TODO make transacted parameterized
      session = connection.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
      ObjectMessage message = session.createObjectMessage();
      message.setObject( data );
      message.setStringProperty( INDEX_NAME_JMS_PROPERTY, indexName );

      sender = session.createSender( processor.getJmsQueue() );
View Full Code Here

    }
    LuceneWorkSerializer serializer = indexManager.getSerializer();
    byte[] data = serializer.toSerializedModel( filteredQueue );
    QueueSender sender;
    QueueSession session;
    QueueConnection connection;
    try {
      connection = processor.getJMSConnection();
      //TODO make transacted parameterized
      session = connection.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
      ObjectMessage message = session.createObjectMessage();
      message.setObject( data );
      message.setStringProperty( Environment.INDEX_NAME_JMS_PROPERTY, indexName );

      sender = session.createSender( processor.getJmsQueue() );
View Full Code Here

    }
    if ( filteredQueue.size() == 0) return;
    LuceneWorkSerializer serializer = indexManager.getSerializer();
    byte[] data = serializer.toSerializedModel( filteredQueue );
    processor.prepareJMSTools();
    QueueConnection cnn = null;
    QueueSender sender;
    QueueSession session;
    try {
      cnn = processor.getJMSFactory().createQueueConnection();
      //TODO make transacted parameterized
      session = cnn.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
      ObjectMessage message = session.createObjectMessage();
      message.setObject( data );
      message.setStringProperty( INDEX_NAME_JMS_PROPERTY, indexName );

      sender = session.createSender( processor.getJmsQueue() );
      sender.send( message );

      session.close();
    }
    catch (JMSException e) {
      throw new SearchException( "Unable to send Search work to JMS queue: " + processor.getJmsQueueName(), e );
    }
    finally {
      try {
        if (cnn != null)
          cnn.close();
        }
      catch ( JMSException e ) {
        log.unableToCloseJmsConnection( processor.getJmsQueueName(), e );
      }
    }
View Full Code Here

    }
    if ( filteredQueue.size() == 0) return;
    LuceneWorkSerializer serializer = indexManager.getSerializer();
    byte[] data = serializer.toSerializedModel( filteredQueue );
    processor.prepareJMSTools();
    QueueConnection cnn = null;
    QueueSender sender;
    QueueSession session;
    try {
      cnn = processor.getJMSFactory().createQueueConnection();
      //TODO make transacted parameterized
      session = cnn.createQueueSession( false, QueueSession.AUTO_ACKNOWLEDGE );
      ObjectMessage message = session.createObjectMessage();
      message.setObject( data );
      message.setStringProperty( INDEX_NAME_JMS_PROPERTY, indexName );

      sender = session.createSender( processor.getJmsQueue() );
      sender.send( message );

      session.close();
    }
    catch (JMSException e) {
      throw new SearchException( "Unable to send Search work to JMS queue: " + processor.getJmsQueueName(), e );
    }
    finally {
      try {
        if (cnn != null)
          cnn.close();
        }
      catch ( JMSException e ) {
        log.unableToCloseJmsConnection( processor.getJmsQueueName(), e );
      }
    }
View Full Code Here

    */
   public void testQueueConnection1() throws Exception
   {
      QueueConnectionFactory qcf = (QueueConnectionFactory)cf;

      QueueConnection qc = qcf.createQueueConnection();

      qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      qc.close();
   }
View Full Code Here

    *
    * @throws Exception
    */
   public void testDurableSubscriberOnQueueConnection() throws Exception
   {
      QueueConnection queueConnection = ((QueueConnectionFactory)cf).createQueueConnection();

      try
      {
         queueConnection.createDurableConnectionConsumer((Topic)topic1, "subscriptionName", "",
            (ServerSessionPool) null, 1);
         fail("Should throw a javax.jms.IllegalStateException");
      }
      catch (javax.jms.IllegalStateException e)
      {
      }
      catch (java.lang.IllegalStateException e)
      {
         fail ("Should throw a javax.jms.IllegalStateException");
      }
      catch (JMSException e)
      {
         fail("Should throw a javax.jms.IllegalStateException, not a " + e);
      }
      finally
      {
         queueConnection.close();
      }
   }    
View Full Code Here

    */
   public void testQueueConnection1() throws Exception
   {
      QueueConnectionFactory qcf = (QueueConnectionFactory)cf;

      QueueConnection qc = qcf.createQueueConnection();

      qc.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

      qc.close();
   }
View Full Code Here

                    return connections.get(JMSType.QUEUE);
                }
                else
                {
                    QueueConnectionFactory ccf = (QueueConnectionFactory) createOrReturnConnectionFactory();
                    QueueConnection qc = ccf.createQueueConnection();
                    connections.put(JMSType.QUEUE, qc);

                    return qc;
                }
            }
View Full Code Here

    }
    throw new Exception("Notification not recoginsed.");
  }

  private String storeMessage(String messageType, String contents) {
    QueueConnection queueConnection = null;
    try {
      queueConnection = queueConnectionFactory.createQueueConnection();
      QueueSession queueSession = queueConnection.createQueueSession(
          false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = queueSession.createSender(queue);
      TextMessage message = queueSession.createTextMessage();
      message.setStringProperty("messageType", messageType);
      message.setText(contents);
      queueSender.send(message);

      return NotificationAcknowledgment.getAckString();

    } catch (JMSException e) {
      e.printStackTrace();
    } finally {
      if (queueConnection != null) {
        try {
          queueConnection.close();
        } catch (JMSException e) {
          e.printStackTrace();
        }
      }
    }
View Full Code Here

TOP

Related Classes of javax.jms.QueueConnection

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.