You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@activemq.apache.org by robottaway <ro...@musiciansfriend.com> on 2006/11/01 19:03:56 UTC

AMQ shut down, NMS connection still going!

I am running a Windows service that  connects to AMQ 4.0.2 thourgh the .NET
NMS api. It works almost perfect but there seems be one sticking point,
which is if I kill AMQ the service keeps on going like nothing happened!

I have tried using both Receive() and Receive(span) methods, niether throw
exception when AMQ is no longer running.

here is a .NET console app I wrote to make testing this easy. Just run it
wait for the message "Before Receive()", then kill AMQ. Nothing happens in
the app! It seems to think things are still going good.

using System;
using System.Collections.Generic;
using System.Text;
using NMS;
using ActiveMQ;
using ActiveMQ.Commands;
using System.Threading;

namespace TestKillAmq
{
    class Program
    {
        static String connString = "tcp://172.16.10.243:61616";

        static String queue = "bsd.development.orderentry";

        static void Main(string[] args)
        {
            IConnectionFactory factory;
            Connection amqConnection;
            Session amqSession;
            IDestination destination;
            IMessageConsumer consumer;
            ActiveMQTextMessage message;

            factory = new ConnectionFactory(new Uri(connString));
            try
            {
                amqConnection = (Connection)factory.CreateConnection();

                amqSession =
(Session)amqConnection.CreateSession(AcknowledgementMode.Transactional);

                destination = amqSession.GetQueue(queue);

                consumer = amqSession.CreateConsumer(destination);

                Console.WriteLine("Before Receive()");

                message = (ActiveMQTextMessage)consumer.Receive();

                Console.WriteLine("After Receive(), message: " +
message.Text);

                amqSession.Commit();

                Console.WriteLine("Commited transaction!");

                // shutdown all the stuff
                consumer.Dispose();
                amqSession.Dispose();
                amqConnection.Dispose();

                Thread.Sleep(5000);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
            }
        }
    }
}

-- 
View this message in context: http://www.nabble.com/AMQ-shut-down%2C-NMS-connection-still-going%21-tf2554850.html#a7119119
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


RE: AMQ shut down, NMS connection still going!

Posted by Rob Lugt <ro...@cheynecapital.com>.
Hi Kevin

The patch for AMQ-999 contains a number of fixes in this area, including the
raising of an event which should cause Receive() to return NULL in the
scenario you describe.  If you use the Trunk version of NMS you should see
this fix.

Regards
Rob Lugt


