MatthiasBuck
12 years agoOccasional Contributor
[Resolved] Groovy Script - Clear JMS Messages from Queue
Hi all,
I'm trying to create a script to clear all messages from one or more queues.
I found a code example online http://josies.blogspot.com/2012/03/delete-messages-from-queues-in-groovy.html but it contains a bunch of issues. This script however, serves as my basis since it's better than starting from scratch.
The purpose of clearing messages from a queue is to run it as a setup of a test case that works with JMS messages. Having old JMS messages on a queue will create assertion failures since its likely not what the test case expects. Clearing messages will solve this problem.
The problem with below code is that I'm still unclear as to how I get a handle on certain objects. Unfortunately the Java Doc API http://www.soapui.org/apidocs/ doesn't contain quite enough information to work with.
Currently I'm stuck with following line of code:
def hermes = HermesUtils.getHermes(testSuite.getProject(), "sessionName")
http://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/submit/transports/jms/util/HermesUtils.html
I don't know what sessionName should be. Once that's clear, I'm sure there are going to be additional challenges with the script.
Does anybody have better documentation on how to use the Classes and feed the methods?
Or some additional ideas to get this working?
Here is my current version of the script:
Thanks much for your help!
I'm trying to create a script to clear all messages from one or more queues.
I found a code example online http://josies.blogspot.com/2012/03/delete-messages-from-queues-in-groovy.html but it contains a bunch of issues. This script however, serves as my basis since it's better than starting from scratch.
The purpose of clearing messages from a queue is to run it as a setup of a test case that works with JMS messages. Having old JMS messages on a queue will create assertion failures since its likely not what the test case expects. Clearing messages will solve this problem.
The problem with below code is that I'm still unclear as to how I get a handle on certain objects. Unfortunately the Java Doc API http://www.soapui.org/apidocs/ doesn't contain quite enough information to work with.
Currently I'm stuck with following line of code:
def hermes = HermesUtils.getHermes(testSuite.getProject(), "sessionName")
http://www.soapui.org/apidocs/com/eviware/soapui/impl/wsdl/submit/transports/jms/util/HermesUtils.html
I don't know what sessionName should be. Once that's clear, I'm sure there are going to be additional challenges with the script.
Does anybody have better documentation on how to use the Classes and feed the methods?
Or some additional ideas to get this working?
Here is my current version of the script:
import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSConnectionHolder
import com.eviware.soapui.impl.wsdl.submit.transports.jms.JMSEndpoint
import com.eviware.soapui.impl.wsdl.submit.transports.jms.util.HermesUtils
import hermes.Hermes
import javax.jms.*
// ${endpoint} is set in global properties to session created in Hermes ie Tibco-INT
def endpoint = context.expand('${endpoint}')
List queues = ["MYQUEUE"];
queues.each{
def queueName = "${it}"
def jmsEndPoint = new JMSEndpoint("jms://" + endpoint + "::-::queue_" + queueName);
def hermes = HermesUtils.getHermes(testSuite.getProject(), "sessionName")
def jmsConnectionHolder = new JMSConnectionHolder(jmsEndPoint,hermes,false,null,null,null);
log.info("endpoint:" + endpoint);
log.info("queueName:" + queueName);
//log.info("jmsEndPoint:" + "jms://" + endpoint + "::-::queue_" + queueName");
Session session = jmsConnectionHolder.getSession();
Queue queue = jmsConnectionHolder.getQueue(jmsConnectionHolder.getJMSEndpoint().getReceive());
MessageConsumer consumer = session.createConsumer(queue);
Message message = null;
while((message = consumer.receiveNoWait()) != null){
//do nothing
}
jmsConnectionHolder.closeAll()
*/
}
Thanks much for your help!