From 8dcb1d30b0414a3aa139dd93319ce2fe42c9049a Mon Sep 17 00:00:00 2001 From: Rajith Muditha Attapattu Date: Tue, 29 Jan 2008 22:24:40 +0000 Subject: added support to notify connection.close to the JMSExceptionListener git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@616542 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/example/jmsexample/direct/Producer.java | 30 +++++++++++++++++++++- .../qpid/client/AMQConnectionDelegate_0_10.java | 13 +++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) (limited to 'qpid/java/client') diff --git a/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java b/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java index 9cbd40f9ea..1e1390941f 100644 --- a/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java +++ b/qpid/java/client/example/src/main/java/org/apache/qpid/example/jmsexample/direct/Producer.java @@ -25,6 +25,8 @@ import java.util.Properties; import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.Destination; +import javax.jms.ExceptionListener; +import javax.jms.JMSException; import javax.jms.Message; import javax.jms.MessageProducer; import javax.jms.Session; @@ -32,6 +34,12 @@ import javax.jms.TextMessage; import javax.naming.Context; import javax.naming.InitialContext; +import org.apache.qpid.client.AMQDestination; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQSession_0_10; +import org.apache.qpidity.nclient.Client; +import org.apache.qpidity.transport.Option; + /** * Message producer example, sends message to a queue. */ @@ -73,13 +81,22 @@ public class Producer Context ctx = new InitialContext(properties); // look up destination - Destination destination = (Destination)ctx.lookup("directQueue"); + //Destination destination = (Destination)ctx.lookup("directQueue"); + Destination destination = new AMQQueue("amq.fancy","myQeueu"); // Lookup the connection factory ConnectionFactory conFac = (ConnectionFactory)ctx.lookup("qpidConnectionfactory"); // create the connection Connection connection = conFac.createConnection(); + connection.setExceptionListener(new ExceptionListener() + { + public void onException(JMSException e) + { + e.printStackTrace(); + } + }); + // Create a session on the connection // This session is a default choice of non-transacted and uses the auto acknowledge feature of a session. System.out.println(CLASS + ": Creating a non-transacted, auto-acknowledged session"); @@ -92,6 +109,17 @@ public class Producer System.out.println(CLASS + ": Creating a Message Producer"); MessageProducer messageProducer = session.createProducer(destination); + try{ + org.apache.qpidity.nclient.Connection con = Client.createConnection(); + con.connect("qpid:password=pass;username=name@tcp:localhost:5672"); + org.apache.qpidity.nclient.Session ses = con.createSession(1000000); + ses.exchangeDelete("amq.direct", Option.NO_OPTION); + } + catch(Exception e) + { + e.printStackTrace(); + } + // Create a Message TextMessage message; System.out.println(CLASS + ": Creating a TestMessage to send to the destination"); diff --git a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java index 78090b45ad..1bf1c5bc7f 100644 --- a/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java +++ b/qpid/java/client/src/main/java/org/apache/qpid/client/AMQConnectionDelegate_0_10.java @@ -11,11 +11,13 @@ import org.apache.qpid.client.failover.FailoverException; import org.apache.qpid.jms.BrokerDetails; import org.apache.qpid.jms.Session; import org.apache.qpidity.nclient.Client; +import org.apache.qpidity.nclient.ClosedListener; +import org.apache.qpidity.ErrorCode; import org.apache.qpidity.QpidException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate +public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate, ClosedListener { /** * This class logger. @@ -138,4 +140,13 @@ public class AMQConnectionDelegate_0_10 implements AMQConnectionDelegate } } + + public void onClosed(ErrorCode errorCode, String reason) + { + if (_logger.isDebugEnabled()) + { + _logger.debug("Received a connection close from the broker: Error code : " + errorCode.getCode()); + } + _conn._exceptionListener.onException(new JMSException(reason,String.valueOf(errorCode.getCode()))); + } } -- cgit v1.2.1