[jboss-user] [JBoss Messaging] - Re: ERROR: Cannot find delivery to cancel

noxis do-not-reply at jboss.com
Fri Aug 17 08:06:30 EDT 2007


"timfox" wrote : I just copied what you posted.
  | 
  | If you can package up a test program and exact step by step instructions I will try again

I think I forgot about one important thing - TTL of messages.

Here is a working example. I can replicate this bug all the time. "Cannot find delivery to cancel" appears after about 2 minutes.

Queue configuration:

  | <?xml version="1.0" encoding="UTF-8"?>
  | <server>
  | 	<mbean code="org.jboss.jms.server.destination.QueueService" name="jboss.messaging.destination:service=Queue,name=testCancel" xmbean-dd="xmdesc/Queue-xmbean.xml">
  | 		<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
  | 		<depends>jboss.messaging:service=PostOffice</depends>
  | 		<attribute name="RedeliveryDelay">5000</attribute>
  | 	</mbean>
  | </server>
  | 

TestMDB.java

  | package main.ejb;
  | 
  | import javax.annotation.Resource;
  | import javax.ejb.MessageDriven;
  | import javax.ejb.ActivationConfigProperty;
  | import javax.ejb.MessageDrivenContext;
  | import javax.jms.Message;
  | import javax.jms.MessageListener;
  | import javax.jms.TextMessage;
  | 
  | @MessageDriven(activationConfig = {
  | 		@ActivationConfigProperty(propertyName="destinationType", propertyValue="javax.jms.Queue"),
  | 		@ActivationConfigProperty(propertyName="destination", propertyValue="queue/testCancel"),
  | 		@ActivationConfigProperty(propertyName="maxSession", propertyValue="1")
  | 	})
  | 
  | public class TestMDB implements MessageListener {
  | 
  | 	@Resource
  |     private MessageDrivenContext mdc;
  | 
  | 	public void onMessage(Message msg) {
  | 		try {
  | 			TextMessage textMsg = (TextMessage) msg;
  | 			System.out.println("got: " + textMsg.getText());
  | 			Thread.sleep(40000);
  | 			mdc.setRollbackOnly();
  | 		} catch (Throwable te) {
  | 			te.printStackTrace();
  | 			mdc.setRollbackOnly();
  | 		}
  | 	}
  | }
  | 


Test.java (interface)

  | package main.ejb;
  | 
  | import javax.ejb.Remote;
  | 
  | @Remote
  | public interface Test {
  | 
  | 	void testCancel();
  | }
  | 

TestBean.java

  | package main.ejb;
  | 
  | import javax.annotation.Resource;
  | import javax.ejb.Stateless;
  | import javax.jms.Connection;
  | import javax.jms.ConnectionFactory;
  | import javax.jms.JMSException;
  | import javax.jms.MessageProducer;
  | import javax.jms.Queue;
  | import javax.jms.Session;
  | import javax.jms.TextMessage;
  | 
  | @Stateless
  | public class TestBean implements Test {
  | 
  | 	@Resource(mappedName = "ConnectionFactory")
  | 	private ConnectionFactory factory;
  | 
  | 	@Resource(mappedName = "queue/testCancel")
  | 	private Queue queue;
  | 
  | 	public void testCancel() {
  | 		Connection connection = null;
  | 		Session session = null;
  | 		MessageProducer producer = null;
  | 		try {
  | 			connection = factory.createConnection();
  | 			session = connection.createSession(true, 0);
  | 			producer = session.createProducer(queue);
  | 
  | 			TextMessage msg = session.createTextMessage();
  | 			msg.setText("just another test");
  | 
  | 			producer.setTimeToLive(90000);
  | 
  | 			producer.send(msg);
  | 			session.commit();
  | 
  | 		} catch (Throwable te) {
  | 			te.printStackTrace();
  | 		} finally {
  | 			try {
  | 				if (producer != null) {
  | 					producer.close();
  | 				}
  | 				if (session != null) {
  | 					session.close();
  | 				}
  | 				if (connection != null) {
  | 					connection.close();
  | 				}
  | 			} catch (JMSException e) {
  | 				e.printStackTrace();
  | 			}
  | 		}
  | 	}
  | }
  | 

TestIt.java (Client)

  | package test;
  | 
  | import javax.naming.InitialContext;
  | 
  | import main.ejb.Test;
  | 
  | public class TestIt {
  | 
  | 	public static void main(final String[] args) throws Exception {
  | 		Test t = (Test) (new InitialContext()).lookup("TestBean/remote");
  | 		while (true) {
  | 			t.testCancel();
  | 			Thread.sleep(20000);
  | 		}
  | 	}
  | }
  | 


View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4075177#4075177

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4075177



More information about the jboss-user mailing list