Package org.apache.qpid.client

Examples of org.apache.qpid.client.AMQSession


        _methodDispatcher = methodDispatcher;
    }

    public void setFlowControl(final int channelId, final boolean active)
    {
        final AMQSession session = getSession(channelId);
        session.setFlowControl(active);
    }
View Full Code Here


                                     + "&defaultTopicExchange='test.topic'"
                                     + "&temporaryQueueExchange='tmp.direct'"
                                     + "&temporaryTopicExchange='tmp.topic'");


            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");
View Full Code Here

    }

    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");
View Full Code Here

     * Tests the expired messages get actively deleted even on queues which have no consumers
     */
    public void testActiveTTL() throws URLSyntaxException, AMQException, JMSException, InterruptedException
    {
        Connection producerConnection = new AMQConnection(BROKER,"guest","guest","activeTTLtest","test");
        AMQSession producerSession = (AMQSession) producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue queue = producerSession.createTemporaryQueue();
        producerSession.declareAndBind((AMQDestination) queue);
        MessageProducer producer = producerSession.createProducer(queue);
        producer.setTimeToLive(1000L);

        // send Messages
        for(int i = 0; i < MSG_COUNT; i++)
        {
            producer.send(producerSession.createTextMessage("Message: "+i));
        }
        long failureTime = System.currentTimeMillis() + 2*SERVER_TTL_TIMEOUT;

        // check Queue depth for up to TIMEOUT seconds
        long messageCount;

        do
        {
            Thread.sleep(100);
            messageCount = producerSession.getQueueDepth((AMQDestination) queue);
        }
        while(messageCount > 0L && System.currentTimeMillis() < failureTime);

        assertEquals("Messages not automatically expired: ", 0L, messageCount);

        producer.close();
        producerSession.close();
        producerConnection.close();
    }
View Full Code Here

    }

    public void testStreamMessageEOF() throws Exception
    {
        Connection con = (AMQConnection) getConnection("guest", "guest");
        AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);

        AMQHeadersExchange queue =
            new AMQHeadersExchange(new AMQBindingURL(
                    ExchangeDefaults.HEADERS_EXCHANGE_CLASS + "://" + ExchangeDefaults.HEADERS_EXCHANGE_NAME
                    + "/test/queue1?" + BindingURL.OPTION_ROUTING_KEY + "='F0000=1'"));
        FieldTable ft = new FieldTable();
        ft.setString("F1000", "1");
        MessageConsumer consumer =
            consumerSession.createConsumer(queue, Integer.parseInt(ClientProperties.MAX_PREFETCH_DEFAULT), Integer.parseInt(ClientProperties.MAX_PREFETCH_DEFAULT), false, false, (String) null, ft);

        // force synch to ensure the consumer has resulted in a bound queue
        // ((AMQSession) consumerSession).declareExchangeSynch(ExchangeDefaults.HEADERS_EXCHANGE_NAME, ExchangeDefaults.HEADERS_EXCHANGE_CLASS);
        // This is the default now

        Connection con2 = (AMQConnection) getConnection("guest", "guest");

        AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);

        // Need to start the "producer" connection in order to receive bounced messages
        _logger.info("Starting producer connection");
        con2.start();

        MessageProducer mandatoryProducer = producerSession.createProducer(queue);

        // Third test - should be routed
        _logger.info("Sending isBound message");
        StreamMessage msg = producerSession.createStreamMessage();

        msg.setStringProperty("F1000", "1");

        msg.writeByte((byte) 42);
