activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Timothy Bish <tabish...@gmail.com>
Subject Re: Can I delete a message from a queue in c# code ?
Date Thu, 23 Jan 2014 14:51:30 GMT
On 01/22/2014 10:41 PM, HellKnight wrote:
> I want to set a unique guid for each message in message head , then if I want
> , I could delete a specific message if I want to.  Is there any api in NMS
> could help me deleting the message ? I am using ActiveMQ 5.9.0 and NMS 1.6.1
> Thanks in advance.
>
>
>
> --
> View this message in context: http://activemq.2283324.n4.nabble.com/Can-I-delete-a-message-from-a-queue-in-c-code-tp4676691.html
> Sent from the ActiveMQ - User mailing list archive at Nabble.com.
>
Yes, although only if that destination has no active consumers.  You can 
do something like this:

         protected static void DeleteDestination()
         {
             IConnectionFactory factory = new 
ConnectionFactory(ReplaceEnvVar(connectionURI));

             using (Connection connection = factory.CreateConnection() 
as Connection)
             {
                 using (ISession session = connection.CreateSession())
                 {
                     IQueue queue = session.GetQueue(testQueueName);
                     try
                     {
                         connection.DeleteDestination(queue);
                     }
                     catch
                     {
                     }
                 }
             }
         }


-- 
Tim Bish
Sr Software Engineer | RedHat Inc.
tim.bish@redhat.com | www.fusesource.com | www.redhat.com
skype: tabish121 | twitter: @tabish121
blog: http://timbish.blogspot.com/


Mime
View raw message