Kevin German wrote:
> 
> Ok,
> 
> Seems I forgot the important part in that last message.  I'm getting the
> errors because the BrokerService that I am retrieving from a call to 
> 
> 	broker = (XBeanBrokerService)
> ctx.getBean(XBeanBrokerService.class.getName());
> 
> is not the one that contains those connectors.  So I guess the real
> question
> (treading off to the XBean and Spring lists) is how do I get the object
> that
> was created when I use XBean/Spring to create a broker?
> 
> 
> -----Original Message-----
> From: Kevin German [mailto:Kevin.German@efi.com] 
> Sent: Wednesday, November 01, 2006 3:44 PM
> To: activemq-users@geronimo.apache.org
> Subject: RE: AMQ shut down, NMS connection still going!
> 
> I'm seeing a similar situation with a server started using the
> Spring/XBean
> on an inputstream in a build of the activemq-4.0 branch.  (I want to use
> 4.0.2 because it seems some openwire C++ bugs were fixed in that version).
> My start method boils down to:
> 
> 	InputStreamResource isr = new InputStreamResource( cfg );
> 	ResourceXmlApplicationContext ctx = new
> ResourceXmlApplicationContext( isr );
> 	XBeanBrokerService broker = null;
> 
> And in my shutdown method I'm calling
> 
> 	new org.apache.activemq.util.ServiceStopper().stop(b);
> 
> On that same broker service.  After ServiceStopper.stop returns I still
> see 9
> threads running in the debugger.  My main thread has exited.
> 
> All of those threads are waiting except 1 for jmDNS Resolver and 1
> org.apache.activemq.broker.TransportStatusDetector for each of the
> transport
> connectors that are described in the XBean config file.  
> I put some extra logging in TransportStatusDetector and see that for each
> the
> two transports described in the XBean config file there is a
> vm://localhost
> connector created.  The strange thing I noticed is that the
> TransportStatusDetector that receives the stop() call is not the one that
> was
> started.  In fact the one that receives the stop call was never started. 
> An
> abstraction of my log follows.  The long is the Object.geHashCode() for
> that
> TransportStatusDetector.
> 
> 10298 Starting instance 16179550 of TransportStatusDetector(default) on
> thread 1
> 10298 Looping run method in 16179550 of TransportStatusDetector on thread
> 33
> 
> 13845 Starting instance 14758874 of TransportStatusDetector(broker) on
> thread
> 1
> 13861 Looping run method in 14758874 of TransportStatusDetector on thread
> 35
> 
> 13892 Starting instance 13653774 of
> TransportStatusDetector(vm://localhost)
> on thread 1
> 13908 Looping run method in 13653774 of TransportStatusDetector on thread
> 36
> 13939 Stopping instance 13653774 of
> TransportStatusDetector(vm://localhost)
> on thread 1
> 
> 14205 Starting instance 26432381 of
> TransportStatusDetector(vm://localhost)
> on thread 32
> 14205 Looping run method in 26432381 of TransportStatusDetector on thread
> 37
> 14205 Stopping instance 26432381 of
> TransportStatusDetector(vm://localhost)
> on thread 32
> 
> 15314 Looping run method in 16179550 of TransportStatusDetector on thread
> 33
> 
> 17221 Stopping instance 31777764 of TransportStatusDetector(default) on
> thread 1
> 
> 18861 Looping run method in 14758874 of TransportStatusDetector on thread
> 35
> 
> 19190 Stopping instance 3001934 of TransportStatusDetector(broker) on
> thread
> 1
> 
> 20315 Looping run method in 16179550 of TransportStatusDetector on thread
> 33
> 23862 Looping run method in 14758874 of TransportStatusDetector on thread
> 35
> 25315 Looping run method in 16179550 of TransportStatusDetector on thread
> 33
> 28863 Looping run method in 14758874 of TransportStatusDetector on thread
> 35
> ...and they loop 
> 
> That said, I'm gonna go dig around and try to figure out where the switch
> is
> happenning.
> 
> Have fun,
> 
> -Kevin German
> 
> -----Original Message-----
> From: robottaway [mailto:rottaway@musiciansfriend.com] 
> Sent: Wednesday, November 01, 2006 1:04 PM
> To: activemq-users@geronimo.apache.org
> Subject: AMQ shut down, NMS connection still going!
> 
> 
> I am running a Windows service that  connects to AMQ 4.0.2 thourgh the
> .NET
> NMS api. It works almost perfect but there seems be one sticking point,
> which is if I kill AMQ the service keeps on going like nothing happened!
> 
> I have tried using both Receive() and Receive(span) methods, niether throw
> exception when AMQ is no longer running.
> 
> here is a .NET console app I wrote to make testing this easy. Just run it
> wait for the message "Before Receive()", then kill AMQ. Nothing happens in
> the app! It seems to think things are still going good.
> 
> using System;
> using System.Collections.Generic;
> using System.Text;
> using NMS;
> using ActiveMQ;
> using ActiveMQ.Commands;
> using System.Threading;
> 
> namespace TestKillAmq
> {
>     class Program
>     {
>         static String connString = "tcp://172.16.10.243:61616";
> 
>         static String queue = "bsd.development.orderentry";
> 
>         static void Main(string[] args)
>         {
>             IConnectionFactory factory;
>             Connection amqConnection;
>             Session amqSession;
>             IDestination destination;
>             IMessageConsumer consumer;
>             ActiveMQTextMessage message;
> 
>             factory = new ConnectionFactory(new Uri(connString));
>             try
>             {
>                 amqConnection = (Connection)factory.CreateConnection();
> 
>                 amqSession =
> (Session)amqConnection.CreateSession(AcknowledgementMode.Transactional);
> 
>                 destination = amqSession.GetQueue(queue);
> 
>                 consumer = amqSession.CreateConsumer(destination);
> 
>                 Console.WriteLine("Before Receive()");
> 
>                 message = (ActiveMQTextMessage)consumer.Receive();
> 
>                 Console.WriteLine("After Receive(), message: " +
> message.Text);
> 
>                 amqSession.Commit();
> 
>                 Console.WriteLine("Commited transaction!");
> 
>                 // shutdown all the stuff
>                 consumer.Dispose();
>                 amqSession.Dispose();
>                 amqConnection.Dispose();
> 
>                 Thread.Sleep(5000);
>             }
>             catch (Exception exception)
>             {
>                 Console.WriteLine(exception.ToString());
>             }
>         }
>     }
> }
> 
> -- 
> View this message in context:
> http://www.nabble.com/AMQ-shut-down%2C-NMS-connection-still-going%21-tf255485
> 0.html#a7119119
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/AMQ-shut-down%2C-NMS-connection-still-going%21-tf2554850.html#a7200756
Sent from the ActiveMQ - User mailing list archive at Nabble.com.