[rabbitmq-discuss] Queue / Exchange Purge
Alexandru Scvorţov
alexandru at rabbitmq.com
Wed Dec 22 19:20:47 GMT 2010
Hi Steven,
So, first client connects and publishes, second client connects and
doesn't get any message (fails to ack), third client connects and purges
the queue:
public static int Main(string[] args) {
ConnectionFactory cf = new ConnectionFactory();
string QUEUE_NAME = "magic";
using (IConnection conn = cf.CreateConnection()) {
using (IModel ch = conn.CreateModel()) {
ch.QueueDeclare(QUEUE_NAME, false, true, false, false, false, null);
IBasicProperties props = ch.CreateBasicProperties();
props.SetPersistent(true);
ch.BasicPublish("", QUEUE_NAME, props, Encoding.UTF8.GetBytes("Happy Holidays!"));
}
}
using (IConnection conn = cf.CreateConnection()) {
using (IModel ch = conn.CreateModel()) {
ch.BasicGet(QUEUE_NAME, false);
//not ack'ing
}
}
using (IConnection conn = cf.CreateConnection()) {
using (IModel ch = conn.CreateModel()) {
uint n = ch.QueuePurge(QUEUE_NAME, false);
Console.Write("" + n + " message(s) lost. ):");
}
}
return 0;
}
This works.
Since you're getting 404 errors, I suspect you either: 1) get the queue
name wrong at some point; or 2) declare it at auto-delete, exclusive or
non-durable and then restart the broker.
Does this help?
Cheers,
Alex
On Wed, Dec 22, 2010 at 06:35:08PM +0000, Steven Taylor wrote:
> Hi Alexander,
>
> the situation is where client connects, publishes, and disconnects. 2nd
> client comes along to consume message, and fails in some task it tries to do
> on the data (i.e. message is returned to the queue). 3rd client intervenes
> (i.e. me manually during test phase with a little script), and wants to
> clear out all messages that are hanging around on the broker.
>
> Your test sounds like purge works for the 1st client in the above example,
> but not for the 3rd.
>
> Probably I'm not understanding what you intended purge for. Could you help
> me out with this scenario?
>
> thanks,
> -Steven
>
> On 22 December 2010 15:04, Alexandru Scvorţov <alexandru at rabbitmq.com>wrote:
>
> > Hi,
> >
> > Using our .NET client, declaring a queue, then immediately purging it
> > works as expected.
> >
> > Could you supply the code that's causing the problem?
> >
> > Cheers,
> > Alex
> >
> > On Wed, Dec 22, 2010 at 02:37:50PM +0000, Steven Taylor wrote:
> > > update:
> > >
> > >
> > > code: ch.QueuePurge(queueName,false);
> > >
> > >
> > >
> > > The AMQP operation was interrupted: AMQP close-reason, initiated by Peer,
> > > code=404, text="NOT_FOUND - no queue 'm.w' in vhost '/'", classId=50,
> > > methodId=30, cause=
> > >
> > > First off, this error relates to an exchange routing key, so slightly
> > > expected. What wasn't expected was the error message should have had the
> > > right queue name 'm.w.ctr'. 'm.w' is the queue (not bound to an
> > exchange)
> > > that failed earlier when I tried to purge it because it wasn't yet
> > created.
> > >
> > > let me try something else...
> > >
> > > If I first create the queue 'm.w' and then attempted to purge it, I still
> > > get the same error message as above.
> > >
> > > Is anybody else seeing this behaviour?
> > >
> > > thanks,
> > > -Steven
> > >
> > >
> > > On 22 December 2010 13:32, Steven Taylor <taylste at gmail.com> wrote:
> > >
> > > > Hi,
> > > >
> > > > is there equivilent to purge queue for an exchange? If we can't
> > already,
> > > > it would be nice to be able to purge with a routing key. I see
> > > > an ExchangeDelete. Perhaps I should delete and then redeclare.
> > > >
> > > > Currently I'm using non-durable queues, and taking down the broker +
> > > > restarting it. I just wanted something a little simpler to execute.
> > This is
> > > > a test phase request.
> > > >
> > > > thanks,
> > > > -Steven
> > > >
> >
> > > _______________________________________________
> > > rabbitmq-discuss mailing list
> > > rabbitmq-discuss at lists.rabbitmq.com
> > > https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
> >
> >
More information about the rabbitmq-discuss
mailing list