Package org.apache.qpid.jms

Examples of org.apache.qpid.jms.Session


    {
        try
        {
            AMQConnection con = (AMQConnection) getConnection("guest", "guest");

            Session consumerSession = con.createSession(true, Session.SESSION_TRANSACTED);
            AMQQueue queue3 = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q3"), false);
            MessageConsumer consumer = consumerSession.createConsumer(queue3);

            AMQConnection con2 = (AMQConnection) getConnection("guest", "guest");
            Session producerSession = con2.createSession(true, Session.SESSION_TRANSACTED);
            MessageProducer producer = producerSession.createProducer(queue3);

            _logger.info("Sending four messages");
            producer.send(producerSession.createTextMessage("msg1"));
            producer.send(producerSession.createTextMessage("msg2"));
            producer.send(producerSession.createTextMessage("msg3"));
            producer.send(producerSession.createTextMessage("msg4"));

            producerSession.commit();

            _logger.info("Starting connection");
            con.start();
            TextMessage tm = (TextMessage) consumer.receive();
            assertNotNull(tm);
View Full Code Here


        _con = (AMQConnection) getConnection(url);
        _con.setExceptionListener(this);
        _con.start();
       
        // Create queue
        Session qsession = _con.createSession(true, Session.SESSION_TRANSACTED);
        AMQShortString queueName = new AMQShortString("test");
        _queue = new AMQQueue(qsession.getDefaultQueueExchangeName(), queueName, queueName, false, true);
        qsession.close();
       
        // Create producer and consumer
        producer();
        consumer();
    }
View Full Code Here

            public void failoverComplete()
            {
                _logger.info("App got failover complete callback");
            }
        });
        final Session session = (Session) _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        _logger.info("Service (queue) name is '" + serviceName + "'...");

        AMQQueue destination = new AMQQueue(serviceName);

        MessageConsumer consumer = session.createConsumer(destination,
                                                          100, true, false, null);

        consumer.setMessageListener(new MessageListener()
        {
            private int _messageCount;

            public void onMessage(Message message)
            {
                //_logger.info("Got message '" + message + "'");

                TextMessage tm = (TextMessage) message;

                try
                {
                    Destination responseDest = tm.getJMSReplyTo();
                    if (responseDest == null)
                    {
                        _logger.info("Producer not created because the response destination is null.");
                        return;
                    }

                    if (!responseDest.equals(_responseDest))
                    {
                        _responseDest = responseDest;

                        _logger.info("About to create a producer");
                        _destinationProducer = session.createProducer(responseDest);
                        _destinationProducer.setDisableMessageTimestamp(true);
                        _destinationProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
                        _logger.info("After create a producer");
                    }
                }
                catch (JMSException e)
                {
                    _logger.error("Error creating destination");
                }
                _messageCount++;
                if (_messageCount % 1000 == 0)
                {
                    _logger.info("Received message total: " + _messageCount);
                    _logger.info("Sending response to '" + _responseDest + "'");
                }

                try
                {
                    String payload = "This is a response: sing together: 'Mahnah mahnah...'" + tm.getText();
                    TextMessage msg = session.createTextMessage(payload);
                    if (tm.propertyExists("timeSent"))
                    {
                        _logger.info("timeSent property set on message");
                        _logger.info("timeSent value is: " + tm.getLongProperty("timeSent"));
                        msg.setStringProperty("timeSent", tm.getStringProperty("timeSent"));
View Full Code Here

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

            final int expectedMessageCount = numExpectedMessages;

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

            consumer.setMessageListener(new MessageListener()
            {
                private int _messageCount;
View Full Code Here

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

        Session consumerSession = con.createSession(true, Session.SESSION_TRANSACTED);
        AMQQueue queue3 = new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q3"), false);
        MessageConsumer consumer = consumerSession.createConsumer(queue3);

        AMQConnection con2 = (AMQConnection) getConnection("guest", "guest");
        Session producerSession = con2.createSession(true, Session.SESSION_TRANSACTED);
        MessageProducer producer = producerSession.createProducer(queue3);

        _logger.info("Sending four messages");
        producer.send(producerSession.createTextMessage("msg1"));
        producer.send(producerSession.createTextMessage("msg2"));
        producer.send(producerSession.createTextMessage("msg3"));
        producer.send(producerSession.createTextMessage("msg4"));

        producerSession.commit();

        _logger.info("Starting connection");
        con.start();
        TextMessage tm = (TextMessage) consumer.receive();
        assertNotNull(tm);
View Full Code Here

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

        Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        Queue queue =
                new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q1"), new AMQShortString("Q1"),
                             false, true);
        Queue queue2 =
                new AMQQueue(consumerSession.getDefaultQueueExchangeName(), new AMQShortString("Q2"), new AMQShortString("Q2"),
                             false, true);
        MessageConsumer consumer = consumerSession.createConsumer(queue);
        MessageConsumer consumer2 = consumerSession.createConsumer(queue2);

        AMQConnection con2 = (AMQConnection) getConnection("guest", "guest");
        Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE);
        MessageProducer producer = producerSession.createProducer(queue);
        MessageProducer producer2 = producerSession.createProducer(queue2);

        producer.send(producerSession.createTextMessage("msg1"));
        producer2.send(producerSession.createTextMessage("msg2"));

        con2.close();

        _logger.info("Starting connection");
        con.start();
View Full Code Here

    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 redilvered on what should be first delivery attempt"));
                        }

                        consumerSession.recover();
                    }
                    else if (count.get() == 2)
                    {
                        if (!message.getJMSRedelivered())
                        {
View Full Code Here

TOP

Related Classes of org.apache.qpid.jms.Session

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.