If you are getting connection issues, I would speculate that you are not configured to allow enough connections. Perhaps the OS isn't configured to allow enough FDs, or the messaging server isn't configured with enough? You will need to fix the issue with the OS/server, and try to avoid working around it programmatically.
But, if you want to try regardless, you can try ...
1. Creating a consumer to consume all the unwanted messages from the queue.
2. Have the producer(s) assign a expiration to the messages, so that they are automatically deleted if the consumers are not available..
3. Manually queue browse the queues -- and deleting the unwanted messages.