activemq-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From abakar <abaka...@web.de>
Subject Re: How can I remove a message from Queue
Date Tue, 06 Oct 2009 09:41:33 GMT

Hi Felix, 

Many thanks for your answer,

That mean there is no a way to delete all a messages directly form my java
client!!!

I have wrote this code :

public void purgeQueue(JmsDestination dst) {
		
		try {

			BrokerService broker = new BrokerService();
			broker.setUseShutdownHook(false);
			broker.setPlugins(new BrokerPlugin[] { new JaasAuthenticationPlugin() });

			broker.addConnector("tcp://localhost:0");
			// broker.start();

			mbeanServer = broker.getManagementContext().getMBeanServer();

			// System.out.println("MbeanServer :
"+broker.getManagementContext().isCreateMBeanServer());

			ObjectName queueViewMBeanName = new ObjectName(domain
					+ ":Type=Queue,Destination=" + dst + ",BrokerName="
					+ broker.getBrokerName());

			if (mbeanServer.isRegistered(queueViewMBeanName)) {
				System.out.println("Bean Registered: " + queueViewMBeanName);
			} else {
				System.out.println("Could not find MBean!: "
						+ queueViewMBeanName);
			}

			// Create a proxy to the QueueViewMBean
			QueueViewMBean queue = (QueueViewMBean) MBeanServerInvocationHandler
					.newProxyInstance(mbeanServer, queueViewMBeanName,
							QueueViewMBean.class, true);

			/**/

			// Purge the queue
			queue.purge();

		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();

		}

	}


But i have allways following exception :

javax.management.InstanceNotFoundException:
org.apache.activemq:Type=Queue,Destination=simple.queue,BrokerName=localhost
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(Unknown
Source)
	at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(Unknown
Source)
	at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(Unknown Source)
	at javax.management.MBeanServerInvocationHandler.invoke(Unknown Source)
	at $Proxy0.purge(Unknown Source) 

I look forward to find out one way to delete alle messages in a Destination
or only one message???.

Many Thanks :-(



fehm wrote:
> 
> Hi abakar,
> 
> This example below will read all message from a queue (until it is empty).
> Make sure that no producer runs.
> If you need to delete all messages you can also use jconsole
> (http://activemq.apache.org/jmx.html) to empty the queue (operation
> "purge").
> 
> 
> Felix
> 
> 
> 
> import javax.jms.Connection;
> import javax.jms.Destination;
> import javax.jms.ExceptionListener;
> import javax.jms.JMSException;
> import javax.jms.Message;
> import javax.jms.TextMessage;
> import javax.jms.MessageConsumer;
> import javax.jms.Session;
> 
> 
> import org.apache.activemq.ActiveMQConnectionFactory;
> 
> public class Test {
> 
>   /**
>    * @param args
>    */
>   public static void main(String[] args) throws Exception {
> 
>     Message message = null ;
>     // your broker url
>     String sConnection = "tcp://0.0.0.0:61620";
>     ActiveMQConnectionFactory connectionFactory = new
> ActiveMQConnectionFactory(sConnection);
>     Connection connection = connectionFactory.createConnection();
>     connection.start();
> 
>     // create Session for the queue and register us in the server
>     Session session = connection.createSession(false,
> Session.AUTO_ACKNOWLEDGE);
>     Destination queue = session.createQueue("YOUR_QUEUE_NAME");
>     MessageConsumer consumer = session.createConsumer(queue);
> 
>     // polling for messages
>     while ( (message = consumer.receive()) != null ){
>       if(message instanceof TextMessage){
>         TextMessage tx = (TextMessage)message;
>         System.out.println(tx);
>       }
>     }
>   }
> }
> 
> 
> 
> 
> 
> 
> abakar wrote:
>> 
>> Hello i am a new by ActiveMQ. I have tried form my java code to delete a
>> message form queue but didn't work.
>> 
>> I don't know how can i do that!!!!!  
>> 
>> how can I remove alle messages from a queue or only one message from
>> Queue.
>> 
>> Ich have lookout at google, Nabble and activeMQ Community but i didn't
>> find one example as java code.
>> 
>> please help me, i have more than two weeks and i tried many ways but
>> without sucess. :-(
>> 
>> Thank you so much 
>> 
>> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/How-can-I-remove-a-message-from-Queue-tp25749799p25765613.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.


Mime
View raw message