Package org.apache.qpid.client

Examples of org.apache.qpid.client.AMQConnection


    }

    public void testRecoverInAutoAckListener() throws Exception
    {
        AMQConnection con = (AMQConnection) getConnection("guest", "guest");

        final Session consumerSession = con.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue =
                new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q3"), new AMQShortString("Q3"),
                             false, true);
        MessageConsumer consumer = consumerSession.createConsumer(queue);
        MessageProducer producer = consumerSession.createProducer(queue);
        producer.send(consumerSession.createTextMessage("hello"));

        final Object lock = new Object();

        consumer.setMessageListener(new MessageListener()
        {

            public void onMessage(Message message)
            {
                try
                {
                    count.incrementAndGet();
                    if (count.get() == 1)
                    {
                        if (message.getJMSRedelivered())
                        {
                            setError(new Exception("Message marked as redelivered on what should be first delivery attempt"));
                        }

                        consumerSession.recover();
                    }
                    else if (count.get() == 2)
                    {
                        if (!message.getJMSRedelivered())
                        {
                            setError(
                                    new Exception("Message not marked as redelivered on what should be second delivery attempt"));
                        }
                    }
                    else
                    {
                        System.err.println(message);
                        fail("Message delivered too many times!: " + count);
                    }
                }
                catch (JMSException e)
                {
                    _logger.error("Error recovering session: " + e, e);
                    setError(e);
                }

                synchronized (lock)
                {
                    lock.notify();
                }
            }
        });

        con.start();

        long waitTime = 30000L;
        long waitUntilTime = System.currentTimeMillis() + waitTime;

        synchronized (lock)