View Full Code Here

    }

    public void testModifyReceivedMessageExpandsBuffer() throws Exception
    {
        AMQConnection con = (AMQConnection) getConnection("guest", "guest");
        AMQSession consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        AMQQueue queue = new AMQQueue(con.getDefaultQueueExchangeName(), new AMQShortString("testQ"));
        MessageConsumer consumer = consumerSession.createConsumer(queue);
        consumer.setMessageListener(new MessageListener()
            {

                public void onMessage(Message message)
                {
                    StreamMessage sm = (StreamMessage) message;
                    try
                    {
                        sm.clearBody();
                        sm.writeString("dfgjshfslfjshflsjfdlsjfhdsljkfhdsljkfhsd");
                    }
                    catch (JMSException e)
                    {
                        _logger.error("Error when writing large string to received msg: " + e, e);
                        fail("Error when writing large string to received msg" + e);
                    }
                }
            });

        Connection con2 = (AMQConnection) getConnection("guest", "guest");
        AMQSession producerSession = (AMQSession) con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer mandatoryProducer = producerSession.createProducer(queue);
        con.start();
        StreamMessage sm = producerSession.createStreamMessage();
        sm.writeInt(42);
        mandatoryProducer.send(sm);
        Thread.sleep(2000);
        con.close();
        con2.close();
View Full Code Here

        try
        {
            InetAddress address = InetAddress.getLocalHost();
            AMQConnection con = new AMQConnection(host, port, username, password,
                                                  address.getHostName(), virtualPath);
            final AMQSession session = (AMQSession) con.createSession(false, Session.AUTO_ACKNOWLEDGE);

            final int expectedMessageCount = numExpectedMessages;

            MessageConsumer consumer = session.createConsumer(new AMQTopic(session.getDefaultTopicExchangeName(),
                                                                           new AMQShortString("large")),
                                                              100, true, false, null);

            consumer.setMessageListener(new MessageListener()
            {
View Full Code Here

    }

    public void testJMSDestination() 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);

        Connection con2 =  (AMQConnection) getConnection("guest", "guest");
        Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer producer = producerSession.createProducer(queue);
View Full Code Here

        this(connection, new AMQQueue(connection.getDefaultQueueExchangeName(), new AMQShortString(randomize("LatencyTest")), true), count, delay, length);
    }

    LatencyTest(AMQConnection connection, AMQDestination destination, int count, int delay, int length) throws Exception
    {
        AMQSession session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);

        data = new byte[length];
        for(int i = 0; i < data.length; i++)
        {
            data[i] = (byte) (i % 100);
        }

        //set up a consumer
        session.createConsumer(destination).setMessageListener(this);
        connection.start();

        //create a publisher
        MessageProducer producer = session.createProducer(destination, false, false, true);

        //publish at a low volume
        for(int i = 0; i < count; i++)
        {
            BytesMessage msg = session.createBytesMessage();
            msg.writeBytes(data);
            msg.setStringProperty("sent-at", Long.toString(System.nanoTime()));
            producer.send(msg);
            Thread.sleep(delay);
            if(++sent % 100 == 0)
            {
                System.out.println("Sent " + sent + " of " + count);
            }
        }

        waitUntilReceived(sent);

        session.close();
        connection.close();

        System.out.println("Latency (in nanoseconds): avg=" + (total/sent) + ", min=" + min + ", max=" + max
        + ", avg(discarding min and max)=" + ((total - min - max) / (sent - 2)));
    }
View Full Code Here

    }

    public void testUnparsableSelectors() throws Exception
    {
        AMQSession session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
        boolean caught = false;

        //Try Creating a Browser
        try
        {
            session.createBrowser(session.createQueue("Ping"), INVALID_SELECTOR);
        }
        catch (JMSException e)
        {
            _logger.debug("JMS:" + e.getClass().getSimpleName() + ":" + e.getMessage());
            if (!(e instanceof InvalidSelectorException))
            {
                fail("Wrong exception:" + e.getMessage());
            }
            caught = true;
        }
        assertTrue("No exception thrown!", caught);
        caught = false;

        //Try Creating a Consumer
        try
        {
            session.createConsumer(session.createQueue("Ping"), INVALID_SELECTOR);
        }
        catch (JMSException e)
        {
            _logger.debug("JMS:" + e.getClass().getSimpleName() + ":" + e.getMessage());
            if (!(e instanceof InvalidSelectorException))
            {
                fail("Wrong exception:" + e.getMessage());
            }
            caught = true;
        }
        assertTrue("No exception thrown!", caught);
        caught = false;

        //Try Creating a Receiever
        try
        {
            session.createReceiver(session.createQueue("Ping"), INVALID_SELECTOR);
        }
        catch (JMSException e)
        {
            _logger.debug("JMS:" + e.getClass().getSimpleName() + ":" + e.getMessage());
            if (!(e instanceof InvalidSelectorException))
            {
                fail("Wrong exception:" + e.getMessage());
            }
            caught = true;
        }
        assertTrue("No exception thrown!", caught);
        caught = false;

        try
        {
            session.createReceiver(session.createQueue("Ping"), BAD_MATHS_SELECTOR);
        }
        catch (JMSException e)
        {
            _logger.debug("JMS:" + e.getClass().getSimpleName() + ":" + e.getMessage());
            if (!(e instanceof InvalidSelectorException))
View Full Code Here

TOP

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

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.