View Full Code Here


           Process startScript = pb.start();
           startScript.waitFor();
           startScript.destroy();
          
           Connection con =
               new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:" + port + "'");
           final AtomicBoolean lock = new AtomicBoolean(false);
          
           String cmd = "/usr/bin/pgrep -f " + port;
           process = Runtime.getRuntime().exec("/bin/bash");
           LineNumberReader reader = new LineNumberReader(new InputStreamReader(process.getInputStream()));
           PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(process.getOutputStream())), true);
           out.println(cmd);
           pid = reader.readLine();
           try
           {
               Integer.parseInt(pid);
           }
           catch (NumberFormatException e)
           {
               // Error! try to read further to gather the error msg.
               String line;
               _logger.debug(pid);
               while ((line = reader.readLine()) != null )
               {
                   _logger.debug(line);
               }
               throw new Exception( "Unable to get the brokers pid " + pid);
           }
           _logger.debug("pid : " + pid);
          
           con.setExceptionListener(new ExceptionListener(){
              
               public void onException(JMSException e)
               {
                   synchronized(lock) {
                       lock.set(true);
View Full Code Here

    public void test() throws Exception
    {
        _failedOver = new CountDownLatch(1);

        _connection = new AMQConnection("amqp://guest:guest@client/test?brokerlist='localhost?retries='20'&connectdelay='2000''");

        _session = _connection.createSession(true, Session.SESSION_TRANSACTED);
        _queue = _session.createQueue("QAtest");
        _consumer = _session.createConsumer(_queue);
        _connection.setConnectionListener(this);
View Full Code Here

        super.tearDown();
    }

    public void testJMSProperties() throws Exception
    {
        AMQConnection con = (AMQConnection) getConnection("guest", "guest");
        AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue =
            new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("someQ"), new AMQShortString("someQ"), false,
                true);
        MessageConsumer consumer = consumerSession.createConsumer(queue);

        AMQConnection con2 = (AMQConnection) getConnection("guest", "guest");
        Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer producer = producerSession.createProducer(queue);
        Destination JMS_REPLY_TO = new AMQQueue(con2, "my.replyto");
        // create a test message to send
        ObjectMessage sentMsg = new NonQpidObjectMessage(producerSession);
        sentMsg.setJMSCorrelationID(JMS_CORR_ID);
        sentMsg.setJMSDeliveryMode(JMS_DELIV_MODE);
        sentMsg.setJMSType(JMS_TYPE);
        sentMsg.setJMSReplyTo(JMS_REPLY_TO);

        String JMSXGroupID_VALUE = "group";
        sentMsg.setStringProperty("JMSXGroupID", JMSXGroupID_VALUE);
       
        int JMSXGroupSeq_VALUE = 1;
        sentMsg.setIntProperty("JMSXGroupSeq", JMSXGroupSeq_VALUE);

        try
        {
            sentMsg.setObjectProperty(NULL_OBJECT_PROPERTY, null);
            fail("Null Object Property value set");
        }
        catch (MessageFormatException mfe)
        {
            // Check the error message
            assertEquals("Incorrect error message", AMQPInvalidClassException.INVALID_OBJECT_MSG + "null", mfe.getMessage());
        }

        try
        {
            sentMsg.setObjectProperty(INVALID_OBJECT_PROPERTY, new Exception());
            fail("Non primitive Object Property value set");
        }
        catch (MessageFormatException mfe)
        {
            // Check the error message
            assertEquals("Incorrect error message: " + mfe.getMessage(), AMQPInvalidClassException.INVALID_OBJECT_MSG + Exception.class, mfe.getMessage());
        }

        // send it
        producer.send(sentMsg);

        con2.close();

        con.start();

        // get message and check JMS properties
        ObjectMessage rm = (ObjectMessage) consumer.receive(2000);
View Full Code Here

        assertEquals("Incorrect vhost delivery total", 0, vhost.getTotalMessagesDelivered());
        assertEquals("Incorrect vhost delivery data", 0, vhost.getTotalDataDelivered());
        assertEquals("Incorrect vhost receipt total", 5, vhost.getTotalMessagesReceived());
        assertEquals("Incorrect vhost receipt data", 1000, vhost.getTotalDataReceived());
       
        Connection test = new AMQConnection(_brokerUrl, USER, USER, "clientid", "test");
        test.start();
        receiveUsing(test, 5);
       
        for (ManagedConnection mc : _jmxUtils.getManagedConnections("test"))
        {
            if (addresses.contains(mc.getRemoteAddress()))
            {
                assertEquals("Incorrect connection delivery total", 0,  mc.getTotalMessagesDelivered());
                assertEquals("Incorrect connection delivery data", 0, mc.getTotalDataDelivered());
                assertEquals("Incorrect connection receipt total", 5,  mc.getTotalMessagesReceived());
                assertEquals("Incorrect connection receipt data", 1000, mc.getTotalDataReceived());
            }
            else
            {
                assertEquals("Incorrect connection delivery total", 5,  mc.getTotalMessagesDelivered());
                assertEquals("Incorrect connection delivery data", 1000, mc.getTotalDataDelivered());
                assertEquals("Incorrect connection receipt total", 0,  mc.getTotalMessagesReceived());
                assertEquals("Incorrect connection receipt data", 0, mc.getTotalDataReceived());
            }
        }
        assertEquals("Incorrect vhost delivery total", 5, vhost.getTotalMessagesDelivered());
        assertEquals("Incorrect vhost delivery data", 1000, vhost.getTotalDataDelivered());
        assertEquals("Incorrect vhost receipt total", 5, vhost.getTotalMessagesReceived());
        assertEquals("Incorrect vhost receipt data", 1000, vhost.getTotalDataReceived());
       
        test.close();
    }
View Full Code Here

    /**
     * Test message totals when a connection is closed.
     */
    public void testMessageTotalsWithClosedConnections() throws Exception
    {
        Connection temp = new AMQConnection(_brokerUrl, USER, USER, "clientid", "test");
        temp.start();
       
        sendUsing(_test, 10, 100);
        sendUsing(temp, 10, 100);
        sendUsing(_test, 10, 100);
        Thread.sleep(2000);
       
        temp.close();
       
        ManagedBroker test = _jmxUtils.getManagedBroker("test");

        if (!isBroker010())
        {
View Full Code Here

            AMQConnectionURL url = new AMQConnectionURL(connectionString);

            try
            {
                //Start the connection so it will use the retries
                connection = new AMQConnection(url, null);

                connection.setExceptionListener(this);

                session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
                consumer = session.createConsumer(session.createQueue(this.getName()));
View Full Code Here

    String _broker_NotRunning = "vm://:2";
    String _broker_BadDNS = "tcp://hg3sgaaw4lgihjs";

    public void testSimpleConnection() throws Exception
    {
        AMQConnection conn = null;
        try
        {
            conn = new AMQConnection(getBroker().toString(), "guest", "guest", "fred", "test");
        }
        catch (Exception e)
        {
            fail("Connection to " + getBroker() + " should succeed. Reason: " + e);
        }
        finally
        {
            if(conn != null)
            {
                conn.close();
            }
        }
    }
View Full Code Here

        }
    }

    public void testDefaultExchanges() throws Exception
    {
        AMQConnection conn = null;
        try
        {
            BrokerDetails broker = getBroker();
            broker.setProperty(BrokerDetails.OPTIONS_RETRY, "1");
            ConnectionURL url = new AMQConnectionURL("amqp://guest:guest@clientid/test?brokerlist='"
                                     + broker
                                     + "'&defaultQueueExchange='test.direct'"
                                     + "&defaultTopicExchange='test.topic'"
                                     + "&temporaryQueueExchange='tmp.direct'"
                                     + "&temporaryTopicExchange='tmp.topic'");

            System.err.println(url.toString());
            conn = new AMQConnection(url, null);


            AMQSession sess = (AMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
           
            sess.declareExchange(new AMQShortString("test.direct"),
                    ExchangeDefaults.DIRECT_EXCHANGE_CLASS, false);

            sess.declareExchange(new AMQShortString("tmp.direct"),
                    ExchangeDefaults.DIRECT_EXCHANGE_CLASS, false);

            sess.declareExchange(new AMQShortString("tmp.topic"),
                    ExchangeDefaults.TOPIC_EXCHANGE_CLASS, false);

            sess.declareExchange(new AMQShortString("test.topic"),
                    ExchangeDefaults.TOPIC_EXCHANGE_CLASS, false);

            QueueSession queueSession = conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);

            AMQQueue queue = (AMQQueue) queueSession.createQueue("MyQueue");

            assertEquals(queue.getExchangeName().toString(), "test.direct");

            AMQQueue tempQueue = (AMQQueue) queueSession.createTemporaryQueue();

            assertEquals(tempQueue.getExchangeName().toString(), "tmp.direct");

            queueSession.close();

            TopicSession topicSession = conn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
           
            AMQTopic topic = (AMQTopic) topicSession.createTopic("silly.topic");

            assertEquals(topic.getExchangeName().toString(), "test.topic");

            AMQTopic tempTopic = (AMQTopic) topicSession.createTemporaryTopic();

            assertEquals(tempTopic.getExchangeName().toString(), "tmp.topic");

            topicSession.close();

        }
        catch (Exception e)
        {
            fail("Connection to " + getBroker() + " should succeed. Reason: " + e);
        }
        finally
        {
            conn.close();
        }
    }
View Full Code Here

        }
    }

    public void testPasswordFailureConnection() throws Exception
    {
        AMQConnection conn = null;
        try
        {
            BrokerDetails broker = getBroker();
            broker.setProperty(BrokerDetails.OPTIONS_RETRY, "0");
            conn = new AMQConnection("amqp://guest:rubbishpassword@clientid/test?brokerlist='" + broker + "'");
            fail("Connection should not be established password is wrong.");
        }
        catch (AMQConnectionFailureException amqe)
        {
            assertNotNull("No cause set:" + amqe.getMessage(), amqe.getCause());
            assertTrue("Exception was wrong type", amqe.getCause() instanceof AMQException);
        }
        finally
        {
            if (conn != null)
            {
                conn.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.apache.qpid.client.AMQConnection

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.